From 4fe5edae39fb9915ebbd95774c8cf3ef338377fc Mon Sep 17 00:00:00 2001 From: Tripon Alexandru-Ionut Date: Wed, 27 Mar 2019 10:35:58 +0200 Subject: [PATCH] Added Guardian tests for API --- apier/v1/guardian_it_test.go | 96 ++++++++++++++++++++++++++++++++++++ utils/consts.go | 2 +- 2 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 apier/v1/guardian_it_test.go diff --git a/apier/v1/guardian_it_test.go b/apier/v1/guardian_it_test.go new file mode 100644 index 000000000..07bc55807 --- /dev/null +++ b/apier/v1/guardian_it_test.go @@ -0,0 +1,96 @@ +// +build integration + +/* +Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments +Copyright (C) ITsysCOM GmbH + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see +*/ +package v1 + +import ( + "net/rpc/jsonrpc" + "path" + "reflect" + "sort" + "testing" + "time" + + "github.com/cgrates/cgrates/config" + "github.com/cgrates/cgrates/engine" + "github.com/cgrates/cgrates/utils" +) + +//Test start here +func TestGuardianSIT(t *testing.T) { + var err error + guardianCfgPath := path.Join(*dataDir, "conf", "samples", "tutmysql") + guardianCfg, err := config.NewCGRConfigFromPath(guardianCfgPath) + if err != nil { + t.Error(err) + } + guardianCfg.DataFolderPath = *dataDir + config.SetCgrConfig(guardianCfg) + + if err = engine.InitDataDb(guardianCfg); err != nil { + t.Fatal(err) + } + + if err = engine.InitStorDb(guardianCfg); err != nil { + t.Fatal(err) + } + + // start engine + if _, err = engine.StopStartEngine(guardianCfgPath, *waitRater); err != nil { + t.Fatal(err) + } + + // start RPC + guardianRPC, err := jsonrpc.Dial("tcp", guardianCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed + if err != nil { + t.Fatal(err) + } + + // lock + args := utils.AttrRemoteLock{ + ReferenceID: "", + LockIDs: []string{"lock1"}, + Timeout: 500 * time.Millisecond, + } + var reply string + if err = guardianRPC.Call(utils.GuardianSv1RemoteLock, args, &reply); err != nil { + t.Error(err) + } + var unlockReply []string + if err = guardianRPC.Call(utils.GuardianSv1RemoteUnlock, reply, &unlockReply); err != nil { + t.Error(err) + } + sort.Strings(unlockReply) + if !reflect.DeepEqual(args.LockIDs, unlockReply) { + t.Errorf("Expected: %s , received: %s", utils.ToJSON(args.LockIDs), utils.ToJSON(unlockReply)) + } + + // ping + var resp string + if err = guardianRPC.Call(utils.GuardianSv1Ping, new(utils.CGREvent), &resp); err != nil { + t.Error(err) + } else if resp != utils.Pong { + t.Error("Unexpected reply returned", resp) + } + + // stop engine + if err := engine.KillEngine(100); err != nil { + t.Error(err) + } +} diff --git a/utils/consts.go b/utils/consts.go index 8fca68992..c39bbb102 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -912,7 +912,7 @@ const ( AttributesCsv = "Attributes.csv" ChargersCsv = "Chargers.csv" DispatchersCsv = "Dispatchers.csv" - DispatcherHostsCsv = " DispatcherHosts.csv" + DispatcherHostsCsv = "DispatcherHosts.csv" ) // Table Name