mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-22 07:38:45 +05:00
Adding SendMessage on the DiameterClient, integration tests updated
This commit is contained in:
@@ -59,10 +59,15 @@ func (self *DiameterAgent) handlers() diam.Handler {
|
||||
FirmwareRevision: datatype.Unsigned32(utils.DIAMETER_FIRMWARE_REVISION),
|
||||
}
|
||||
dSM := sm.New(settings)
|
||||
dSM.HandleFunc("CCR", self.handleCCR)
|
||||
dSM.HandleFunc("ALL", self.handleALL)
|
||||
return dSM
|
||||
}
|
||||
|
||||
func (self *DiameterAgent) handleCCR(c diam.Conn, m *diam.Message) {
|
||||
utils.Logger.Warning(fmt.Sprintf("<DiameterAgent> Received CCR message from %s:\n%s", c.RemoteAddr(), m))
|
||||
}
|
||||
|
||||
func (self *DiameterAgent) handleALL(c diam.Conn, m *diam.Message) {
|
||||
utils.Logger.Warning(fmt.Sprintf("<DiameterAgent> Received unexpected message from %s:\n%s", c.RemoteAddr(), m))
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ package agents
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"path"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -82,7 +81,7 @@ func TestDmtAgentStartEngine(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDmtAgentStartClient(t *testing.T) {
|
||||
func TestDmtAgentSendCCR(t *testing.T) {
|
||||
if !*testIntegration {
|
||||
return
|
||||
}
|
||||
@@ -91,7 +90,17 @@ func TestDmtAgentStartClient(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fmt.Printf("%+v", dmtClient)
|
||||
cdr := &engine.StoredCdr{CgrId: utils.Sha1("dsafdsaf", time.Date(2013, 11, 7, 8, 42, 20, 0, time.UTC).String()), OrderId: 123, TOR: utils.VOICE,
|
||||
AccId: "dsafdsaf", CdrHost: "192.168.1.1", CdrSource: utils.UNIT_TEST, ReqType: utils.META_RATED, Direction: "*out",
|
||||
Tenant: "cgrates.org", Category: "call", Account: "1001", Subject: "1001", Destination: "1002", Supplier: "SUPPL1",
|
||||
SetupTime: time.Date(2013, 11, 7, 8, 42, 20, 0, time.UTC), AnswerTime: time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC), MediationRunId: utils.DEFAULT_RUNID,
|
||||
Usage: time.Duration(10) * time.Second, Pdd: time.Duration(7) * time.Second, ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}, Cost: 1.01, RatedAccount: "dan", RatedSubject: "dans", Rated: true,
|
||||
}
|
||||
m := storedCdrToCCR(cdr, "UNIT_TEST", daCfg.DiameterAgentCfg().OriginRealm, daCfg.DiameterAgentCfg().VendorId,
|
||||
daCfg.DiameterAgentCfg().ProductName, utils.DIAMETER_FIRMWARE_REVISION, time.Duration(300)*time.Second, true)
|
||||
if err := dmtClient.SendMessage(m); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
time.Sleep(time.Duration(10) * time.Second)
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package agents
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
"github.com/fiorix/go-diameter/diam"
|
||||
@@ -28,10 +27,6 @@ import (
|
||||
"github.com/fiorix/go-diameter/diam/sm"
|
||||
)
|
||||
|
||||
func init() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
}
|
||||
|
||||
func NewDiameterClient(addr, originHost, originRealm string, vendorId int, productName string, firmwareRev int) (*DiameterClient, error) {
|
||||
cfg := &sm.Settings{
|
||||
OriginHost: datatype.DiameterIdentity(originHost),
|
||||
@@ -64,3 +59,8 @@ type DiameterClient struct {
|
||||
conn diam.Conn
|
||||
handlers diam.Handler
|
||||
}
|
||||
|
||||
func (self *DiameterClient) SendMessage(m *diam.Message) error {
|
||||
_, err := m.WriteTo(self.conn)
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user