Best Go-testdeep code snippet using td.stringPointer
replicate_it_test.go
Source:replicate_it_test.go
1//go:build integration2// +build integration3/*4Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments5Copyright (C) ITsysCOM GmbH6This program is free software: you can redistribute it and/or modify7it under the terms of the GNU General Public License as published by8the Free Software Foundation, either version 3 of the License, or9(at your option) any later version.10This program is distributed in the hope that it will be useful,11but WITHOUT ANY WARRANTY; without even the implied warranty of12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13GNU General Public License for more details.14You should have received a copy of the GNU General Public License15along with this program. If not, see <http://www.gnu.org/licenses/>16*/17package v118import (19 "path"20 "reflect"21 "testing"22 "time"23 "github.com/cgrates/cgrates/config"24 "github.com/cgrates/cgrates/engine"25 "github.com/cgrates/cgrates/utils"26)27var (28 sTestsInternalReplicateIT = []func(t *testing.T){29 testInternalReplicateITInitCfg,30 testInternalReplicateITDataFlush,31 testInternalReplicateITStartEngine,32 testInternalReplicateITRPCConn,33 testInternalReplicateLoadDataInInternalEngine,34 testInternalReplicateITDestination,35 testInternalReplicateITAttributeProfile,36 testInternalReplicateITRatingProfile,37 testInternalReplicateITRouteProfile,38 testInternalReplicateITStatQueueProfile,39 testInternalReplicateITDispatcherProfile,40 testInternalReplicateITChargerProfile,41 testInternalReplicateITDispatcherHost,42 testInternalReplicateITFilter,43 testInternalReplicateITResourceProfile,44 testInternalReplicateITActions,45 testInternalReplicateITActionPlan,46 testInternalReplicateITThresholdProfile,47 testInternalReplicateITSetAccount,48 testInternalReplicateITActionTrigger,49 testInternalReplicateITThreshold,50 testInternalReplicateITLoadIds,51 testInternalReplicateITKillEngine,52 }53)54func TestInternalReplicateIT(t *testing.T) {55 internalCfgDirPath = "internal"56 switch *dbType {57 case utils.MetaInternal:58 t.SkipNow()59 case utils.MetaMySQL:60 engineOneCfgDirPath = "engine1_redis"61 engineTwoCfgDirPath = "engine2_redis"62 case utils.MetaMongo:63 engineOneCfgDirPath = "engine1_mongo"64 engineTwoCfgDirPath = "engine2_mongo"65 case utils.MetaPostgres:66 t.SkipNow()67 default:68 t.Fatal("Unknown Database type")69 }70 if *encoding == utils.MetaGOB {71 internalCfgDirPath += "_gob"72 }73 for _, stest := range sTestsInternalReplicateIT {74 t.Run(*dbType, stest)75 }76}77func testInternalReplicateITInitCfg(t *testing.T) {78 var err error79 internalCfgPath = path.Join(*dataDir, "conf", "samples", "replication", internalCfgDirPath)80 internalCfg, err = config.NewCGRConfigFromPath(internalCfgPath)81 if err != nil {82 t.Error(err)83 }84 // prepare config for engine185 engineOneCfgPath = path.Join(*dataDir, "conf", "samples", "replication", engineOneCfgDirPath)86 engineOneCfg, err = config.NewCGRConfigFromPath(engineOneCfgPath)87 if err != nil {88 t.Error(err)89 }90 // prepare config for engine291 engineTwoCfgPath = path.Join(*dataDir, "conf", "samples", "replication", engineTwoCfgDirPath)92 engineTwoCfg, err = config.NewCGRConfigFromPath(engineTwoCfgPath)93 if err != nil {94 t.Error(err)95 }96}97func testInternalReplicateITDataFlush(t *testing.T) {98 if err := engine.InitDataDb(engineOneCfg); err != nil {99 t.Fatal(err)100 }101 if err := engine.InitDataDb(engineTwoCfg); err != nil {102 t.Fatal(err)103 }104}105func testInternalReplicateITStartEngine(t *testing.T) {106 if _, err := engine.StartEngine(engineOneCfgPath, 500); err != nil {107 t.Fatal(err)108 }109 if _, err := engine.StartEngine(engineTwoCfgPath, 500); err != nil {110 t.Fatal(err)111 }112 if _, err := engine.StartEngine(internalCfgPath, 500); err != nil {113 t.Fatal(err)114 }115}116func testInternalReplicateITRPCConn(t *testing.T) {117 var err error118 engineOneRPC, err = newRPCClient(engineOneCfg.ListenCfg())119 if err != nil {120 t.Fatal(err)121 }122 engineTwoRPC, err = newRPCClient(engineTwoCfg.ListenCfg())123 if err != nil {124 t.Fatal(err)125 }126 internalRPC, err = newRPCClient(internalCfg.ListenCfg())127 if err != nil {128 t.Fatal(err)129 }130}131func testInternalReplicateLoadDataInInternalEngine(t *testing.T) {132 var reply string133 attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")}134 if err := internalRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil {135 t.Error(err)136 }137 time.Sleep(100 * time.Millisecond)138}139func testInternalReplicateITDestination(t *testing.T) {140 //check141 rpl := &engine.Destination{}142 if err := engineOneRPC.Call(utils.APIerSv1GetDestination, utils.StringPointer("testDestination"), &rpl); err == nil || err.Error() != utils.ErrNotFound.Error() {143 t.Error(err)144 }145 if err := engineTwoRPC.Call(utils.APIerSv1GetDestination, utils.StringPointer("testDestination"), &rpl); err == nil || err.Error() != utils.ErrNotFound.Error() {146 t.Error(err)147 }148 //set149 attrs := utils.AttrSetDestination{Id: "testDestination", Prefixes: []string{"004", "005"}}150 var reply string151 if err := internalRPC.Call(utils.APIerSv1SetDestination, &attrs, &reply); err != nil {152 t.Error("Unexpected error", err.Error())153 } else if reply != utils.OK {154 t.Error("Unexpected reply returned", reply)155 }156 eDst := &engine.Destination{157 Id: "testDestination",158 Prefixes: []string{"004", "005"},159 }160 // check161 if err := engineOneRPC.Call(utils.APIerSv1GetDestination, utils.StringPointer("testDestination"), &rpl); err != nil {162 t.Error(err)163 } else if !reflect.DeepEqual(eDst, rpl) {164 t.Errorf("Expected: %v,\n received: %v", eDst, rpl)165 }166 if err := engineTwoRPC.Call(utils.APIerSv1GetDestination, utils.StringPointer("testDestination"), &rpl); err != nil {167 t.Error(err)168 } else if !reflect.DeepEqual(eDst, rpl) {169 t.Errorf("Expected: %v,\n received: %v", eDst, rpl)170 }171 // remove172 attr := &AttrRemoveDestination{DestinationIDs: []string{"testDestination"}, Prefixes: []string{"004", "005"}}173 if err := internalRPC.Call(utils.APIerSv1RemoveDestination, &attr, &reply); err != nil {174 t.Error("Unexpected error", err.Error())175 } else if reply != utils.OK {176 t.Errorf("Unexpected reply returned: %+v", reply)177 }178 // check179 if err := engineOneRPC.Call(utils.APIerSv1GetDestination, utils.StringPointer("testDestination"), &rpl); err == nil || err.Error() != utils.ErrNotFound.Error() {180 t.Error(err)181 }182 if err := engineTwoRPC.Call(utils.APIerSv1GetDestination, utils.StringPointer("testDestination"), &rpl); err == nil || err.Error() != utils.ErrNotFound.Error() {183 t.Error(err)184 }185}186func testInternalReplicateITAttributeProfile(t *testing.T) {187 //set188 alsPrf := &engine.AttributeProfileWithAPIOpts{189 AttributeProfile: &engine.AttributeProfile{190 Tenant: "cgrates.org",191 ID: "ATTR_CDRE",192 Contexts: []string{"*cdre"},193 FilterIDs: []string{"*string:~*req.Subject:1001"},194 ActivationInterval: &utils.ActivationInterval{195 ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),196 ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),197 },198 Attributes: []*engine.Attribute{199 {200 Path: utils.MetaReq + utils.NestingSep + utils.Subject,201 Value: config.NewRSRParsersMustCompile("ATTR_SUBJECT", utils.InfieldSep),202 },203 {204 Path: utils.MetaReq + utils.NestingSep + utils.Category,205 Value: config.NewRSRParsersMustCompile("ATTR_CATEGORY", utils.InfieldSep),206 },207 },208 Weight: 20,209 },210 }211 alsPrf.Compile()212 var result string213 if err := internalRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil {214 t.Error(err)215 } else if result != utils.OK {216 t.Error("Unexpected reply returned", result)217 }218 // check219 var reply *engine.AttributeProfile220 if err := engineOneRPC.Call(utils.APIerSv1GetAttributeProfile,221 utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: alsPrf.Tenant, ID: alsPrf.ID}}, &reply); err != nil {222 t.Fatal(err)223 }224 reply.Compile()225 if !reflect.DeepEqual(alsPrf.AttributeProfile, reply) {226 t.Errorf("Expecting : %+v, received: %+v", alsPrf.AttributeProfile, reply)227 }228 if err := engineTwoRPC.Call(utils.APIerSv1GetAttributeProfile,229 utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: alsPrf.Tenant, ID: alsPrf.ID}}, &reply); err != nil {230 t.Fatal(err)231 }232 reply.Compile()233 if !reflect.DeepEqual(alsPrf.AttributeProfile, reply) {234 t.Errorf("Expecting : %+v, received: %+v", alsPrf.AttributeProfile, reply)235 }236 reply = &engine.AttributeProfile{}237 //remove238 if err := internalRPC.Call(utils.APIerSv1RemoveAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{239 Tenant: alsPrf.Tenant, ID: alsPrf.ID}}, &result); err != nil {240 t.Error(err)241 } else if result != utils.OK {242 t.Error("Unexpected reply returned", result)243 }244 //check again245 if err := engineOneRPC.Call(utils.APIerSv1GetAttributeProfile,246 utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: alsPrf.Tenant, ID: alsPrf.ID}}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {247 t.Errorf("Expecting: %+v received: %+v", utils.ErrNotFound, err)248 }249 if err := engineTwoRPC.Call(utils.APIerSv1GetAttributeProfile,250 utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: alsPrf.Tenant, ID: alsPrf.ID}}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {251 t.Errorf("Expecting: %+v received: %+v", utils.ErrNotFound, err)252 }253}254func testInternalReplicateITRatingProfile(t *testing.T) {255 //check256 var rpl engine.RatingProfile257 attrGetRatingProfile := &utils.AttrGetRatingProfile{258 Tenant: "cgrates.org",259 Category: "call",260 Subject: "Subject"}261 if err := engineOneRPC.Call(utils.APIerSv1GetRatingProfile, attrGetRatingProfile, &rpl); err == nil || err.Error() != utils.ErrNotFound.Error() {262 t.Errorf("Expecting: %+v received: %+v", utils.ErrNotFound, err)263 }264 if err := engineTwoRPC.Call(utils.APIerSv1GetRatingProfile, attrGetRatingProfile, &rpl); err == nil || err.Error() != utils.ErrNotFound.Error() {265 t.Errorf("Expecting: %+v received: %+v", utils.ErrNotFound, err)266 }267 // set268 var reply string269 attrSetRatingProfile := &utils.AttrSetRatingProfile{270 Overwrite: true,271 Tenant: "cgrates.org",272 Category: "call",273 Subject: "Subject",274 RatingPlanActivations: []*utils.TPRatingActivation{275 {276 ActivationTime: "2012-01-01T00:00:00Z",277 RatingPlanId: "RP_1001",278 FallbackSubjects: "FallbackSubjects"},279 }}280 if err := internalRPC.Call(utils.APIerSv1SetRatingProfile, &attrSetRatingProfile, &reply); err != nil {281 t.Error(err)282 } else if reply != utils.OK {283 t.Error(reply)284 }285 // Calling the second time should not raise EXISTS286 if err := internalRPC.Call(utils.APIerSv1SetRatingProfile, &attrSetRatingProfile, &reply); err != nil {287 t.Error(err)288 }289 //check290 actTime, err := utils.ParseTimeDetectLayout("2012-01-01T00:00:00Z", utils.EmptyString)291 if err != nil {292 t.Error(err)293 }294 expected := engine.RatingProfile{295 Id: "*out:cgrates.org:call:Subject",296 RatingPlanActivations: engine.RatingPlanActivations{297 {298 ActivationTime: actTime,299 RatingPlanId: "RP_1001",300 FallbackKeys: []string{"*out:cgrates.org:call:FallbackSubjects"},301 },302 },303 }304 if err := engineOneRPC.Call(utils.APIerSv1GetRatingProfile, attrGetRatingProfile, &rpl); err != nil {305 t.Error(err)306 } else if !reflect.DeepEqual(expected, rpl) {307 t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expected), utils.ToJSON(rpl))308 }309 if err := engineTwoRPC.Call(utils.APIerSv1GetRatingProfile, attrGetRatingProfile, &rpl); err != nil {310 t.Error(err)311 } else if !reflect.DeepEqual(expected, rpl) {312 t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expected), utils.ToJSON(rpl))313 }314}315func testInternalReplicateITRouteProfile(t *testing.T) {316 // check317 var reply *engine.RouteProfile318 if err := engineOneRPC.Call(utils.APIerSv1GetRouteProfile,319 &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err == nil ||320 err.Error() != utils.ErrNotFound.Error() {321 t.Error(err)322 }323 if err := engineTwoRPC.Call(utils.APIerSv1GetRouteProfile,324 &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err == nil ||325 err.Error() != utils.ErrNotFound.Error() {326 t.Error(err)327 }328 rPrf := &RouteWithAPIOpts{329 RouteProfile: &engine.RouteProfile{330 Tenant: "cgrates.org",331 ID: "TEST_PROFILE1",332 Sorting: "Sort1",333 SortingParameters: []string{"Param1", "Param2"},334 Routes: []*engine.Route{335 {336 ID: "SPL1",337 RatingPlanIDs: []string{"RP1"},338 AccountIDs: []string{"Acc"},339 ResourceIDs: []string{"Res1", "ResGroup2"},340 StatIDs: []string{"Stat1"},341 Weight: 20,342 Blocker: false,343 RouteParameters: "SortingParameter1",344 },345 },346 Weight: 10,347 },348 }349 // set350 var result string351 if err := internalRPC.Call(utils.APIerSv1SetRouteProfile, rPrf, &result); err != nil {352 t.Error(err)353 } else if result != utils.OK {354 t.Error("Unexpected reply returned", result)355 }356 // check357 if err := engineOneRPC.Call(utils.APIerSv1GetRouteProfile,358 &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err != nil {359 t.Error(err)360 } else if !reflect.DeepEqual(rPrf.RouteProfile, reply) {361 t.Errorf("Expecting: %+v, received: %+v", rPrf.RouteProfile, reply)362 }363 if err := engineTwoRPC.Call(utils.APIerSv1GetRouteProfile,364 &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err != nil {365 t.Error(err)366 } else if !reflect.DeepEqual(rPrf.RouteProfile, reply) {367 t.Errorf("Expecting: %+v, received: %+v", rPrf.RouteProfile, reply)368 }369 // remove370 var resp string371 if err := internalRPC.Call(utils.APIerSv1RemoveRouteProfile,372 &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}}, &resp); err != nil {373 t.Error(err)374 } else if resp != utils.OK {375 t.Error("Unexpected reply returned", resp)376 }377 // check378 if err := engineOneRPC.Call(utils.APIerSv1GetRouteProfile,379 &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err == nil ||380 err.Error() != utils.ErrNotFound.Error() {381 t.Error(err)382 }383 if err := engineTwoRPC.Call(utils.APIerSv1GetRouteProfile,384 &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err == nil ||385 err.Error() != utils.ErrNotFound.Error() {386 t.Error(err)387 }388}389func testInternalReplicateITStatQueueProfile(t *testing.T) {390 // check391 var reply *engine.StatQueueProfile392 if err := engineOneRPC.Call(utils.APIerSv1GetStatQueueProfile,393 &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err == nil ||394 err.Error() != utils.ErrNotFound.Error() {395 t.Error(err)396 }397 if err := engineTwoRPC.Call(utils.APIerSv1GetStatQueueProfile,398 &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err == nil ||399 err.Error() != utils.ErrNotFound.Error() {400 t.Error(err)401 }402 // set403 statConfig = &engine.StatQueueProfileWithAPIOpts{404 StatQueueProfile: &engine.StatQueueProfile{405 Tenant: tenant,406 ID: "TEST_PROFILE1",407 ActivationInterval: &utils.ActivationInterval{408 ActivationTime: time.Date(2020, 4, 18, 14, 25, 0, 0, time.UTC),409 ExpiryTime: time.Date(2020, 4, 18, 14, 25, 0, 0, time.UTC),410 },411 QueueLength: 10,412 TTL: 10 * time.Second,413 Metrics: []*engine.MetricWithFilters{414 {415 MetricID: "*sum",416 },417 {418 MetricID: "*acd",419 },420 },421 ThresholdIDs: []string{"Val1", "Val2"},422 Blocker: true,423 Stored: true,424 Weight: 20,425 MinItems: 1,426 },427 }428 var result string429 if err := internalRPC.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil {430 t.Error(err)431 } else if result != utils.OK {432 t.Error("Unexpected reply returned", result)433 }434 //check435 if err := engineOneRPC.Call(utils.APIerSv1GetStatQueueProfile,436 &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err != nil {437 t.Error(err)438 } else if !reflect.DeepEqual(statConfig.StatQueueProfile, reply) {439 t.Errorf("Expecting: %+v, received: %+v", statConfig.StatQueueProfile, reply)440 }441 if err := engineTwoRPC.Call(utils.APIerSv1GetStatQueueProfile,442 &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err != nil {443 t.Error(err)444 } else if !reflect.DeepEqual(statConfig.StatQueueProfile, reply) {445 t.Errorf("Expecting: %+v, received: %+v", statConfig.StatQueueProfile, reply)446 }447 //remove448 if err := internalRPC.Call(utils.APIerSv1RemoveStatQueueProfile,449 &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &result); err != nil {450 t.Error(err)451 } else if result != utils.OK {452 t.Error("Unexpected reply returned", result)453 }454 // check455 if err := engineOneRPC.Call(utils.APIerSv1GetStatQueueProfile,456 &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err == nil ||457 err.Error() != utils.ErrNotFound.Error() {458 t.Error(err)459 }460 if err := engineTwoRPC.Call(utils.APIerSv1GetStatQueueProfile,461 &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err == nil ||462 err.Error() != utils.ErrNotFound.Error() {463 t.Error(err)464 }465}466func testInternalReplicateITDispatcherProfile(t *testing.T) {467 // check468 var reply string469 if err := engineOneRPC.Call(utils.APIerSv1GetDispatcherProfile,470 &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"},471 &reply); err == nil || err.Error() != utils.ErrDSPProfileNotFound.Error() {472 t.Error(err)473 }474 if err := engineTwoRPC.Call(utils.APIerSv1GetDispatcherProfile,475 &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"},476 &reply); err == nil || err.Error() != utils.ErrDSPProfileNotFound.Error() {477 t.Error(err)478 }479 // set480 dispatcherProfile = &DispatcherWithAPIOpts{481 DispatcherProfile: &engine.DispatcherProfile{482 Tenant: "cgrates.org",483 ID: "Dsp1",484 FilterIDs: []string{"*string:~*req.Account:1001"},485 Subsystems: []string{utils.MetaAny},486 Strategy: utils.MetaFirst,487 Weight: 20,488 },489 }490 if err := internalRPC.Call(utils.APIerSv1SetDispatcherProfile, dispatcherProfile,491 &reply); err != nil {492 t.Error(err)493 } else if reply != utils.OK {494 t.Errorf("Expecting : %+v, received: %+v", utils.OK, reply)495 }496 // check497 var dsp *engine.DispatcherProfile498 if err := engineOneRPC.Call(utils.APIerSv1GetDispatcherProfile,499 &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"},500 &dsp); err != nil {501 t.Error(err)502 } else if !reflect.DeepEqual(dispatcherProfile.DispatcherProfile, dsp) {503 t.Errorf("Expecting : %+v, received: %+v", dispatcherProfile.DispatcherProfile, dsp)504 }505 if err := engineTwoRPC.Call(utils.APIerSv1GetDispatcherProfile,506 &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"},507 &dsp); err != nil {508 t.Error(err)509 } else if !reflect.DeepEqual(dispatcherProfile.DispatcherProfile, dsp) {510 t.Errorf("Expecting : %+v, received: %+v", dispatcherProfile.DispatcherProfile, dsp)511 }512 // remove513 var result string514 if err := internalRPC.Call(utils.APIerSv1RemoveDispatcherProfile,515 &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"}}, &result); err != nil {516 t.Error(err)517 } else if result != utils.OK {518 t.Errorf("Expecting : %+v, received: %+v", utils.OK, result)519 }520 // remove again521 if err := internalRPC.Call(utils.APIerSv1RemoveDispatcherProfile,522 &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"}}, &result); err == nil || err.Error() != utils.ErrDSPProfileNotFound.Error() {523 t.Error(err)524 }525 // check again526 if err := engineOneRPC.Call(utils.APIerSv1GetDispatcherProfile,527 &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"}, &dsp); err == nil || err.Error() != utils.ErrDSPProfileNotFound.Error() {528 t.Error(err)529 }530 if err := engineTwoRPC.Call(utils.APIerSv1GetDispatcherProfile,531 &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"}, &dsp); err == nil || err.Error() != utils.ErrDSPProfileNotFound.Error() {532 t.Error(err)533 }534}535func testInternalReplicateITChargerProfile(t *testing.T) {536 // check537 var reply *engine.ChargerProfile538 if err := engineOneRPC.Call(utils.APIerSv1GetChargerProfile,539 &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {540 t.Error(err)541 }542 if err := engineTwoRPC.Call(utils.APIerSv1GetChargerProfile,543 &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {544 t.Error(err)545 }546 // set547 chargerProfile = &ChargerWithAPIOpts{548 ChargerProfile: &engine.ChargerProfile{549 Tenant: "cgrates.org",550 ID: "ApierTest",551 FilterIDs: []string{"*string:~*req.Account:1001", "*string:~*opts.Account:1002"},552 ActivationInterval: &utils.ActivationInterval{553 ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),554 ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),555 },556 RunID: utils.MetaDefault,557 AttributeIDs: []string{"Attr1", "Attr2"},558 Weight: 20,559 },560 }561 var result string562 if err := internalRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil {563 t.Error(err)564 } else if result != utils.OK {565 t.Error("Unexpected reply returned", result)566 }567 // check568 if err := engineOneRPC.Call(utils.APIerSv1GetChargerProfile,569 &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}, &reply); err != nil {570 t.Error(err)571 } else if !reflect.DeepEqual(chargerProfile.ChargerProfile, reply) {572 t.Errorf("Expecting : %+v, received: %+v", chargerProfile.ChargerProfile, reply)573 }574 if err := engineTwoRPC.Call(utils.APIerSv1GetChargerProfile,575 &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}, &reply); err != nil {576 t.Error(err)577 } else if !reflect.DeepEqual(chargerProfile.ChargerProfile, reply) {578 t.Errorf("Expecting : %+v, received: %+v", chargerProfile.ChargerProfile, reply)579 }580 // remove581 if err := internalRPC.Call(utils.APIerSv1RemoveChargerProfile,582 &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}, &result); err != nil {583 t.Error(err)584 } else if result != utils.OK {585 t.Error("Unexpected reply returned", result)586 }587 //check588 if err := engineOneRPC.Call(utils.APIerSv1GetChargerProfile,589 &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"},590 &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {591 t.Error(err)592 }593 if err := engineTwoRPC.Call(utils.APIerSv1GetChargerProfile,594 &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"},595 &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {596 t.Error(err)597 }598}599func testInternalReplicateITDispatcherHost(t *testing.T) {600 // check601 var reply string602 if err := engineOneRPC.Call(utils.APIerSv1GetDispatcherHost,603 &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"},604 &reply); err == nil || err.Error() != utils.ErrDSPHostNotFound.Error() {605 t.Error(err)606 }607 if err := engineTwoRPC.Call(utils.APIerSv1GetDispatcherHost,608 &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"},609 &reply); err == nil || err.Error() != utils.ErrDSPHostNotFound.Error() {610 t.Error(err)611 }612 dispatcherHost = &engine.DispatcherHostWithAPIOpts{613 DispatcherHost: &engine.DispatcherHost{614 Tenant: "cgrates.org",615 RemoteHost: &config.RemoteHost{616 ID: "DspHst1",617 Address: "*internal",618 },619 },620 }621 //set622 if err := internalRPC.Call(utils.APIerSv1SetDispatcherHost,623 dispatcherHost,624 &reply); err != nil {625 t.Error(err)626 } else if reply != utils.OK {627 t.Errorf("Expecting : %+v, received: %+v", utils.OK, reply)628 }629 // check630 var dsp *engine.DispatcherHost631 if err := engineOneRPC.Call(utils.APIerSv1GetDispatcherHost,632 &utils.TenantID{Tenant: "cgrates.org", ID: "DspHst1"},633 &dsp); err != nil {634 t.Error(err)635 } else if !reflect.DeepEqual(dispatcherHost.DispatcherHost, dsp) {636 t.Errorf("Expecting : %+v, received: %+v", dispatcherHost.DispatcherHost, dsp)637 }638 if err := engineTwoRPC.Call(utils.APIerSv1GetDispatcherHost,639 &utils.TenantID{Tenant: "cgrates.org", ID: "DspHst1"},640 &dsp); err != nil {641 t.Error(err)642 } else if !reflect.DeepEqual(dispatcherHost.DispatcherHost, dsp) {643 t.Errorf("Expecting : %+v, received: %+v", dispatcherHost.DispatcherHost, dsp)644 }645 // remove646 if err := internalRPC.Call(utils.APIerSv1RemoveDispatcherHost,647 &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "DspHst1"}},648 &reply); err != nil {649 t.Error(err)650 } else if reply != utils.OK {651 t.Errorf("Expecting : %+v, received: %+v", utils.OK, reply)652 }653 //check654 if err := engineOneRPC.Call(utils.APIerSv1GetDispatcherHost,655 &utils.TenantID{Tenant: "cgrates.org", ID: "DspHst1"},656 &dsp); err == nil || err.Error() != utils.ErrDSPHostNotFound.Error() {657 t.Error(err)658 }659 if err := engineTwoRPC.Call(utils.APIerSv1GetDispatcherHost,660 &utils.TenantID{Tenant: "cgrates.org", ID: "DspHst1"},661 &dsp); err == nil || err.Error() != utils.ErrDSPHostNotFound.Error() {662 t.Error(err)663 }664}665func testInternalReplicateITFilter(t *testing.T) {666 // check667 var reply *engine.Filter668 if err := engineOneRPC.Call(utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {669 t.Error(err)670 }671 if err := engineTwoRPC.Call(utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {672 t.Error(err)673 }674 //set675 filter = &engine.FilterWithAPIOpts{676 Filter: &engine.Filter{677 Tenant: "cgrates.org",678 ID: "Filter1",679 Rules: []*engine.FilterRule{680 {681 Element: "~*req.Account",682 Type: utils.MetaString,683 Values: []string{"1001", "1002"},684 },685 },686 ActivationInterval: &utils.ActivationInterval{687 ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),688 ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),689 },690 },691 }692 var rcv string693 if err := internalRPC.Call(utils.APIerSv1SetFilter, filter, &rcv); err != nil {694 t.Error(err)695 } else if rcv != utils.OK {696 t.Error("Unexpected reply returned", rcv)697 }698 // check699 if err := engineOneRPC.Call(utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}, &reply); err != nil {700 t.Error(err)701 } else if !reflect.DeepEqual(filter.Filter, reply) {702 t.Errorf("Expecting : %+v, received: %+v", filter.Filter, reply)703 }704 if err := engineTwoRPC.Call(utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}, &reply); err != nil {705 t.Error(err)706 } else if !reflect.DeepEqual(filter.Filter, reply) {707 t.Errorf("Expecting : %+v, received: %+v", filter.Filter, reply)708 }709 // remove710 var resp string711 if err := internalRPC.Call(utils.APIerSv1RemoveFilter,712 &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}}, &resp); err != nil {713 t.Error(err)714 } else if resp != utils.OK {715 t.Error("Unexpected reply returned", resp)716 }717 // check again718 if err := engineOneRPC.Call(utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {719 t.Error(err)720 }721 if err := engineTwoRPC.Call(utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {722 t.Error(err)723 }724}725func testInternalReplicateITResourceProfile(t *testing.T) {726 // check727 var reply *engine.ResourceProfile728 if err := engineOneRPC.Call(utils.APIerSv1GetResourceProfile,729 &utils.TenantID{Tenant: "cgrates.org", ID: "RES_GR_TEST"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {730 t.Error(err)731 }732 if err := engineTwoRPC.Call(utils.APIerSv1GetResourceProfile,733 &utils.TenantID{Tenant: "cgrates.org", ID: "RES_GR_TEST"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {734 t.Error(err)735 }736 // set737 rlsConfig = &engine.ResourceProfileWithAPIOpts{738 ResourceProfile: &engine.ResourceProfile{739 Tenant: "cgrates.org",740 ID: "RES_GR_TEST",741 FilterIDs: []string{"*string:~*req.Account:1001"},742 ActivationInterval: &utils.ActivationInterval{743 ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),744 ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),745 },746 UsageTTL: time.Nanosecond,747 Limit: 10,748 AllocationMessage: "MessageAllocation",749 Blocker: true,750 Stored: true,751 Weight: 20,752 ThresholdIDs: []string{"Val1"},753 },754 }755 var result string756 if err := internalRPC.Call(utils.APIerSv1SetResourceProfile, rlsConfig, &result); err != nil {757 t.Error(err)758 } else if result != utils.OK {759 t.Error("Unexpected reply returned", result)760 }761 // check762 if err := engineOneRPC.Call(utils.APIerSv1GetResourceProfile,763 &utils.TenantID{Tenant: "cgrates.org", ID: "RES_GR_TEST"}, &reply); err != nil {764 t.Error(err)765 } else if !reflect.DeepEqual(reply, rlsConfig.ResourceProfile) {766 t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(rlsConfig.ResourceProfile), utils.ToJSON(reply))767 }768 if err := engineTwoRPC.Call(utils.APIerSv1GetResourceProfile,769 &utils.TenantID{Tenant: "cgrates.org", ID: "RES_GR_TEST"}, &reply); err != nil {770 t.Error(err)771 } else if !reflect.DeepEqual(reply, rlsConfig.ResourceProfile) {772 t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(rlsConfig.ResourceProfile), utils.ToJSON(reply))773 }774 // remove775 if err := internalRPC.Call(utils.APIerSv1RemoveResourceProfile,776 &utils.TenantID{Tenant: "cgrates.org", ID: "RES_GR_TEST"}, &result); err != nil {777 t.Error(err)778 } else if result != utils.OK {779 t.Error("Unexpected reply returned", result)780 }781 // check again782 if err := engineOneRPC.Call(utils.APIerSv1GetResourceProfile,783 &utils.TenantID{Tenant: "cgrates.org", ID: "RES_GR_TEST"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {784 t.Error(err)785 }786 if err := engineTwoRPC.Call(utils.APIerSv1GetResourceProfile,787 &utils.TenantID{Tenant: "cgrates.org", ID: "RES_GR_TEST"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {788 t.Error(err)789 }790}791func testInternalReplicateITActions(t *testing.T) {792 // check793 var reply1 []*utils.TPAction794 if err := engineOneRPC.Call(utils.APIerSv1GetActions, utils.StringPointer("ACTS_1"), &reply1); err == nil || err.Error() != "SERVER_ERROR: NOT_FOUND" {795 t.Error(err)796 }797 if err := engineTwoRPC.Call(utils.APIerSv1GetActions, utils.StringPointer("ACTS_1"), &reply1); err == nil || err.Error() != "SERVER_ERROR: NOT_FOUND" {798 t.Error(err)799 }800 // set801 attrs1 := &V1AttrSetActions{802 ActionsId: "ACTS_1",803 Actions: []*V1TPAction{{804 Identifier: utils.MetaTopUpReset,805 BalanceType: utils.MetaMonetary,806 Units: 75.0,807 ExpiryTime: utils.MetaUnlimited,808 Weight: 20.0}}}809 var reply string810 if err := internalRPC.Call(utils.APIerSv1SetActions, &attrs1, &reply); err != nil {811 t.Error(err)812 } else if reply != utils.OK {813 t.Errorf("Unexpected reply returned: %s", reply)814 }815 if err := internalRPC.Call(utils.APIerSv1SetActions, &attrs1, &reply); err == nil || err.Error() != "EXISTS" {816 t.Error("Unexpected result on duplication: ", err)817 }818 // check819 eOut := []*utils.TPAction{{820 Identifier: utils.MetaTopUpReset,821 BalanceType: utils.MetaMonetary,822 Units: "75",823 BalanceWeight: "0",824 BalanceBlocker: "false",825 BalanceDisabled: "false",826 ExpiryTime: utils.MetaUnlimited,827 Weight: 20.0,828 }}829 if err := internalRPC.Call(utils.APIerSv1GetActions, utils.StringPointer("ACTS_1"), &reply1); err != nil {830 t.Error("Got error on APIerSv1.GetActions: ", err.Error())831 } else if !reflect.DeepEqual(eOut, reply1) {832 t.Errorf("Expected: %v, received: %v", utils.ToJSON(eOut), utils.ToJSON(reply1))833 }834 if err := engineOneRPC.Call(utils.APIerSv1GetActions, utils.StringPointer("ACTS_1"), &reply1); err != nil {835 t.Error("Got error on APIerSv1.GetActions: ", err.Error())836 } else if !reflect.DeepEqual(eOut, reply1) {837 t.Errorf("Expected: %v, received: %v", utils.ToJSON(eOut), utils.ToJSON(reply1))838 }839 if err := engineTwoRPC.Call(utils.APIerSv1GetActions, utils.StringPointer("ACTS_1"), &reply1); err != nil {840 t.Error("Got error on APIerSv1.GetActions: ", err.Error())841 } else if !reflect.DeepEqual(eOut, reply1) {842 t.Errorf("Expected: %v, received: %v", utils.ToJSON(eOut), utils.ToJSON(reply1))843 }844 // remove845 if err := internalRPC.Call(utils.APIerSv1RemoveActions,846 &AttrRemoveActions{847 ActionIDs: []string{"ACTS_1"}}, &reply); err != nil {848 t.Error("Got error on APIerSv1.RemoveActions: ", err.Error())849 } else if reply != utils.OK {850 t.Error("Unexpected reply when calling APIerSv1.RemoveActions: ", err.Error())851 }852 // check again853 if err := engineOneRPC.Call(utils.APIerSv1GetActions, utils.StringPointer("ACTS_1"), &reply1); err == nil || err.Error() != "SERVER_ERROR: NOT_FOUND" {854 t.Error(err)855 }856 if err := engineTwoRPC.Call(utils.APIerSv1GetActions, utils.StringPointer("ACTS_1"), &reply1); err == nil || err.Error() != "SERVER_ERROR: NOT_FOUND" {857 t.Error(err)858 }859}860func testInternalReplicateITActionPlan(t *testing.T) {861 var reply string862 if err := internalRPC.Call(utils.APIerSv2SetActions, &utils.AttrSetActions{863 ActionsId: "ACTS_1",864 Actions: []*utils.TPAction{{Identifier: utils.MetaLog}},865 }, &reply); err != nil && err.Error() != utils.ErrExists.Error() {866 t.Error(err)867 } else if reply != utils.OK {868 t.Errorf("Calling APIerSv2.SetActions received: %s", reply)869 }870 // check871 var aps []*engine.ActionPlan872 if err := engineOneRPC.Call(utils.APIerSv1GetActionPlan,873 &AttrGetActionPlan{ID: "ATMS_1"}, &aps); err == nil || err.Error() != utils.ErrNotFound.Error() {874 t.Errorf("Error at APIerSv1.GetActionPlan: %+v", err)875 }876 if err := engineTwoRPC.Call(utils.APIerSv1GetActionPlan,877 &AttrGetActionPlan{ID: "ATMS_1"}, &aps); err == nil || err.Error() != utils.ErrNotFound.Error() {878 t.Errorf("Error at APIerSv1.GetActionPlan: %+v", err)879 }880 // set881 atms1 := &AttrSetActionPlan{882 Id: "ATMS_1",883 ActionPlan: []*AttrActionPlan{884 {885 ActionsId: "ACTS_1",886 Time: utils.MetaASAP,887 Weight: 20.0},888 },889 }890 var reply1 string891 if err := internalRPC.Call(utils.APIerSv1SetActionPlan, &atms1, &reply1); err != nil {892 t.Error("Got error on APIerSv1.SetActionPlan: ", err.Error())893 } else if reply1 != utils.OK {894 t.Errorf("Unexpected reply returned: %s", reply1)895 }896 // check897 if err := engineOneRPC.Call(utils.APIerSv1GetActionPlan,898 &AttrGetActionPlan{ID: "ATMS_1"}, &aps); err != nil {899 t.Error(err)900 } else if len(aps) != 1 {901 t.Errorf("Expected: %v,\n received: %v", 1, len(aps))902 } else if aps[0].Id != "ATMS_1" {903 t.Errorf("Expected: ATMS_1,\n received: %v", aps[0].Id)904 } else if aps[0].ActionTimings[0].ActionsID != "ACTS_1" {905 t.Errorf("Expected: ACTS_1,\n received: %v", aps[0].ActionTimings[0].ActionsID)906 } else if aps[0].ActionTimings[0].Weight != 20.0 {907 t.Errorf("Expected: 20.0,\n received: %v", aps[0].ActionTimings[0].Weight)908 }909 if err := engineTwoRPC.Call(utils.APIerSv1GetActionPlan,910 &AttrGetActionPlan{ID: "ATMS_1"}, &aps); err != nil {911 t.Error(err)912 } else if len(aps) != 1 {913 t.Errorf("Expected: %v,\n received: %v", 1, len(aps))914 } else if aps[0].Id != "ATMS_1" {915 t.Errorf("Expected: ATMS_1,\n received: %v", aps[0].Id)916 } else if aps[0].ActionTimings[0].ActionsID != "ACTS_1" {917 t.Errorf("Expected: ACTS_1,\n received: %v", aps[0].ActionTimings[0].ActionsID)918 } else if aps[0].ActionTimings[0].Weight != 20.0 {919 t.Errorf("Expected: 20.0,\n received: %v", aps[0].ActionTimings[0].Weight)920 }921 // remove922 if err := internalRPC.Call(utils.APIerSv1RemoveActionPlan, &AttrGetActionPlan{923 ID: "ATMS_1"}, &reply); err != nil {924 t.Error(err)925 } else if reply != utils.OK {926 t.Error("Unexpected reply returned", reply)927 }928 //check again929 if err := engineOneRPC.Call(utils.APIerSv1GetActionPlan,930 &AttrGetActionPlan{ID: "ATMS_1"}, &aps); err == nil || err.Error() != utils.ErrNotFound.Error() {931 t.Errorf("Error: %+v, rcv: %+v", err, utils.ToJSON(aps))932 }933 if err := engineTwoRPC.Call(utils.APIerSv1GetActionPlan,934 &AttrGetActionPlan{ID: "ATMS_1"}, &aps); err == nil || err.Error() != utils.ErrNotFound.Error() {935 t.Errorf("Error: %+v, rcv: %+v", err, utils.ToJSON(aps))936 }937}938func testInternalReplicateITThresholdProfile(t *testing.T) {939 // check940 var reply *engine.ThresholdProfile941 if err := engineOneRPC.Call(utils.APIerSv1GetThresholdProfile,942 &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err == nil ||943 err.Error() != utils.ErrNotFound.Error() {944 t.Error(err)945 }946 if err := engineTwoRPC.Call(utils.APIerSv1GetThresholdProfile,947 &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err == nil ||948 err.Error() != utils.ErrNotFound.Error() {949 t.Error(err)950 }951 // set952 filter = &engine.FilterWithAPIOpts{953 Filter: &engine.Filter{954 Tenant: tenant,955 ID: "TestFilter",956 Rules: []*engine.FilterRule{{957 Element: "~*req.Account",958 Type: utils.MetaString,959 Values: []string{"1001"},960 }},961 ActivationInterval: &utils.ActivationInterval{962 ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),963 ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),964 },965 },966 }967 var result string968 if err := internalRPC.Call(utils.APIerSv1SetFilter, filter, &result); err != nil {969 t.Error(err)970 } else if result != utils.OK {971 t.Error("Unexpected reply returned", result)972 }973 tPrfl = &engine.ThresholdProfileWithAPIOpts{974 ThresholdProfile: &engine.ThresholdProfile{975 Tenant: tenant,976 ID: "TEST_PROFILE1",977 FilterIDs: []string{"TestFilter"},978 ActivationInterval: &utils.ActivationInterval{979 ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),980 ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),981 },982 MaxHits: 1,983 MinSleep: 5 * time.Minute,984 Blocker: false,985 Weight: 20.0,986 ActionIDs: []string{"ACT_1", "ACT_2"},987 Async: true,988 },989 }990 if err := internalRPC.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil {991 t.Error(err)992 } else if result != utils.OK {993 t.Error("Unexpected reply returned", result)994 }995 // check996 if err := engineOneRPC.Call(utils.APIerSv1GetThresholdProfile,997 &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err != nil {998 t.Error(err)999 } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, reply) {1000 t.Errorf("Expecting: %+v, received: %+v", tPrfl.ThresholdProfile, reply)1001 }1002 if err := engineTwoRPC.Call(utils.APIerSv1GetThresholdProfile,1003 &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err != nil {1004 t.Error(err)1005 } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, reply) {1006 t.Errorf("Expecting: %+v, received: %+v", tPrfl.ThresholdProfile, reply)1007 }1008 // remove1009 if err := internalRPC.Call(utils.APIerSv1RemoveThresholdProfile,1010 &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &result); err != nil {1011 t.Error(err)1012 } else if result != utils.OK {1013 t.Error("Unexpected reply returned", result)1014 }1015 // check again1016 if err := engineOneRPC.Call(utils.APIerSv1GetThresholdProfile,1017 &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err == nil ||1018 err.Error() != utils.ErrNotFound.Error() {1019 t.Error(err)1020 }1021 if err := engineTwoRPC.Call(utils.APIerSv1GetThresholdProfile,1022 &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err == nil ||1023 err.Error() != utils.ErrNotFound.Error() {1024 t.Error(err)1025 }1026}1027func testInternalReplicateITSetAccount(t *testing.T) {1028 if *encoding == utils.MetaGOB {1029 t.SkipNow() // skip this function because1030 // APIerSv1GetAccount returns the old format of Account1031 // and it can not register that interface because is duplicate1032 // of the real Account1033 }1034 //check1035 var reply string1036 if err := engineOneRPC.Call(utils.APIerSv1GetAccount,1037 &utils.AttrGetAccount{Account: "AccountTest", Tenant: tenant}, &reply); err == nil ||1038 err.Error() != utils.ErrNotFound.Error() {1039 t.Error(err)1040 }1041 if err := engineTwoRPC.Call(utils.APIerSv1GetAccount,1042 &utils.AttrGetAccount{Account: "AccountTest", Tenant: tenant}, &reply); err == nil ||1043 err.Error() != utils.ErrNotFound.Error() {1044 t.Error(err)1045 }1046 //set1047 attrSetAccount := &utils.AttrSetAccount{1048 Account: "AccountTest",1049 Tenant: tenant}1050 if err := internalRPC.Call(utils.APIerSv1SetAccount, attrSetAccount, &reply); err != nil {1051 t.Error(err)1052 } else if reply != utils.OK {1053 t.Error("Unexpected reply returned", reply)1054 }1055 //check1056 tmp := engine.Account{}1057 rcvAccount := tmp.AsOldStructure()1058 if err := engineOneRPC.Call(utils.APIerSv1GetAccount,1059 &utils.AttrGetAccount{Account: "AccountTest", Tenant: tenant}, &rcvAccount); err != nil {1060 t.Errorf("Unexpected error : %+v\nRCV: %+v", err, rcvAccount)1061 }1062 if err := engineTwoRPC.Call(utils.APIerSv1GetAccount,1063 &utils.AttrGetAccount{Account: "AccountTest", Tenant: tenant}, &rcvAccount); err != nil {1064 t.Errorf("Unexpected error : %+v", err)1065 }1066 //remove1067 if err := internalRPC.Call(utils.APIerSv1RemoveAccount,1068 &utils.AttrRemoveAccount{1069 Account: "AccountTest",1070 Tenant: tenant}, &reply); err != nil {1071 t.Errorf("Unexpected error : %+v", err)1072 }1073 //check1074 if err := engineOneRPC.Call(utils.APIerSv1GetAccount,1075 &utils.AttrGetAccount{Account: "AccountTest", Tenant: tenant}, &reply); err == nil ||1076 err.Error() != utils.ErrNotFound.Error() {1077 t.Error(err)1078 }1079 if err := engineTwoRPC.Call(utils.APIerSv1GetAccount,1080 &utils.AttrGetAccount{Account: "AccountTest", Tenant: tenant}, &reply); err == nil ||1081 err.Error() != utils.ErrNotFound.Error() {1082 t.Error(err)1083 }1084}1085func testInternalReplicateITActionTrigger(t *testing.T) {1086 // check1087 var atrs engine.ActionTriggers1088 if err := engineOneRPC.Call(utils.APIerSv1GetActionTriggers,1089 &AttrGetActionTriggers{GroupIDs: []string{"TestATR"}}, &atrs); err == nil || err.Error() != utils.ErrNotFound.Error() {1090 t.Error("Got error on APIerSv1.GetActionTriggers: ", err)1091 }1092 if err := engineTwoRPC.Call(utils.APIerSv1GetActionTriggers,1093 &AttrGetActionTriggers{GroupIDs: []string{"TestATR"}}, &atrs); err == nil || err.Error() != utils.ErrNotFound.Error() {1094 t.Error("Got error on APIerSv1.GetActionTriggers: ", err)1095 }1096 // set1097 var reply string1098 attrSet := AttrSetActionTrigger{1099 GroupID: "TestATR",1100 UniqueID: "UniqueID",1101 ActionTrigger: map[string]interface{}{1102 utils.BalanceID: utils.StringPointer("BalanceIDtest1"),1103 }}1104 if err := internalRPC.Call(utils.APIerSv1SetActionTrigger, attrSet, &reply); err != nil {1105 t.Error(err)1106 } else if reply != utils.OK {1107 t.Errorf("Calling v1.SetActionTrigger got: %v", reply)1108 }1109 // check1110 if err := engineOneRPC.Call(utils.APIerSv1GetActionTriggers, &AttrGetActionTriggers{GroupIDs: []string{"TestATR"}}, &atrs); err != nil {1111 t.Error("Got error on APIerSv1.GetActionTriggers: ", err)1112 } else if len(atrs) != 1 {1113 t.Errorf("Calling v1.GetActionTriggers got: %v", atrs)1114 } else if atrs[0].ID != "TestATR" {1115 t.Errorf("Expecting: TestATR, received: %+v", atrs[0].ID)1116 } else if atrs[0].UniqueID != "UniqueID" {1117 t.Errorf("Expecting UniqueID, received: %+v", atrs[0].UniqueID)1118 } else if *atrs[0].Balance.ID != "BalanceIDtest1" {1119 t.Errorf("Expecting BalanceIDtest1, received: %+v", atrs[0].Balance.ID)1120 }1121 if err := engineTwoRPC.Call(utils.APIerSv1GetActionTriggers, &AttrGetActionTriggers{GroupIDs: []string{"TestATR"}}, &atrs); err != nil {1122 t.Error("Got error on APIerSv1.GetActionTriggers: ", err)1123 } else if len(atrs) != 1 {1124 t.Errorf("Calling v1.GetActionTriggers got: %v", atrs)1125 } else if atrs[0].ID != "TestATR" {1126 t.Errorf("Expecting: TestATR, received: %+v", atrs[0].ID)1127 } else if atrs[0].UniqueID != "UniqueID" {1128 t.Errorf("Expecting UniqueID, received: %+v", atrs[0].UniqueID)1129 } else if *atrs[0].Balance.ID != "BalanceIDtest1" {1130 t.Errorf("Expecting BalanceIDtest1, received: %+v", atrs[0].Balance.ID)1131 }1132 //remove1133 asttrRemove := &AttrRemoveActionTrigger{1134 GroupID: "TestATR",1135 UniqueID: "UniqueID",1136 }1137 if err := internalRPC.Call(utils.APIerSv1RemoveActionTrigger, asttrRemove, &reply); err != nil {1138 t.Error(err)1139 } else if reply != utils.OK {1140 t.Errorf("Calling v1.RemoveActionTrigger got: %v", reply)1141 }1142 //check1143 if err := engineOneRPC.Call(utils.APIerSv1GetActionTriggers,1144 &AttrGetActionTriggers{GroupIDs: []string{"TestATR"}}, &atrs); err == nil || err.Error() != utils.ErrNotFound.Error() {1145 t.Errorf("Got error on APIerSv1.GetActionTriggers: %+v", err)1146 }1147 if err := engineTwoRPC.Call(utils.APIerSv1GetActionTriggers,1148 &AttrGetActionTriggers{GroupIDs: []string{"TestATR"}}, &atrs); err == nil || err.Error() != utils.ErrNotFound.Error() {1149 t.Error("Got error on APIerSv1.GetActionTriggers: ", err)1150 }1151}1152func testInternalReplicateITThreshold(t *testing.T) {1153 // get threshold1154 var td engine.Threshold1155 if err := engineOneRPC.Call(utils.ThresholdSv1GetThreshold,1156 &utils.TenantIDWithAPIOpts{1157 TenantID: &utils.TenantID{1158 Tenant: tenant,1159 ID: "THD_Test"},1160 }, &td); err == nil ||1161 err.Error() != utils.ErrNotFound.Error() {1162 t.Error(err)1163 }1164 if err := engineTwoRPC.Call(utils.ThresholdSv1GetThreshold,1165 &utils.TenantIDWithAPIOpts{1166 TenantID: &utils.TenantID{1167 Tenant: tenant,1168 ID: "THD_Test"},1169 }, &td); err == nil ||1170 err.Error() != utils.ErrNotFound.Error() {1171 t.Error(err)1172 }1173 tEvs := &utils.CGREvent{1174 Tenant: "cgrates.org",1175 ID: "event1",1176 Event: map[string]interface{}{1177 utils.EventType: utils.AccountUpdate,1178 utils.AccountField: "1005",1179 utils.AllowNegative: true,1180 utils.Disabled: false,1181 utils.Units: 12.3},1182 APIOpts: map[string]interface{}{1183 utils.MetaEventType: utils.AccountUpdate,1184 },1185 }1186 //set Actions1187 var reply string1188 if err := internalRPC.Call(utils.APIerSv2SetActions, &utils.AttrSetActions{1189 ActionsId: "ACT_LOG",1190 Actions: []*utils.TPAction{{Identifier: utils.MetaLog}},1191 }, &reply); err != nil && err.Error() != utils.ErrExists.Error() {1192 t.Error(err)1193 } else if reply != utils.OK {1194 t.Errorf("Calling APIerSv2.SetActions received: %s", reply)1195 }1196 tPrfl := engine.ThresholdProfileWithAPIOpts{1197 ThresholdProfile: &engine.ThresholdProfile{1198 Tenant: tenant,1199 ID: "THD_Test",1200 FilterIDs: []string{},1201 MaxHits: -1,1202 Weight: 30,1203 ActionIDs: []string{"ACT_LOG"},1204 },1205 }1206 // set Threshold1207 if err := internalRPC.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &reply); err != nil {1208 t.Error(err)1209 } else if reply != utils.OK {1210 t.Error("Unexpected reply returned", reply)1211 }1212 //get1213 if err := internalRPC.Call(utils.ThresholdSv1GetThreshold,1214 &utils.TenantIDWithAPIOpts{1215 TenantID: &utils.TenantID{1216 Tenant: tenant,1217 ID: "THD_Test"},1218 }, &td); err != nil {1219 t.Error(err)1220 } else if td.Hits != 0 { //still not processed1221 t.Errorf("Expecting threshold to be hit once received: %v", td.Hits)1222 }1223 //set account1224 attrSetAccount := &utils.AttrSetAccount{1225 Account: "1005",1226 Tenant: tenant,1227 ExtraOptions: map[string]bool{1228 utils.AllowNegative: true}}1229 if err := internalRPC.Call(utils.APIerSv1SetAccount, attrSetAccount, &reply); err != nil {1230 t.Error(err)1231 } else if reply != utils.OK {1232 t.Error("Unexpected reply returned", reply)1233 }1234 //set balance1235 attrs := &utils.AttrSetBalance{1236 Tenant: tenant,1237 Account: "1005",1238 BalanceType: utils.MetaMonetary,1239 Value: 1,1240 Balance: map[string]interface{}{1241 utils.ID: utils.MetaDefault,1242 utils.Weight: 10.0,1243 },1244 }1245 if err := internalRPC.Call(utils.APIerSv2SetBalance, attrs, &reply); err != nil {1246 t.Fatal(err)1247 }1248 // processEvent1249 var ids []string1250 //eIDs := []string{}1251 if err := internalRPC.Call(utils.ThresholdSv1ProcessEvent, &tEvs, &ids); err != nil {1252 t.Error(err)1253 } else if len(ids) != 1 {1254 t.Errorf("Expecting 1: ,received %+v", len(ids))1255 } else if ids[0] != "THD_Test" {1256 t.Errorf("Expecting: THD_Test, received %q", ids[0])1257 }1258 //get1259 if err := internalRPC.Call(utils.ThresholdSv1GetThreshold,1260 &utils.TenantIDWithAPIOpts{1261 TenantID: &utils.TenantID{1262 Tenant: tenant,1263 ID: "THD_Test"},1264 }, &td); err != nil {1265 t.Error(err)1266 } else if td.Hits != 1 { //processed1267 t.Errorf("Expecting threshold to be hit once received: %v", td.Hits)1268 }1269 // remove1270 var result string1271 if err := internalRPC.Call(utils.APIerSv1RemoveThresholdProfile,1272 &utils.TenantID{Tenant: tenant, ID: "THD_Test"}, &result); err != nil {1273 t.Error(err)1274 } else if result != utils.OK {1275 t.Error("Unexpected reply returned", result)1276 }1277 if err := engineOneRPC.Call(utils.ThresholdSv1GetThreshold,1278 &utils.TenantIDWithAPIOpts{1279 TenantID: &utils.TenantID{1280 Tenant: tenant,1281 ID: "THD_Test"},1282 }, &td); err == nil ||1283 err.Error() != utils.ErrNotFound.Error() {1284 t.Error(err)1285 }1286 if err := engineTwoRPC.Call(utils.ThresholdSv1GetThreshold,1287 &utils.TenantIDWithAPIOpts{1288 TenantID: &utils.TenantID{1289 Tenant: tenant,1290 ID: "THD_Test"},1291 }, &td); err == nil ||1292 err.Error() != utils.ErrNotFound.Error() {1293 t.Error(err)1294 }1295}1296func testInternalReplicateITLoadIds(t *testing.T) {1297 // get LoadIDs1298 var rcv1e1 map[string]int641299 if err := engineOneRPC.Call(utils.APIerSv1GetLoadIDs, utils.StringPointer(utils.EmptyString), &rcv1e1); err != nil {1300 t.Error(err)1301 }1302 var rcv1e2 map[string]int641303 if err := engineTwoRPC.Call(utils.APIerSv1GetLoadIDs, utils.StringPointer(utils.EmptyString), &rcv1e2); err != nil {1304 t.Error(err)1305 }1306 if !reflect.DeepEqual(rcv1e1, rcv1e2) {1307 t.Errorf("Expecting same LoadIDs for both engines")1308 }1309 // set AttributeProfile1310 alsPrf = &engine.AttributeProfileWithAPIOpts{1311 AttributeProfile: &engine.AttributeProfile{1312 Tenant: "cgrates.org",1313 ID: "AttributeWithNonSubstitute",1314 Contexts: []string{utils.MetaSessionS},1315 FilterIDs: []string{"*string:~*req.Account:1008"},1316 ActivationInterval: &utils.ActivationInterval{1317 ActivationTime: time.Date(2020, 4, 18, 14, 35, 0, 0, time.UTC),1318 ExpiryTime: time.Date(2020, 4, 18, 14, 35, 0, 0, time.UTC),1319 },1320 Attributes: []*engine.Attribute{1321 {1322 FilterIDs: []string{"*string:~*req.Account:1008"},1323 Path: utils.MetaReq + utils.NestingSep + utils.AccountField,1324 Value: config.NewRSRParsersMustCompile("1001", utils.InfieldSep),1325 },1326 {1327 Path: utils.MetaReq + utils.NestingSep + utils.Subject,1328 Value: config.NewRSRParsersMustCompile(utils.MetaRemove, utils.InfieldSep),1329 },1330 },1331 Weight: 20,1332 },1333 }1334 alsPrf.Compile()1335 var result string1336 if err := internalRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil {1337 t.Error(err)1338 } else if result != utils.OK {1339 t.Error("Unexpected reply returned", result)1340 }1341 // check AttributeProfile1342 var reply *engine.AttributeProfile1343 if err := engineOneRPC.Call(utils.APIerSv1GetAttributeProfile,1344 utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: alsPrf.Tenant, ID: alsPrf.ID}}, &reply); err != nil {1345 t.Fatal(err)1346 }1347 reply.Compile()1348 if !reflect.DeepEqual(alsPrf.AttributeProfile, reply) {1349 t.Errorf("Expecting : %+v, received: %+v", alsPrf.AttributeProfile, reply)1350 }1351 // check again the LoadIDs1352 var rcv2e1 map[string]int641353 if err := engineOneRPC.Call(utils.APIerSv1GetLoadIDs, utils.StringPointer(utils.EmptyString), &rcv2e1); err != nil {1354 t.Error(err)1355 }1356 var rcv2e2 map[string]int641357 if err := engineTwoRPC.Call(utils.APIerSv1GetLoadIDs, utils.StringPointer(utils.EmptyString), &rcv2e2); err != nil {1358 t.Error(err)1359 }1360 // needs to be different LoadIds after the APIerSv1SetAttributeProfile call1361 if reflect.DeepEqual(rcv1e1, rcv2e1) {1362 t.Errorf("Expecting same LoadIDs for both engines")1363 }1364 // needs to be same LoadIds in both engines1365 if !reflect.DeepEqual(rcv2e1, rcv2e2) {1366 t.Errorf("Expecting same LoadIDs for both engines")1367 }1368 // check if the data was corectly modified after the APIerSv1SetAttributeProfile call1369 // only CacheAttributeProfiles should differ1370 if rcv1e1[utils.CacheAttributeProfiles] == rcv2e1[utils.CacheAttributeProfiles] {1371 t.Errorf("Expecting: %+v, received: %+v", rcv1e1[utils.CacheAttributeProfiles], rcv2e1[utils.CacheAttributeProfiles])1372 } else if rcv1e1[utils.CacheAccountActionPlans] != rcv2e1[utils.CacheAccountActionPlans] {1373 t.Errorf("Expecting: %+v, received: %+v", rcv1e1[utils.CacheAccountActionPlans], rcv2e1[utils.CacheAccountActionPlans])1374 } else if rcv1e1[utils.CacheActionPlans] != rcv2e1[utils.CacheActionPlans] {1375 t.Errorf("Expecting: %+v, received: %+v", rcv1e1[utils.CacheActionPlans], rcv2e1[utils.CacheActionPlans])1376 } else if rcv1e1[utils.CacheActions] != rcv2e1[utils.CacheActions] {1377 t.Errorf("Expecting: %+v, received: %+v", rcv1e1[utils.CacheActions], rcv2e1[utils.CacheActions])1378 } else if rcv1e1[utils.CacheChargerProfiles] != rcv2e1[utils.CacheChargerProfiles] {1379 t.Errorf("Expecting: %+v, received: %+v", rcv1e1[utils.CacheChargerProfiles], rcv2e1[utils.CacheChargerProfiles])1380 } else if rcv1e1[utils.CacheDestinations] != rcv2e1[utils.CacheDestinations] {1381 t.Errorf("Expecting: %+v, received: %+v", rcv1e1[utils.CacheDestinations], rcv2e1[utils.CacheDestinations])1382 } else if rcv1e1[utils.CacheFilters] != rcv2e1[utils.CacheFilters] {1383 t.Errorf("Expecting: %+v, received: %+v", rcv1e1[utils.CacheFilters], rcv2e1[utils.CacheFilters])1384 } else if rcv1e1[utils.CacheRatingPlans] != rcv2e1[utils.CacheRatingPlans] {1385 t.Errorf("Expecting: %+v, received: %+v", rcv1e1[utils.CacheRatingPlans], rcv2e1[utils.CacheRatingPlans])1386 } else if rcv1e1[utils.CacheRatingProfiles] != rcv2e1[utils.CacheRatingProfiles] {1387 t.Errorf("Expecting: %+v, received: %+v", rcv1e1[utils.CacheRatingProfiles], rcv2e1[utils.CacheRatingProfiles])1388 } else if rcv1e1[utils.CacheResourceProfiles] != rcv2e1[utils.CacheResourceProfiles] {1389 t.Errorf("Expecting: %+v, received: %+v", rcv1e1[utils.CacheResourceProfiles], rcv2e1[utils.CacheResourceProfiles])1390 } else if rcv1e1[utils.CacheResources] != rcv2e1[utils.CacheResources] {1391 t.Errorf("Expecting: %+v, received: %+v", rcv1e1[utils.CacheResources], rcv2e1[utils.CacheResources])1392 } else if rcv1e1[utils.CacheReverseDestinations] != rcv2e1[utils.CacheReverseDestinations] {1393 t.Errorf("Expecting: %+v, received: %+v", rcv1e1[utils.CacheReverseDestinations], rcv2e1[utils.CacheReverseDestinations])1394 } else if rcv1e1[utils.CacheStatQueueProfiles] != rcv2e1[utils.CacheStatQueueProfiles] {1395 t.Errorf("Expecting: %+v, received: %+v", rcv1e1[utils.CacheStatQueueProfiles], rcv2e1[utils.CacheStatQueueProfiles])1396 } else if rcv1e1[utils.CacheRouteProfiles] != rcv2e1[utils.CacheRouteProfiles] {1397 t.Errorf("Expecting: %+v, received: %+v", rcv1e1[utils.CacheRouteProfiles], rcv2e1[utils.CacheRouteProfiles])1398 } else if rcv1e1[utils.CacheThresholdProfiles] != rcv2e1[utils.CacheThresholdProfiles] {1399 t.Errorf("Expecting: %+v, received: %+v", rcv1e1[utils.CacheThresholdProfiles], rcv2e1[utils.CacheThresholdProfiles])1400 } else if rcv1e1[utils.CacheThresholds] != rcv2e1[utils.CacheThresholds] {1401 t.Errorf("Expecting: %+v, received: %+v", rcv1e1[utils.CacheThresholds], rcv2e1[utils.CacheThresholds])1402 } else if rcv1e1[utils.CacheTimings] != rcv2e1[utils.CacheTimings] {1403 t.Errorf("Expecting: %+v, received: %+v", rcv1e1[utils.CacheTimings], rcv2e1[utils.CacheTimings])1404 }1405}1406func testInternalReplicateITKillEngine(t *testing.T) {1407 if err := engine.KillEngine(100); err != nil {1408 t.Error(err)1409 }1410}...
td_shallow.go
Source:td_shallow.go
...17 expectedPointer uintptr18 expectedStr string // in reflect.String case, to avoid contents GC19}20var _ TestDeep = &tdShallow{}21func stringPointer(s string) uintptr {22 return (*reflect.StringHeader)(unsafe.Pointer(&s)).Data23}24// summary(Shallow): compares pointers only, not their contents25// input(Shallow): nil,str,slice,map,ptr,chan,func26// Shallow operator compares pointers only, not their contents. It27// applies on channels, functions (with some restrictions), maps,28// pointers, slices and strings.29//30// During a match, the compared data must be the same as expectedPtr31// to succeed.32//33// a, b := 123, 12334// td.Cmp(t, &a, td.Shallow(&a)) // succeeds35// td.Cmp(t, &a, td.Shallow(&b)) // fails even if a == b as &a != &b36//37// back := "foobarfoobar"38// a, b := back[:6], back[6:]39// // a == b but...40// td.Cmp(t, &a, td.Shallow(&b)) // fails41//42// Be careful for slices and strings! Shallow can succeed but the43// slices/strings not be identical because of their different44// lengths. For example:45//46// a := "foobar yes!"47// b := a[:1] // aka "f"48// td.Cmp(t, &a, td.Shallow(&b)) // succeeds as both strings point to the same area, even if len() differ49//50// The same behavior occurs for slices:51//52// a := []int{1, 2, 3, 4, 5, 6}53// b := a[:2] // aka []int{1, 2}54// td.Cmp(t, &a, td.Shallow(&b)) // succeeds as both slices point to the same area, even if len() differ55//56// See also [Ptr].57func Shallow(expectedPtr any) TestDeep {58 vptr := reflect.ValueOf(expectedPtr)59 shallow := tdShallow{60 base: newBase(3),61 expectedKind: vptr.Kind(),62 }63 // Note from reflect documentation:64 // If v's Kind is Func, the returned pointer is an underlying code65 // pointer, but not necessarily enough to identify a single function66 // uniquely. The only guarantee is that the result is zero if and67 // only if v is a nil func Value.68 switch shallow.expectedKind {69 case reflect.Chan,70 reflect.Func,71 reflect.Map,72 reflect.Ptr,73 reflect.Slice,74 reflect.UnsafePointer:75 shallow.expectedPointer = vptr.Pointer()76 case reflect.String:77 shallow.expectedStr = vptr.String()78 shallow.expectedPointer = stringPointer(shallow.expectedStr)79 default:80 shallow.err = ctxerr.OpBadUsage(81 "Shallow", "(CHANNEL|FUNC|MAP|PTR|SLICE|UNSAFE_PTR|STRING)",82 expectedPtr, 1, true)83 }84 return &shallow85}86func (s *tdShallow) Match(ctx ctxerr.Context, got reflect.Value) *ctxerr.Error {87 if s.err != nil {88 return ctx.CollectError(s.err)89 }90 if got.Kind() != s.expectedKind {91 if ctx.BooleanError {92 return ctxerr.BooleanError93 }94 return ctx.CollectError(&ctxerr.Error{95 Message: "bad kind",96 Got: types.RawString(got.Kind().String()),97 Expected: types.RawString(s.expectedKind.String()),98 })99 }100 var ptr uintptr101 // Special case for strings102 if s.expectedKind == reflect.String {103 ptr = stringPointer(got.String())104 } else {105 ptr = got.Pointer()106 }107 if ptr != s.expectedPointer {108 if ctx.BooleanError {109 return ctxerr.BooleanError110 }111 return ctx.CollectError(&ctxerr.Error{112 Message: fmt.Sprintf("%s pointer mismatch", s.expectedKind),113 Got: types.RawString(fmt.Sprintf("0x%x", ptr)),114 Expected: types.RawString(fmt.Sprintf("0x%x", s.expectedPointer)),115 })116 }117 return nil...
pretty_test.go
Source:pretty_test.go
1package utils2import (3 "testing"4 "github.com/stretchr/testify/assert"5)6func TestPrettyPrint(t *testing.T) {7 testdata := []struct {8 name string9 sample map[string]any10 expected string11 }{12 {13 name: "Nil map",14 sample: nil,15 expected: "nil",16 },17 {18 name: "Empty map",19 sample: map[string]any{},20 expected: "map[string]any{}",21 },22 {23 name: "String field",24 sample: map[string]any{25 "String": "value",26 },27 expected: `map[string]any{28 "String": "value",29}`,30 },31 {32 name: "String field",33 sample: map[string]any{34 "StringPointer": ToPointer("value"),35 },36 expected: `map[string]any{37 "StringPointer": &"value",38}`,39 },40 {41 name: "Integer field",42 sample: map[string]any{43 "Integer": 123456,44 },45 expected: `map[string]any{46 "Integer": 123456,47}`,48 },49 {50 name: "Boolean field",51 sample: map[string]any{52 "Boolean": true,53 },54 expected: `map[string]any{55 "Boolean": true,56}`,57 },58 {59 name: "String Slice field",60 sample: map[string]any{61 "StringSlice": []string{62 "Item1",63 "Item2",64 },65 },66 expected: `map[string]any{67 "StringSlice": []string{68 "Item1",69 "Item2",70 },71}`,72 },73 {74 name: "Map[string]any field",75 sample: map[string]any{76 "MapStringAny": map[string]any{77 "Integer": 123,78 },79 },80 expected: `map[string]any{81 "MapStringAny": map[string]any{82 "Integer": 123,83 },84}`,85 },86 {87 name: "Struct field",88 sample: map[string]any{89 "Struct": struct {90 String string91 Integer int92 }{93 String: "string value",94 Integer: 1234,95 },96 },97 expected: `map[string]any{98 "Struct": struct {99 Integer int100 String string101 }{102 Integer: 1234,103 String: "string value",104 },105}`,106 },107 }108 for _, td := range testdata {109 t.Run(td.name, func(t *testing.T) {110 result := PrettyPrint(td.sample)111 assert.Equal(t, td.expected, result)112 })113 }114}...
stringPointer
Using AI Code Generation
1import (2type td struct {3}4func (t td) stringPointer() *string {5}6func main() {7 t := td{"hello"}8 f := reflect.ValueOf(t).MethodByName("stringPointer")9 out := f.Call([]reflect.Value{})10 fmt.Println(*out[0].Interface().(*string))11}
stringPointer
Using AI Code Generation
1import "fmt"2func main() {3 td := new(TestData)4 fmt.Println(td.stringPointer)5}6import "fmt"7func main() {8 td := new(TestData)9 fmt.Println(td.stringPointer)10}11import "fmt"12func main() {13 td := new(TestData)14 fmt.Println(td.stringPointer)15}16import "fmt"17func main() {18 td := new(TestData)19 fmt.Println(td.stringPointer)20}21import "fmt"22func main() {23 td := new(TestData)24 fmt.Println(td.stringPointer)25}26import "fmt"27func main() {28 td := new(TestData)29 fmt.Println(td.stringPointer)30}31import "fmt"32func main() {33 td := new(TestData)34 fmt.Println(td.stringPointer)35}36import "fmt"37func main() {38 td := new(TestData)39 fmt.Println(td.stringPointer)40}41import "fmt"42func main() {43 td := new(TestData)44 fmt.Println(td.stringPointer)45}46import "fmt"47func main() {48 td := new(TestData)49 fmt.Println(td
stringPointer
Using AI Code Generation
1import (2func main() {3 fmt.Println(s)4 fmt.Println(td.StringPointer(s))5}6import (7func main() {8 fmt.Println(s)9 fmt.Println(td.StringPointer(s))10}11import (12func main() {13 fmt.Println(s)14 fmt.Println(td.StringPointer(s))15}16import (17func main() {18 fmt.Println(s)19 fmt.Println(td.StringPointer(s))20}21import (22func main() {23 fmt.Println(s)24 fmt.Println(td.StringPointer(s))25}26import (27func main() {28 fmt.Println(s)29 fmt.Println(td.StringPointer(s))30}31import (32func main() {33 fmt.Println(s)34 fmt.Println(td.StringPointer(s))35}36import (37func main() {38 fmt.Println(s)39 fmt.Println(td.StringPointer(s))40}41import (42func main() {
stringPointer
Using AI Code Generation
1import "fmt"2func main() {3 td := new(td)4 fmt.Println(td.stringPointer())5}6import "fmt"7func main() {8 td := new(td)9 fmt.Println(td.stringPointer())10}11import "fmt"12func main() {13 td := new(td)14 fmt.Println(td.stringPointer())15}16import "fmt"17func main() {18 td := new(td)19 fmt.Println(td.stringPointer())20}21import "fmt"22func main() {23 td := new(td)24 fmt.Println(td.stringPointer())25}26import "fmt"27func main() {28 td := new(td)29 fmt.Println(td.stringPointer())30}31import "fmt"32func main() {33 td := new(td)34 fmt.Println(td.stringPointer())35}36import "fmt"37func main() {38 td := new(td)39 fmt.Println(td.stringPointer())40}41import "fmt"42func main() {43 td := new(td)44 fmt.Println(td.stringPointer())45}46import "fmt"47func main() {48 td := new(td)49 fmt.Println(td
stringPointer
Using AI Code Generation
1import "fmt"2func main() {3 fmt.Println("Before: ", a, *b)4 fmt.Println("After: ", a, *b)5}6import "fmt"7func main() {8 fmt.Println("Before: ", a, *b)9 fmt.Println("After: ", a, *b)10}11import "fmt"12func main() {13 fmt.Println("Before: ", a, *b)14 fmt.Println("After: ", a, *b)15}16import "fmt"17func main() {18 fmt.Println("Before: ", a, *b)19 fmt.Println("After: ", a, *b)20}21import "fmt"22func main() {23 fmt.Println("Before: ", a, *b)24 fmt.Println("After: ", a, *b)25}26import "fmt"27func main() {28 fmt.Println("Before: ", a, *
stringPointer
Using AI Code Generation
1import (2func main() {3 td = td{}4 fmt.Println(td.stringPointer())5}6import (7func main() {8 td = td{}9 fmt.Println(*td.stringPointer())10}11import (12func main() {13 td = td{}14 fmt.Println(td.stringPointer())15}16import (17func main() {18 td = td{}19 fmt.Println(*td.stringPointer())20}21import (22func main() {23 td = td{}24 fmt.Println(td.stringPointer())25}26import (27func main() {28 td = td{}29 fmt.Println(*td.stringPointer())30}31import (32func main() {33 td = td{}34 fmt.Println(td.stringPointer())35}36import (37func main() {38 td = td{}39 fmt.Println(*td.stringPointer())40}41import (42func main() {43 td = td{}
stringPointer
Using AI Code Generation
1import (2func main() {3 td := new(TD)4 td.SetName("Test")5 td.SetAge(10)6 fmt.Println(td)7 td.SetAge(11)8 fmt.Println(td)9}10import (11func main() {12 td := new(TD)13 td.SetName("Test")14 td.SetAge(10)15 fmt.Println(td)16 td.SetAge(11)17 fmt.Println(td)18}19&{Test 10}20&{Test 11}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!