From 79a69b5aa77dc627e1c145b0348b64f00bb327cc Mon Sep 17 00:00:00 2001 From: TeoV Date: Wed, 9 Jan 2019 09:41:54 -0500 Subject: [PATCH] Add integration test for versions.go in apier/v1 --- apier/v1/versions_it_test.go | 137 +++++++++++++++++++++++++++++++++++ engine/version.go | 3 - 2 files changed, 137 insertions(+), 3 deletions(-) create mode 100644 apier/v1/versions_it_test.go diff --git a/apier/v1/versions_it_test.go b/apier/v1/versions_it_test.go new file mode 100644 index 000000000..37c3dd4c8 --- /dev/null +++ b/apier/v1/versions_it_test.go @@ -0,0 +1,137 @@ +// +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" + "net/rpc/jsonrpc" + "path" + "testing" + + "github.com/cgrates/cgrates/config" + "github.com/cgrates/cgrates/engine" + "github.com/cgrates/cgrates/utils" +) + +var ( + vrsCfgPath string + vrsCfg *config.CGRConfig + vrsRPC *rpc.Client + vrsDataDir = "/usr/share/cgrates" + vrsDelay int + vrsConfigDIR string //run tests for specific configuration + vrsStorageType string +) + +var sTestsVrs = []func(t *testing.T){ + testVrsInitCfg, + testVrsResetStorDb, + testVrsStartEngine, + testVrsRpcConn, + testVrsDataDB, + testVrsStorDB, + testVrsKillEngine, +} + +//Test start here +func TestVrsITMySql(t *testing.T) { + vrsConfigDIR = "tutmysql" + vrsStorageType = utils.REDIS + for _, stest := range sTestsVrs { + t.Run(vrsConfigDIR, stest) + } +} + +func TestVrsITMongo(t *testing.T) { + vrsConfigDIR = "tutmongo" + vrsStorageType = utils.MONGO + for _, stest := range sTestsVrs { + t.Run(vrsConfigDIR, stest) + } +} + +func testVrsInitCfg(t *testing.T) { + var err error + vrsCfgPath = path.Join(vrsDataDir, "conf", "samples", vrsConfigDIR) + vrsCfg, err = config.NewCGRConfigFromFolder(vrsCfgPath) + if err != nil { + t.Error(err) + } + vrsCfg.DataFolderPath = vrsDataDir // Share DataFolderPath through config towards StoreDb for Flush() + vrsDelay = 1000 +} + +// Wipe out the cdr database +func testVrsResetStorDb(t *testing.T) { + if err := engine.InitStorDb(vrsCfg); err != nil { + t.Fatal(err) + } +} + +// Start CGR Engine +func testVrsStartEngine(t *testing.T) { + if _, err := engine.StopStartEngine(vrsCfgPath, vrsDelay); err != nil { + t.Fatal(err) + } +} + +// Connect rpc client to rater +func testVrsRpcConn(t *testing.T) { + var err error + vrsRPC, err = jsonrpc.Dial("tcp", vrsCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed + if err != nil { + t.Fatal(err) + } +} + +func testVrsDataDB(t *testing.T) { + var result engine.Versions + expectedVrs := engine.Versions{"ActionTriggers": 2, + "Actions": 2, "DerivedChargers": 1, "RQF": 1, "ReverseDestinations": 1, "Attributes": 2, "RatingPlan": 1, + "RatingProfile": 1, "User": 1, "Accounts": 3, "ActionPlans": 2, "Alias": 1, "Chargers": 1, + "Destinations": 1, "SharedGroups": 2, "Stats": 2, "Resource": 1, "ReverseAlias": 1, + "Subscribers": 1, "Suppliers": 1, "Thresholds": 3, "Timing": 1} + if err := vrsRPC.Call("ApierV1.GetDataDBVersions", "", &result); err != nil { + t.Error(err) + } else if expectedVrs.Compare(result, vrsStorageType, true) != "" { + t.Errorf("Expecting: %+v, received: %+v", result, expectedVrs) + } +} + +func testVrsStorDB(t *testing.T) { + var result engine.Versions + expectedVrs := engine.Versions{"TpDerivedChargers": 1, "TpDestinations": 1, "TpResource": 1, "TpThresholds": 1, + "TpActions": 1, "TpDestinationRates": 1, "TpFilters": 1, "TpRates": 1, "CDRs": 2, "TpActionTriggers": 1, "TpRatingPlans": 1, + "TpSharedGroups": 1, "TpSuppliers": 1, "SessionSCosts": 3, "TpDerivedCharges": 1, "TpRatingProfiles": 1, "TpStats": 1, "TpTiming": 1, + "CostDetails": 2, "TpAccountActions": 1, "TpActionPlans": 1, "TpChargers": 1, "TpRatingProfile": 1, "TpUsers": 1, + "TpAliases": 1, "TpRatingPlan": 1, "TpResources": 1} + if err := vrsRPC.Call("ApierV1.GetStorDBVersions", "", &result); err != nil { + t.Error(err) + } else if expectedVrs.Compare(result, vrsStorageType, true) != "" { + t.Errorf("Expecting: %+v, received: %+v", result, expectedVrs) + } +} + +func testVrsKillEngine(t *testing.T) { + if err := engine.KillEngine(vrsDelay); err != nil { + t.Error(err) + } +} diff --git a/engine/version.go b/engine/version.go index 8659159e8..efa02efb0 100644 --- a/engine/version.go +++ b/engine/version.go @@ -153,10 +153,8 @@ func CurrentDataDBVersions() Versions { utils.User: 1, utils.Subscribers: 1, utils.DerivedChargersV: 1, - utils.CdrStats: 1, utils.Destinations: 1, utils.ReverseDestinations: 1, - utils.LCR: 1, utils.RatingPlan: 1, utils.RatingProfile: 1, utils.Chargers: 1, @@ -188,7 +186,6 @@ func CurrentStorDBVersions() Versions { utils.TpAliases: 1, utils.TpUsers: 1, utils.TpDerivedChargersV: 1, - utils.TpCdrStats: 1, utils.TpDestinations: 1, utils.TpRatingPlan: 1, utils.TpRatingProfile: 1,