本文整理汇总了Golang中github.com/cgrates/cgrates/config.NewDefaultCGRConfig函数的典型用法代码示例。如果您正苦于以下问题:Golang NewDefaultCGRConfig函数的具体用法?Golang NewDefaultCGRConfig怎么用?Golang NewDefaultCGRConfig使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewDefaultCGRConfig函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestAlternativeFieldSeparator
func TestAlternativeFieldSeparator(t *testing.T) {
writer := &bytes.Buffer{}
cfg, _ := config.NewDefaultCGRConfig()
storedCdr1 := &engine.CDR{CGRID: utils.Sha1("dsafdsaf", time.Unix(1383813745, 0).UTC().String()), ToR: utils.VOICE, OriginID: "dsafdsaf", OriginHost: "192.168.1.1",
RequestType: utils.META_RATED, Direction: "*out", Tenant: "cgrates.org",
Category: "call", Account: "1001", Subject: "1001", Destination: "1002", SetupTime: time.Unix(1383813745, 0).UTC(), AnswerTime: time.Unix(1383813746, 0).UTC(),
Usage: time.Duration(10) * time.Second, RunID: utils.DEFAULT_RUNID,
ExtraFields: map[string]string{"extra1": "val_extra1", "extra2": "val_extra2", "extra3": "val_extra3"}, Cost: 1.01,
}
cdre, err := NewCdrExporter([]*engine.CDR{storedCdr1}, nil, cfg.CdreProfiles["*default"], utils.CSV, '|',
"firstexport", 0.0, 0.0, 0.0, 0.0, 0.0, 0, 4, cfg.RoundingDecimals, "", 0, cfg.HttpSkipTlsVerify, "")
if err != nil {
t.Error("Unexpected error received: ", err)
}
csvWriter := csv.NewWriter(writer)
if err := cdre.writeCsv(csvWriter); err != nil {
t.Error("Unexpected error: ", err)
}
expected := `dbafe9c8614c785a65aabd116dd3959c3c56f7f6|*default|*voice|dsafdsaf|*rated|*out|cgrates.org|call|1001|1001|1002|2013-11-07T08:42:25Z|2013-11-07T08:42:26Z|10|1.0100`
result := strings.TrimSpace(writer.String())
if result != expected {
t.Errorf("Expected: \n%s received: \n%s.", expected, result)
}
if cdre.TotalCost() != 1.01 {
t.Error("Unexpected TotalCost: ", cdre.TotalCost())
}
}
开发者ID:bhepp,项目名称:cgrates,代码行数:27,代码来源:csv_test.go
示例2: TestParseFsHangup
func TestParseFsHangup(t *testing.T) {
cfg, _ = config.NewDefaultCGRConfig()
config.SetCgrConfig(cfg)
ev := new(FSEvent).New(hangupEv)
setupTime, _ := ev.GetSetupTime(utils.META_DEFAULT)
answerTime, _ := ev.GetAnswerTime(utils.META_DEFAULT)
dur, _ := ev.GetDuration(utils.META_DEFAULT)
if ev.GetReqType(utils.META_DEFAULT) != utils.PSEUDOPREPAID ||
ev.GetDirection(utils.META_DEFAULT) != "*out" ||
ev.GetTenant(utils.META_DEFAULT) != "cgrates.org" ||
ev.GetCategory(utils.META_DEFAULT) != "call" ||
ev.GetAccount(utils.META_DEFAULT) != "1003" ||
ev.GetSubject(utils.META_DEFAULT) != "1003" ||
ev.GetDestination(utils.META_DEFAULT) != "1002" ||
setupTime.UTC() != time.Date(2014, 4, 25, 16, 8, 27, 0, time.UTC) ||
answerTime.UTC() != time.Date(2014, 4, 25, 16, 8, 40, 0, time.UTC) ||
dur != time.Duration(5)*time.Second {
t.Error("Default values not matching",
ev.GetReqType(utils.META_DEFAULT) != utils.PSEUDOPREPAID,
ev.GetDirection(utils.META_DEFAULT) != "*out",
ev.GetTenant(utils.META_DEFAULT) != "cgrates.org",
ev.GetCategory(utils.META_DEFAULT) != "call",
ev.GetAccount(utils.META_DEFAULT) != "1003",
ev.GetSubject(utils.META_DEFAULT) != "1003",
ev.GetDestination(utils.META_DEFAULT) != "1002",
setupTime.UTC() != time.Date(2014, 4, 25, 17, 8, 27, 0, time.UTC),
answerTime.UTC() != time.Date(2014, 4, 25, 17, 8, 40, 0, time.UTC),
dur != time.Duration(5)*time.Second)
}
}
开发者ID:intralanman,项目名称:cgrates,代码行数:30,代码来源:fsevent_test.go
示例3: TestCsvCdrWriter
func TestCsvCdrWriter(t *testing.T) {
writer := &bytes.Buffer{}
cfg, _ := config.NewDefaultCGRConfig()
logDb, _ := engine.NewMapStorage()
storedCdr1 := &utils.StoredCdr{CgrId: utils.Sha1("dsafdsaf", time.Unix(1383813745, 0).UTC().String()), TOR: utils.VOICE, AccId: "dsafdsaf", CdrHost: "192.168.1.1",
ReqType: "rated", Direction: "*out", Tenant: "cgrates.org",
Category: "call", Account: "1001", Subject: "1001", Destination: "1002", SetupTime: time.Unix(1383813745, 0).UTC(), AnswerTime: time.Unix(1383813746, 0).UTC(),
Usage: time.Duration(10) * time.Second, MediationRunId: utils.DEFAULT_RUNID,
ExtraFields: map[string]string{"extra1": "val_extra1", "extra2": "val_extra2", "extra3": "val_extra3"}, Cost: 1.01,
}
cdre, err := NewCdrExporter([]*utils.StoredCdr{storedCdr1}, logDb, cfg.CdreDefaultInstance, utils.CSV, ',', "firstexport", 0.0, 0.0, 0, 4, cfg.RoundingDecimals, "", 0, cfg.HttpSkipTlsVerify)
if err != nil {
t.Error("Unexpected error received: ", err)
}
csvWriter := csv.NewWriter(writer)
if err := cdre.writeCsv(csvWriter); err != nil {
t.Error("Unexpected error: ", err)
}
expected := `dbafe9c8614c785a65aabd116dd3959c3c56f7f6,default,*voice,dsafdsaf,rated,*out,cgrates.org,call,1001,1001,1002,2013-11-07T08:42:25Z,2013-11-07T08:42:26Z,10000000000,1.0100`
result := strings.TrimSpace(writer.String())
if result != expected {
t.Errorf("Expected: \n%s received: \n%s.", expected, result)
}
if cdre.TotalCost() != 1.01 {
t.Error("Unexpected TotalCost: ", cdre.TotalCost())
}
}
开发者ID:intralanman,项目名称:cgrates,代码行数:27,代码来源:csv_test.go
示例4: TestParseFsHangup
func TestParseFsHangup(t *testing.T) {
cfg, _ := config.NewDefaultCGRConfig()
config.SetCgrConfig(cfg)
ev := new(FSEvent).AsEvent(hangupEv)
setupTime, _ := ev.GetSetupTime(utils.META_DEFAULT, "")
answerTime, _ := ev.GetAnswerTime(utils.META_DEFAULT, "")
dur, _ := ev.GetDuration(utils.META_DEFAULT)
if ev.GetReqType(utils.META_DEFAULT) != utils.META_PREPAID ||
ev.GetDirection(utils.META_DEFAULT) != "*out" ||
ev.GetTenant(utils.META_DEFAULT) != "cgrates.org" ||
ev.GetCategory(utils.META_DEFAULT) != "call" ||
ev.GetAccount(utils.META_DEFAULT) != "1001" ||
ev.GetSubject(utils.META_DEFAULT) != "1001" ||
ev.GetDestination(utils.META_DEFAULT) != "1003" ||
setupTime.UTC() != time.Date(2015, 7, 7, 14, 52, 8, 0, time.UTC) ||
answerTime.UTC() != time.Date(2015, 7, 7, 14, 52, 8, 0, time.UTC) ||
dur != time.Duration(66)*time.Second ||
ev.GetSupplier(utils.META_DEFAULT) != "supplier1" ||
ev.GetDisconnectCause(utils.META_DEFAULT) != "NORMAL_CLEARING" {
t.Error("Default values not matching",
ev.GetReqType(utils.META_DEFAULT) != utils.META_PREPAID,
ev.GetDirection(utils.META_DEFAULT) != "*out",
ev.GetTenant(utils.META_DEFAULT) != "cgrates.org",
ev.GetCategory(utils.META_DEFAULT) != "call",
ev.GetAccount(utils.META_DEFAULT) != "1001",
ev.GetSubject(utils.META_DEFAULT) != "1001",
ev.GetDestination(utils.META_DEFAULT) != "1003",
setupTime.UTC() != time.Date(2015, 7, 7, 14, 52, 8, 0, time.UTC),
answerTime.UTC() != time.Date(2015, 7, 7, 14, 52, 8, 0, time.UTC),
dur != time.Duration(66)*time.Second,
ev.GetSupplier(utils.META_DEFAULT) != "supplier1",
ev.GetDisconnectCause(utils.META_DEFAULT) != "NORMAL_CLEARING")
}
}
开发者ID:bhepp,项目名称:cgrates,代码行数:34,代码来源:fsevent_test.go
示例5: TestOnStorITRedisConnect
func TestOnStorITRedisConnect(t *testing.T) {
cfg, _ := config.NewDefaultCGRConfig()
rdsITdb, err = NewRedisStorage(fmt.Sprintf("%s:%s", cfg.TpDbHost, cfg.TpDbPort), 4, cfg.TpDbPass, cfg.DBDataEncoding, utils.REDIS_MAX_CONNS, nil, 1)
if err != nil {
t.Fatal("Could not connect to Redis", err.Error())
}
}
开发者ID:cgrates,项目名称:cgrates,代码行数:7,代码来源:onstor_it_test.go
示例6: TestConnDataDbs
// Create connection to ratingDb
// Will use 3 different datadbs in order to be able to see differences in data loaded
func TestConnDataDbs(t *testing.T) {
if !*testLocal {
return
}
lCfg, _ = config.NewDefaultCGRConfig()
var err error
if ratingDbCsv, err = ConfigureRatingStorage(lCfg.TpDbType, lCfg.TpDbHost, lCfg.TpDbPort, "4", lCfg.TpDbUser, lCfg.TpDbPass, lCfg.DBDataEncoding, nil, 1); err != nil {
t.Fatal("Error on ratingDb connection: ", err.Error())
}
if ratingDbStor, err = ConfigureRatingStorage(lCfg.TpDbType, lCfg.TpDbHost, lCfg.TpDbPort, "5", lCfg.TpDbUser, lCfg.TpDbPass, lCfg.DBDataEncoding, nil, 1); err != nil {
t.Fatal("Error on ratingDb connection: ", err.Error())
}
if ratingDbApier, err = ConfigureRatingStorage(lCfg.TpDbType, lCfg.TpDbHost, lCfg.TpDbPort, "6", lCfg.TpDbUser, lCfg.TpDbPass, lCfg.DBDataEncoding, nil, 1); err != nil {
t.Fatal("Error on ratingDb connection: ", err.Error())
}
if accountDbCsv, err = ConfigureAccountingStorage(lCfg.DataDbType, lCfg.DataDbHost, lCfg.DataDbPort, "7",
lCfg.DataDbUser, lCfg.DataDbPass, lCfg.DBDataEncoding, nil, 1); err != nil {
t.Fatal("Error on ratingDb connection: ", err.Error())
}
if accountDbStor, err = ConfigureAccountingStorage(lCfg.DataDbType, lCfg.DataDbHost, lCfg.DataDbPort, "8",
lCfg.DataDbUser, lCfg.DataDbPass, lCfg.DBDataEncoding, nil, 1); err != nil {
t.Fatal("Error on ratingDb connection: ", err.Error())
}
if accountDbApier, err = ConfigureAccountingStorage(lCfg.DataDbType, lCfg.DataDbHost, lCfg.DataDbPort, "9",
lCfg.DataDbUser, lCfg.DataDbPass, lCfg.DBDataEncoding, nil, 1); err != nil {
t.Fatal("Error on ratingDb connection: ", err.Error())
}
for _, db := range []Storage{ratingDbCsv, ratingDbStor, ratingDbApier, accountDbCsv, accountDbStor, accountDbApier} {
if err = db.Flush(""); err != nil {
t.Fatal("Error when flushing datadb")
}
}
}
开发者ID:eloycoto,项目名称:cgrates,代码行数:36,代码来源:loader_local_test.go
示例7: TestDmtAgentCCRAsSMGenericEvent
func TestDmtAgentCCRAsSMGenericEvent(t *testing.T) {
if !*testIntegration {
return
}
cfgDefaults, _ := config.NewDefaultCGRConfig()
loadDictionaries(cfgDefaults.DiameterAgentCfg().DictionariesDir, "UNIT_TEST")
ccr := &CCR{
SessionId: "routinga;1442095190;1476802709",
OriginHost: cfgDefaults.DiameterAgentCfg().OriginHost,
OriginRealm: cfgDefaults.DiameterAgentCfg().OriginRealm,
DestinationHost: cfgDefaults.DiameterAgentCfg().OriginHost,
DestinationRealm: cfgDefaults.DiameterAgentCfg().OriginRealm,
AuthApplicationId: 4,
ServiceContextId: "[email protected]",
CCRequestType: 1,
CCRequestNumber: 0,
EventTimestamp: time.Date(2015, 11, 23, 12, 22, 24, 0, time.UTC),
ServiceIdentifier: 0,
SubscriptionId: []struct {
SubscriptionIdType int `avp:"Subscription-Id-Type"`
SubscriptionIdData string `avp:"Subscription-Id-Data"`
}{
struct {
SubscriptionIdType int `avp:"Subscription-Id-Type"`
SubscriptionIdData string `avp:"Subscription-Id-Data"`
}{SubscriptionIdType: 0, SubscriptionIdData: "4986517174963"},
struct {
SubscriptionIdType int `avp:"Subscription-Id-Type"`
SubscriptionIdData string `avp:"Subscription-Id-Data"`
}{SubscriptionIdType: 0, SubscriptionIdData: "4986517174963"}},
debitInterval: time.Duration(300) * time.Second,
}
ccr.RequestedServiceUnit.CCTime = 300
ccr.ServiceInformation.INInformation.CallingPartyAddress = "4986517174963"
ccr.ServiceInformation.INInformation.CalledPartyAddress = "4986517174964"
ccr.ServiceInformation.INInformation.RealCalledNumber = "4986517174964"
ccr.ServiceInformation.INInformation.ChargeFlowType = 0
ccr.ServiceInformation.INInformation.CallingVlrNumber = "49123956767"
ccr.ServiceInformation.INInformation.CallingCellIDOrSAI = "12340185301425"
ccr.ServiceInformation.INInformation.BearerCapability = "capable"
ccr.ServiceInformation.INInformation.CallReferenceNumber = "askjadkfjsdf"
ccr.ServiceInformation.INInformation.MSCAddress = "123324234"
ccr.ServiceInformation.INInformation.TimeZone = 0
ccr.ServiceInformation.INInformation.CalledPartyNP = "4986517174964"
ccr.ServiceInformation.INInformation.SSPTime = "20091020120101"
var err error
if ccr.diamMessage, err = ccr.AsDiameterMessage(); err != nil {
t.Error(err)
}
eSMGE := sessionmanager.SMGenericEvent{"EventName": "DIAMETER_CCR", "AccId": "routinga;1442095190;1476802709",
"Account": "*users", "AnswerTime": "2015-11-23 12:22:24 +0000 UTC", "Category": "call",
"Destination": "4986517174964", "Direction": "*out", "ReqType": "*users", "SetupTime": "2015-11-23 12:22:24 +0000 UTC",
"Subject": "*users", "SubscriberId": "4986517174963", "TOR": "*voice", "Tenant": "*users", "Usage": "300"}
if smge, err := ccr.AsSMGenericEvent(cfgDefaults.DiameterAgentCfg().RequestProcessors[0].ContentFields); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(eSMGE, smge) {
t.Errorf("Expecting: %+v, received: %+v", eSMGE, smge)
}
}
开发者ID:perrault,项目名称:cgrates,代码行数:59,代码来源:dmtagent_it_test.go
示例8: TestWriteCdr
// Write one CDR and test it's results only for content buffer
func TestWriteCdr(t *testing.T) {
wrBuf := &bytes.Buffer{}
logDb, _ := engine.NewMapStorage()
cfg, _ := config.NewDefaultCGRConfig()
fixedWidth := utils.CDRE_FIXED_WIDTH
exportTpl := &config.CgrXmlCdreCfg{
CdrFormat: &fixedWidth,
Header: &config.CgrXmlCfgCdrHeader{Fields: hdrCfgFlds},
Content: &config.CgrXmlCfgCdrContent{Fields: contentCfgFlds},
Trailer: &config.CgrXmlCfgCdrTrailer{Fields: trailerCfgFlds},
}
cdr := &utils.StoredCdr{CgrId: utils.Sha1("dsafdsaf", time.Date(2013, 11, 7, 8, 42, 20, 0, time.UTC).String()),
TOR: utils.VOICE, OrderId: 1, AccId: "dsafdsaf", CdrHost: "192.168.1.1",
ReqType: "rated", Direction: "*out", Tenant: "cgrates.org",
Category: "call", Account: "1001", Subject: "1001", Destination: "1002",
SetupTime: time.Date(2013, 11, 7, 8, 42, 20, 0, time.UTC),
AnswerTime: time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC),
Usage: time.Duration(10) * time.Second, MediationRunId: utils.DEFAULT_RUNID, Cost: 2.34567,
ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"},
}
cdre, err := NewCdrExporter([]*utils.StoredCdr{cdr}, logDb, exportTpl.AsCdreConfig(), utils.CDRE_FIXED_WIDTH, ',', "fwv_1", 0.0, 0.0, 0, 4, cfg.RoundingDecimals, "", -1, cfg.HttpSkipTlsVerify)
if err != nil {
t.Error(err)
}
eHeader := "10 VOI0000007111308420024031415390001 \n"
eContentOut := "201001 1001 1002 0211 07111308420010 1 3dsafdsaf 0002.34570\n"
eTrailer := "90 VOI0000000000100000010071113084260071113084200 \n"
if err := cdre.writeOut(wrBuf); err != nil {
t.Error(err)
}
allOut := wrBuf.String()
eAllOut := eHeader + eContentOut + eTrailer
if math.Mod(float64(len(allOut)), 145) != 0 {
t.Error("Unexpected export content length", len(allOut))
} else if len(allOut) != len(eAllOut) {
t.Errorf("Output does not match expected length. Have output %q, expecting: %q", allOut, eAllOut)
}
// Test stats
if !cdre.firstCdrATime.Equal(cdr.AnswerTime) {
t.Error("Unexpected firstCdrATime in stats: ", cdre.firstCdrATime)
} else if !cdre.lastCdrATime.Equal(cdr.AnswerTime) {
t.Error("Unexpected lastCdrATime in stats: ", cdre.lastCdrATime)
} else if cdre.numberOfRecords != 1 {
t.Error("Unexpected number of records in the stats: ", cdre.numberOfRecords)
} else if cdre.totalDuration != cdr.Usage {
t.Error("Unexpected total duration in the stats: ", cdre.totalDuration)
} else if cdre.totalCost != utils.Round(cdr.Cost, cdre.roundDecimals, utils.ROUNDING_MIDDLE) {
t.Error("Unexpected total cost in the stats: ", cdre.totalCost)
}
if cdre.FirstOrderId() != 1 {
t.Error("Unexpected FirstOrderId", cdre.FirstOrderId())
}
if cdre.LastOrderId() != 1 {
t.Error("Unexpected LastOrderId", cdre.LastOrderId())
}
if cdre.TotalCost() != utils.Round(cdr.Cost, cdre.roundDecimals, utils.ROUNDING_MIDDLE) {
t.Error("Unexpected TotalCost: ", cdre.TotalCost())
}
}
开发者ID:intralanman,项目名称:cgrates,代码行数:60,代码来源:fixedwidth_test.go
示例9: init
func init() {
cfgDcT, _ = config.NewDefaultCGRConfig()
if DEBUG {
acntDb, _ = NewMapStorage()
} else {
acntDb, _ = NewRedisStorage("127.0.0.1:6379", 13, "", utils.MSGPACK)
}
acntDb.CacheAccounting(nil, nil, nil, nil)
}
开发者ID:intralanman,项目名称:cgrates,代码行数:9,代码来源:handler_derivedcharging_test.go
示例10: TestConnectRedis
func TestConnectRedis(t *testing.T) {
if !*testLocal {
return
}
cfg, _ = config.NewDefaultCGRConfig()
rds, err = NewRedisStorage(fmt.Sprintf("%s:%s", cfg.RatingDBHost, cfg.RatingDBPort), 4, cfg.RatingDBPass, cfg.DBDataEncoding)
if err != nil {
t.Fatal("Could not connect to Redis", err.Error())
}
}
开发者ID:intralanman,项目名称:cgrates,代码行数:10,代码来源:storage_redis_local_test.go
示例11: TestMongoCreateTables
func TestMongoCreateTables(t *testing.T) {
if !*testLocal {
return
}
cgrConfig, _ := config.NewDefaultCGRConfig()
var err error
if mongoDb, err = NewMongoStorage("localhost", "27017", cgrConfig.StorDBName, cgrConfig.StorDBUser, cgrConfig.StorDBPass); err != nil {
t.Error("Error on opening database connection: ", err)
}
}
开发者ID:henrylee2cn,项目名称:cgrates,代码行数:10,代码来源:storage_mongo_local_test.go
示例12: TestConnectRedis
func TestConnectRedis(t *testing.T) {
if !*testLocal {
return
}
cfg, _ := config.NewDefaultCGRConfig()
rds, err = NewRedisStorage(fmt.Sprintf("%s:%s", cfg.TpDbHost, cfg.TpDbPort), 4, cfg.TpDbPass, cfg.DBDataEncoding, utils.REDIS_MAX_CONNS)
if err != nil {
t.Fatal("Could not connect to Redis", err.Error())
}
}
开发者ID:bhepp,项目名称:cgrates,代码行数:10,代码来源:storage_redis_local_test.go
示例13: TestAuthSetStorage
func TestAuthSetStorage(t *testing.T) {
ratingDbAuth, _ = engine.NewMapStorageJson()
engine.SetRatingStorage(ratingDbAuth)
acntDbAuth, _ = engine.NewMapStorageJson()
engine.SetAccountingStorage(acntDbAuth)
cfg, _ := config.NewDefaultCGRConfig()
config.SetCgrConfig(cfg)
rsponder = new(engine.Responder)
}
开发者ID:kevinlovesing,项目名称:cgrates,代码行数:10,代码来源:auth_test.go
示例14: TestFsEvGetExtraFields
func TestFsEvGetExtraFields(t *testing.T) {
cfg, _ := config.NewDefaultCGRConfig()
cfg.SmFsConfig.ExtraFields = []*utils.RSRField{&utils.RSRField{Id: "Channel-Read-Codec-Name"}, &utils.RSRField{Id: "Channel-Write-Codec-Name"}, &utils.RSRField{Id: "NonExistingHeader"}}
config.SetCgrConfig(cfg)
ev := new(FSEvent).AsEvent(hangupEv)
expectedExtraFields := map[string]string{"Channel-Read-Codec-Name": "SPEEX", "Channel-Write-Codec-Name": "SPEEX", "NonExistingHeader": ""}
if extraFields := ev.GetExtraFields(); !reflect.DeepEqual(expectedExtraFields, extraFields) {
t.Errorf("Expecting: %+v, received: %+v", expectedExtraFields, extraFields)
}
}
开发者ID:bhepp,项目名称:cgrates,代码行数:10,代码来源:fsevent_test.go
示例15: TestFirstNonEmpty
func TestFirstNonEmpty(t *testing.T) {
fsCdrCfg, _ = config.NewDefaultCGRConfig()
fsCdr, err := NewFSCdr(body, fsCdrCfg)
if err != nil {
t.Errorf("Error loading cdr: %v", err)
}
//fsc := fsCdr.(FSCdr)
if _, ok := fsCdr.vars["cgr_reqtype"]; !ok {
t.Error("Error parsing cdr: ", fsCdr)
}
}
开发者ID:iwada,项目名称:cgrates,代码行数:11,代码来源:fscdr_test.go
示例16: TestFwvRecordPassesCfgFilter
func TestFwvRecordPassesCfgFilter(t *testing.T) {
//record, configKey string) bool {
cgrConfig, _ := config.NewDefaultCGRConfig()
cdrcConfig := cgrConfig.CdrcProfiles["/var/spool/cgrates/cdrc/in"][0] // We don't really care that is for .csv since all we want to test are the filters
cdrcConfig.CdrFilter = utils.ParseRSRFieldsMustCompile(`~52:s/^0(\d{9})/+49${1}/(^+49123123120)`, utils.INFIELD_SEP)
fwvRp := &FwvRecordsProcessor{cdrcCfgs: cgrConfig.CdrcProfiles["/var/spool/cgrates/cdrc/in"]}
cdrLine := "CDR0000010 0 20120708181506000123451234 0040123123120 004 000018009980010001ISDN ABC 10Buiten uw regio EHV 00000009190000000009"
if passesFilter := fwvRp.recordPassesCfgFilter(cdrLine, cdrcConfig); !passesFilter {
t.Error("Not passes filter")
}
}
开发者ID:iwada,项目名称:cgrates,代码行数:11,代码来源:fwv_test.go
示例17: TestCsvDataMultiplyFactor
func TestCsvDataMultiplyFactor(t *testing.T) {
cgrConfig, _ := config.NewDefaultCGRConfig()
cdrcConfig := cgrConfig.CdrcProfiles["/var/spool/cgrates/cdrc/in"][0]
cdrcConfig.CdrSourceId = "TEST_CDRC"
cdrcConfig.ContentFields = []*config.CfgCdrField{&config.CfgCdrField{Tag: "TORField", Type: utils.META_COMPOSED, FieldId: utils.TOR, Value: []*utils.RSRField{&utils.RSRField{Id: "0"}}},
&config.CfgCdrField{Tag: "UsageField", Type: utils.META_COMPOSED, FieldId: utils.USAGE, Value: []*utils.RSRField{&utils.RSRField{Id: "1"}}}}
csvProcessor := &CsvRecordsProcessor{dfltCdrcCfg: cdrcConfig, cdrcCfgs: []*config.CdrcConfig{cdrcConfig}}
csvProcessor.cdrcCfgs[0].DataUsageMultiplyFactor = 0
cdrRow := []string{"*data", "1"}
rtCdr, err := csvProcessor.recordToStoredCdr(cdrRow, cdrcConfig)
if err != nil {
t.Error("Failed to parse CDR in rated cdr", err)
}
var sTime time.Time
expectedCdr := &engine.CDR{
CGRID: utils.Sha1("", sTime.String()),
ToR: cdrRow[0],
OriginHost: "0.0.0.0",
Source: "TEST_CDRC",
Usage: time.Duration(1) * time.Second,
ExtraFields: map[string]string{},
Cost: -1,
}
if !reflect.DeepEqual(expectedCdr, rtCdr) {
t.Errorf("Expected: \n%v, \nreceived: \n%v", expectedCdr, rtCdr)
}
csvProcessor.cdrcCfgs[0].DataUsageMultiplyFactor = 1024
expectedCdr = &engine.CDR{
CGRID: utils.Sha1("", sTime.String()),
ToR: cdrRow[0],
OriginHost: "0.0.0.0",
Source: "TEST_CDRC",
Usage: time.Duration(1024) * time.Second,
ExtraFields: map[string]string{},
Cost: -1,
}
if rtCdr, _ := csvProcessor.recordToStoredCdr(cdrRow, cdrcConfig); !reflect.DeepEqual(expectedCdr, rtCdr) {
t.Errorf("Expected: \n%v, \nreceived: \n%v", expectedCdr, rtCdr)
}
cdrRow = []string{"*voice", "1"}
expectedCdr = &engine.CDR{
CGRID: utils.Sha1("", sTime.String()),
ToR: cdrRow[0],
OriginHost: "0.0.0.0",
Source: "TEST_CDRC",
Usage: time.Duration(1) * time.Second,
ExtraFields: map[string]string{},
Cost: -1,
}
if rtCdr, _ := csvProcessor.recordToStoredCdr(cdrRow, cdrcConfig); !reflect.DeepEqual(expectedCdr, rtCdr) {
t.Errorf("Expected: \n%v, \nreceived: \n%v", expectedCdr, rtCdr)
}
}
开发者ID:eloycoto,项目名称:cgrates,代码行数:53,代码来源:csv_test.go
示例18: TestNewSureTaxRequest
func TestNewSureTaxRequest(t *testing.T) {
CGRID := utils.Sha1("dsafdsaf", time.Date(2013, 11, 7, 8, 42, 20, 0, time.UTC).String())
cdr := &CDR{CGRID: CGRID, OrderID: 123, ToR: utils.VOICE,
OriginID: "dsafdsaf", OriginHost: "192.168.1.1", Source: utils.UNIT_TEST, RequestType: 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), RunID: utils.DEFAULT_RUNID,
Usage: time.Duration(12) * time.Second, PDD: time.Duration(7) * time.Second,
ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}, Cost: 1.01, Rated: true,
}
cfg, _ := config.NewDefaultCGRConfig()
stCfg := cfg.SureTaxCfg()
stCfg.ClientNumber = "000000000"
stCfg.ValidationKey = "19491161-F004-4F44-BDB3-E976D6739A64"
stCfg.Timezone = time.UTC
eSTRequest := &STRequest{
ClientNumber: "000000000",
ValidationKey: "19491161-F004-4F44-BDB3-E976D6739A64",
DataYear: "2013",
DataMonth: "11",
TotalRevenue: 1.01,
ReturnFileCode: "0",
ClientTracking: CGRID,
ResponseGroup: "03",
ResponseType: "D4",
ItemList: []*STRequestItem{
&STRequestItem{
CustomerNumber: "1001",
OrigNumber: "1001",
TermNumber: "1002",
BillToNumber: "",
TransDate: "2013-11-07T08:42:26",
Revenue: 1.01,
Units: 1,
UnitType: "00",
Seconds: 12,
TaxIncludedCode: "0",
TaxSitusRule: "04",
TransTypeCode: "010101",
SalesTypeCode: "R",
RegulatoryCode: "03",
TaxExemptionCodeList: []string{},
},
},
}
jsnReq, _ := json.Marshal(eSTRequest)
eSureTaxRequest := &SureTaxRequest{Request: string(jsnReq)}
if stReq, err := NewSureTaxRequest(cdr, stCfg); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(eSureTaxRequest, stReq) {
t.Errorf("Expecting: %s, received: %s", string(eSureTaxRequest.Request), string(stReq.Request))
}
}
开发者ID:eloycoto,项目名称:cgrates,代码行数:52,代码来源:suretax_test.go
示例19: TestOsipsEventGetValues
func TestOsipsEventGetValues(t *testing.T) {
cfg, _ := config.NewDefaultCGRConfig()
config.SetCgrConfig(cfg)
setupTime, _ := osipsEv.GetSetupTime(utils.META_DEFAULT, "")
eSetupTime, _ := utils.ParseTimeDetectLayout("1406370492", "")
answerTime, _ := osipsEv.GetAnswerTime(utils.META_DEFAULT, "")
eAnswerTime, _ := utils.ParseTimeDetectLayout("1406370499", "")
dur, _ := osipsEv.GetDuration(utils.META_DEFAULT)
pdd, _ := osipsEv.GetPdd(utils.META_DEFAULT)
endTime, _ := osipsEv.GetEndTime(utils.META_DEFAULT, "")
if osipsEv.GetName() != "E_ACC_CDR" ||
osipsEv.GetCgrId("") != utils.Sha1("ODVkMDI2Mzc2MDY5N2EzODhjNTAzNTdlODhiZjRlYWQ", setupTime.UTC().String()) ||
osipsEv.GetUUID() != "ODVkMDI2Mzc2MDY5N2EzODhjNTAzNTdlODhiZjRlYWQ" ||
osipsEv.GetDirection(utils.META_DEFAULT) != utils.OUT ||
osipsEv.GetSubject(utils.META_DEFAULT) != "dan" ||
osipsEv.GetAccount(utils.META_DEFAULT) != "dan" ||
osipsEv.GetDestination(utils.META_DEFAULT) != "+4986517174963" ||
osipsEv.GetCallDestNr(utils.META_DEFAULT) != "+4986517174963" ||
osipsEv.GetCategory(utils.META_DEFAULT) != cfg.DefaultCategory ||
osipsEv.GetTenant(utils.META_DEFAULT) != "itsyscom.com" ||
osipsEv.GetReqType(utils.META_DEFAULT) != utils.META_PREPAID ||
!setupTime.Equal(eSetupTime) ||
!answerTime.Equal(eAnswerTime) ||
!endTime.Equal(eAnswerTime.Add(dur)) ||
dur != time.Duration(20*time.Second) ||
pdd != time.Duration(3)*time.Second ||
osipsEv.GetSupplier(utils.META_DEFAULT) != "supplier3" ||
osipsEv.GetDisconnectCause(utils.META_DEFAULT) != "200" ||
osipsEv.GetOriginatorIP(utils.META_DEFAULT) != "172.16.254.77" {
t.Error("GetValues not matching: ", osipsEv.GetName() != "E_ACC_CDR",
osipsEv.GetCgrId("") != utils.Sha1("ODVkMDI2Mzc2MDY5N2EzODhjNTAzNTdlODhiZjRlYWQ", setupTime.UTC().String()),
osipsEv.GetUUID() != "ODVkMDI2Mzc2MDY5N2EzODhjNTAzNTdlODhiZjRlYWQ",
osipsEv.GetDirection(utils.META_DEFAULT) != utils.OUT,
osipsEv.GetSubject(utils.META_DEFAULT) != "dan",
osipsEv.GetAccount(utils.META_DEFAULT) != "dan",
osipsEv.GetDestination(utils.META_DEFAULT) != "+4986517174963",
osipsEv.GetCallDestNr(utils.META_DEFAULT) != "+4986517174963",
osipsEv.GetCategory(utils.META_DEFAULT) != cfg.DefaultCategory,
osipsEv.GetTenant(utils.META_DEFAULT) != "itsyscom.com",
osipsEv.GetReqType(utils.META_DEFAULT) != utils.META_PREPAID,
!setupTime.Equal(time.Date(2014, 7, 26, 12, 28, 12, 0, time.UTC)),
!answerTime.Equal(time.Date(2014, 7, 26, 12, 28, 19, 0, time.Local)),
!endTime.Equal(time.Date(2014, 7, 26, 12, 28, 39, 0, time.Local)),
dur != time.Duration(20*time.Second),
pdd != time.Duration(3)*time.Second,
osipsEv.GetSupplier(utils.META_DEFAULT) != "supplier3",
osipsEv.GetDisconnectCause(utils.META_DEFAULT) != "200",
osipsEv.GetOriginatorIP(utils.META_DEFAULT) != "172.16.254.77",
)
}
}
开发者ID:kevinlovesing,项目名称:cgrates,代码行数:51,代码来源:osipsevent_test.go
示例20: TestEventSelectiveHeaders
// Test here if the answer is selected out of headers we specify, even if not default defined
func TestEventSelectiveHeaders(t *testing.T) {
body := `Event-Name: RE_SCHEDULE
Core-UUID: 792e181c-b6e6-499c-82a1-52a778e7d82d
FreeSWITCH-Hostname: h1.ip-switch.net
FreeSWITCH-Switchname: h1.ip-switch.net
FreeSWITCH-IPv4: 88.198.12.156
FreeSWITCH-IPv6: %3A%3A1
Event-Date-Local: 2012-10-05%2013%3A41%3A38
Event-Date-GMT: Fri,%2005%20Oct%202012%2011%3A41%3A38%20GMT
Event-Date-Timestamp: 1349437298012866
Event-Calling-File: switch_scheduler.c
Event-Calling-Function: switch_scheduler_execute
Event-Calling-Line-Number: 65
Event-Sequence: 34263
Task-ID: 2
Task-Desc: heartbeat
Task-Group: core
Task-Runtime: 1349437318`
cfg, _ := config.NewDefaultCGRConfig()
config.SetCgrConfig(cfg)
ev := new(FSEvent).AsEvent(body)
setupTime, _ := ev.GetSetupTime("Event-Date-Local", "")
answerTime, _ := ev.GetAnswerTime("Event-Date-Local", "")
dur, _ := ev.GetDuration("Event-Calling-Line-Number")
if ev.GetReqType("FreeSWITCH-Hostname") != "h1.ip-switch.net" ||
ev.GetDirection("FreeSWITCH-Hostname") != "*out" ||
ev.GetTenant("FreeSWITCH-Hostname") != "h1.ip-switch.net" ||
ev.GetCategory("FreeSWITCH-Hostname") != "h1.ip-switch.net" ||
ev.GetAccount("FreeSWITCH-Hostname") != "h1.ip-switch.net" ||
ev.GetSubject("FreeSWITCH-Hostname") != "h1.ip-switch.net" ||
ev.GetDestination("FreeSWITCH-Hostname") != "h1.ip-switch.net" ||
setupTime != time.Date(2012, 10, 5, 13, 41, 38, 0, time.UTC) ||
answerTime != time.Date(2012, 10, 5, 13, 41, 38, 0, time.UTC) ||
dur != time.Duration(65)*time.Second ||
ev.GetSupplier("FreeSWITCH-Hostname") != "h1.ip-switch.net" ||
ev.GetDisconnectCause("FreeSWITCH-Hostname") != "h1.ip-switch.net" {
t.Error("Values out of static not matching",
ev.GetReqType("FreeSWITCH-Hostname") != "h1.ip-switch.net",
ev.GetDirection("FreeSWITCH-Hostname") != "*out",
ev.GetTenant("FreeSWITCH-Hostname") != "h1.ip-switch.net",
ev.GetCategory("FreeSWITCH-Hostname") != "h1.ip-switch.net",
ev.GetAccount("FreeSWITCH-Hostname") != "h1.ip-switch.net",
ev.GetSubject("FreeSWITCH-Hostname") != "h1.ip-switch.net",
ev.GetDestination("FreeSWITCH-Hostname") != "h1.ip-switch.net",
setupTime != time.Date(2012, 10, 5, 13, 41, 38, 0, time.UTC),
answerTime != time.Date(2012, 10, 5, 13, 41, 38, 0, time.UTC),
dur != time.Duration(65)*time.Second,
ev.GetSupplier("FreeSWITCH-Hostname") != "h1.ip-switch.net",
ev.GetDisconnectCause("FreeSWITCH-Hostname") != "h1.ip-switch.net")
}
}
开发者ID:bhepp,项目名称:cgrates,代码行数:52,代码来源:fsevent_test.go
注:本文中的github.com/cgrates/cgrates/config.NewDefaultCGRConfig函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论