From f36b543df3a3b5d06180959b5e4e8c1af97181c9 Mon Sep 17 00:00:00 2001 From: ionutboangiu Date: Wed, 10 Mar 2021 18:43:59 +0200 Subject: [PATCH] Cover functions in utils/librates.go --- utils/coreutils_test.go | 5 ++- utils/librates_test.go | 79 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 utils/librates_test.go diff --git a/utils/coreutils_test.go b/utils/coreutils_test.go index 786f75396..f34f08fa0 100644 --- a/utils/coreutils_test.go +++ b/utils/coreutils_test.go @@ -1710,10 +1710,11 @@ func TestCoreUtilsGenerateDBItemOpts(t *testing.T) { expected := map[string]interface{}{ OptsAPIKey: apiKey, OptsRouteID: routeID, - CacheOpt: cache + ".", + CacheOpt: cache, RemoteHostOpt: rmtHost, } received := GenerateDBItemOpts(apiKey, routeID, cache, rmtHost) + if len(received) != len(expected) { t.Fatalf("The maps differ in length") } @@ -1722,6 +1723,4 @@ func TestCoreUtilsGenerateDBItemOpts(t *testing.T) { t.Errorf("\nReceived: <%+v>, \nExpected: <%+v>", value, expected[key]) } } - fmt.Println(received) - } diff --git a/utils/librates_test.go b/utils/librates_test.go new file mode 100644 index 000000000..04721d9a6 --- /dev/null +++ b/utils/librates_test.go @@ -0,0 +1,79 @@ +/* +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 utils + +import ( + "testing" +) + +func TestLibratesTenantID(t *testing.T) { + rp := &RateProfile{ + Tenant: "tenant", + ID: "testID", + } + expected := rp.Tenant + ":" + rp.ID + received := rp.TenantID() + if received != expected { + t.Errorf("\nReceived: <%v>,\nExpected: <%v>", received, expected) + } +} + +func TestLibratesCompile(t *testing.T) { + // empty struct + rp := &RateProfile{} + err := rp.Compile() + if err != nil { + t.Errorf("\nReceived: <%v>, \nExpected: <%v>", err, nil) + } + + // non-empty + fail := "shouldfail" + rp.ID = "test" + rp.Tenant = "tenant" + rp.Rates = map[string]*Rate{ + "testKey1": &Rate{ + ID: "ID1", + ActivationTimes: fail, + }, + "testKey2": &Rate{ + ID: "ID2", + }, + } + + expected := "expected exactly 5 fields, found 1: [" + fail + "]" + err = rp.Compile() + + if err == nil || err.Error() != expected { + t.Errorf("\nReceived: <%v>, \nExpected: <%v>", err, expected) + } +} + +func TestLibratesUID(t *testing.T) { + rt := &Rate{ + uID: "testString", + } + + expected := "testString" + received := rt.UID() + + if received != expected { + t.Errorf("\nReceived: %q, \nExpected: %q", received, expected) + } + +}