From 35ae6ebd2720d01bd34db71b527686bf3927c4ef Mon Sep 17 00:00:00 2001 From: armirveliaj Date: Tue, 3 Sep 2024 08:31:53 -0400 Subject: [PATCH] Add new unit tests on apier/v1 --- apier/v1/ees_test.go | 73 ++++++++++++++++++++++++++++++++++++++++ apier/v1/loaders_test.go | 65 +++++++++++++++++++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 apier/v1/ees_test.go create mode 100644 apier/v1/loaders_test.go diff --git a/apier/v1/ees_test.go b/apier/v1/ees_test.go new file mode 100644 index 000000000..aaa3e2aaf --- /dev/null +++ b/apier/v1/ees_test.go @@ -0,0 +1,73 @@ +/* +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 ( + "testing" + + "github.com/cgrates/birpc/context" + "github.com/cgrates/cgrates/ees" + "github.com/cgrates/cgrates/ers" + "github.com/cgrates/cgrates/utils" +) + +func TestNewEeSv1(t *testing.T) { + eeS := &ees.EventExporterS{} + eeSv1 := NewEeSv1(eeS) + if eeSv1 == nil { + t.Fatalf("Expected non-nil EeSv1, got nil") + } + if eeSv1.eeS != eeS { + t.Errorf("Expected eeS field to be set correctly") + } +} + +func TestEeSv1Ping(t *testing.T) { + eeSv1 := &EeSv1{} + ctx := context.Background() + event := &utils.CGREvent{} + var reply string + err := eeSv1.Ping(ctx, event, &reply) + if err != nil { + t.Fatalf("Expected no error, got %v", err) + } + if reply != utils.Pong { + t.Errorf("Expected reply to be %s, got %s", utils.Pong, reply) + } +} + +func TestErSv1NewErSv1AndPing(t *testing.T) { + mockErS := &ers.ERService{} + erSv1 := NewErSv1(mockErS) + if erSv1 == nil { + t.Fatalf("Expected non-nil ErSv1, got nil") + } + if erSv1.erS != mockErS { + t.Errorf("Expected erS field to be set correctly") + } + ctx := context.Background() + var reply string + err := erSv1.Ping(ctx, nil, &reply) + if err != nil { + t.Fatalf("Expected no error from Ping, got %v", err) + } + if reply != utils.Pong { + t.Errorf("Expected reply to be %s, got %s", utils.Pong, reply) + } +} diff --git a/apier/v1/loaders_test.go b/apier/v1/loaders_test.go new file mode 100644 index 000000000..e265e50aa --- /dev/null +++ b/apier/v1/loaders_test.go @@ -0,0 +1,65 @@ +/* +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 ( + "testing" + + "github.com/cgrates/birpc/context" + "github.com/cgrates/cgrates/loaders" + "github.com/cgrates/cgrates/utils" +) + +func TestLoaderSv1Ping(t *testing.T) { + rsv1 := &LoaderSv1{} + ctx := context.Background() + var reply string + ign := &utils.CGREvent{} + err := rsv1.Ping(ctx, ign, &reply) + if err != nil { + t.Errorf("Expected no error, but got: %v", err) + } + if reply != utils.Pong { + t.Errorf("Expected reply to be '%s', but got '%s'", utils.Pong, reply) + } +} + +func TestNewLoaderSv1(t *testing.T) { + mockLoaderService := &loaders.LoaderService{} + result := NewLoaderSv1(mockLoaderService) + if result == nil { + t.Errorf("Expected non-nil result, but got nil") + } + if result.ldrS != mockLoaderService { + t.Errorf("Expected ldrS to be %v, but got %v", mockLoaderService, result.ldrS) + } +} + +func TestLoaderSv1Call(t *testing.T) { + ldrSv1 := &LoaderSv1{} + ctx := context.Background() + serviceMethod := "testMethod" + args := "testArgs" + var reply string + err := ldrSv1.Call(ctx, serviceMethod, args, &reply) + if err == nil { + t.Errorf("Expected error, but got: %v", err) + } + +}