Add new unit tests on agents and apier/v1

This commit is contained in:
armirveliaj
2024-08-29 10:05:40 -04:00
committed by Dan Christian Bogos
parent ddb25433f7
commit 0a0aec58b3
3 changed files with 156 additions and 0 deletions

View File

@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package agents
import (
"errors"
"testing"
"github.com/cgrates/birpc"
@@ -119,3 +120,45 @@ func TestAsteriskAgentV1AlterSession(t *testing.T) {
t.Errorf("Expected error: %v, got: %v", utils.ErrNotImplemented, err)
}
}
func TestAsteriskAgentCall(t *testing.T) {
sma := &AsteriskAgent{}
ctx := context.Background()
tests := []struct {
name string
serviceMethod string
args any
reply any
expectedError error
}{
{
name: "Valid service method",
serviceMethod: "testMethod",
args: nil,
reply: nil,
expectedError: nil,
},
{
name: "Invalid service method",
serviceMethod: "invalidMethod",
args: nil,
reply: nil,
expectedError: errors.New("unexpected method"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := sma.Call(ctx, tt.serviceMethod, tt.args, tt.reply)
if err == nil && tt.expectedError == nil {
t.Errorf("expected no error, but got: %v", err)
} else if err == nil && tt.expectedError != nil {
t.Errorf("expected error: %v, but got no error", tt.expectedError)
} else if err == nil && tt.expectedError != nil {
t.Errorf("expected error: %v, but got: %v", tt.expectedError, err)
}
})
}
}

View File

@@ -281,3 +281,17 @@ func TestCallCacheForFilter(t *testing.T) {
t.Errorf("Expected %s ,received: %s", utils.ToJSON(exp), utils.ToJSON(rpl))
}
}
func TestResourceSv1Ping(t *testing.T) {
rsv1 := &ResourceSv1{}
ctx := context.Background()
ign := &utils.CGREvent{}
var reply string
err := rsv1.Ping(ctx, ign, &reply)
if err != nil {
t.Errorf("expected no error, got %v", err)
}
if reply != utils.Pong {
t.Errorf("expected reply to be %v, got %v", utils.Pong, reply)
}
}

99
apier/v1/rankings_test.go Normal file
View File

@@ -0,0 +1,99 @@
/*
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 <http://www.gnu.org/licenses/>
*/
package v1
import (
"testing"
"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
func TestRankingSv1Ping(t *testing.T) {
sa := &RankingSv1{}
ctx := context.Background()
ign := &utils.CGREvent{}
var reply string
err := sa.Ping(ctx, ign, &reply)
if err != nil {
t.Errorf("expected no error, got %v", err)
}
if reply != utils.Pong {
t.Errorf("expected reply to be %v, got %v", utils.Pong, reply)
}
}
func TestNewRankingSv1(t *testing.T) {
rankingSvc := NewRankingSv1()
if rankingSvc == nil {
t.Errorf("NewRankingSv1() returned nil")
}
}
func TestRemoveRankingProfile(t *testing.T) {
dataManager := &engine.DataManager{}
apierSv1 := &APIerSv1{
DataManager: dataManager,
}
args := &utils.TenantIDWithAPIOpts{
APIOpts: map[string]interface{}{
utils.CacheOpt: "cacheOptValue",
},
}
var reply string
err := apierSv1.RemoveRankingProfile(nil, args, &reply)
if err == nil {
t.Fatalf("RemoveRankingProfile() returned an error: %v", err)
}
if reply == utils.OK {
t.Errorf("RemoveRankingProfile() returned reply = %v, want %v", reply, utils.OK)
}
}
func TestRalsPing(t *testing.T) {
rsv1 := &RALsV1{}
ctx := context.Background()
var ign *utils.CGREvent
var reply string
err := rsv1.Ping(ctx, ign, &reply)
if err != nil {
t.Errorf("Expected no error, got %v", err)
}
expectedReply := utils.Pong
if reply != expectedReply {
t.Errorf("Expected reply %v, got %v", expectedReply, reply)
}
}
func TestRalsCall(t *testing.T) {
rsv1 := &RALsV1{}
ctx := context.Background()
serviceMethod := "TestServiceMethod"
args := "TestArgs"
var reply string
err := rsv1.Call(ctx, serviceMethod, args, &reply)
if err == nil {
t.Errorf("UNSUPPORTED_SERVICE_METHOD")
}
expectedReply := "response"
if reply == expectedReply {
t.Errorf("Expected reply %v, got %v", expectedReply, reply)
}
}