Add new unit tests on apier/v1

This commit is contained in:
armirveliaj
2024-09-20 10:23:05 -04:00
committed by Dan Christian Bogos
parent 4b35d74a29
commit 407f5fa062
2 changed files with 75 additions and 0 deletions

View File

@@ -21,6 +21,8 @@ package v1
import (
"testing"
"github.com/cgrates/cgrates/ers"
"github.com/cgrates/cgrates/sessions"
"github.com/cgrates/cgrates/utils"
)
@@ -120,3 +122,29 @@ func TestGetId(t *testing.T) {
})
}
}
func TestNewSMGenericV1(t *testing.T) {
Session := &sessions.SessionS{}
result := NewSMGenericV1(Session)
if result.Ss != Session {
t.Error("Expected the SessionS to be the same as the input, but got a different value")
}
if result == nil {
t.Error("Expected result to be a valid SMGenericV1 instance, but got nil")
}
}
func TestNewErSv1(t *testing.T) {
erService := &ers.ERService{}
erSv1 := NewErSv1(erService)
if erSv1 == nil {
t.Fatalf("Expected non-nil ErSv1, got nil")
}
if erSv1.erS != erService {
t.Fatalf("Expected erS to be %v, got %v", erService, erSv1.erS)
}
}

View File

@@ -25,6 +25,7 @@ import (
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
"github.com/cgrates/ltcache"
)
func TestCacheLoadCache(t *testing.T) {
@@ -399,3 +400,49 @@ func TestCacheSv1ReplicateRemove(t *testing.T) {
t.Errorf("expected no error with nil context, got %v", err)
}
}
func TestCacheSv1GetCacheStats(t *testing.T) {
cfg := config.NewDefaultCGRConfig()
data := engine.NewInternalDB(nil, nil, true, nil)
cfg.ApierCfg().CachesConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches)}
dm := engine.NewDataManager(data, cfg.CacheCfg(), nil)
ch := engine.NewCacheS(cfg, dm, nil)
cache := NewCacheSv1(ch)
ctx := context.Background()
args := &utils.AttrCacheIDsWithAPIOpts{}
var reply map[string]*ltcache.CacheStats
err := cache.GetCacheStats(ctx, args, &reply)
if err != nil {
t.Errorf("expected no error, got %v", err)
}
if reply == nil {
t.Errorf("expected reply to be non-nil, got nil")
}
}
func TestCacheSv1GetGroupItemIDs(t *testing.T) {
cfg := config.NewDefaultCGRConfig()
data := engine.NewInternalDB(nil, nil, true, nil)
cfg.ApierCfg().CachesConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches)}
dm := engine.NewDataManager(data, cfg.CacheCfg(), nil)
ch := engine.NewCacheS(cfg, dm, nil)
cache := NewCacheSv1(ch)
ctx := context.Background()
args := &utils.ArgsGetGroupWithAPIOpts{}
var reply []string
err := cache.GetGroupItemIDs(ctx, args, &reply)
if err == nil {
t.Errorf("NOT_FOUND")
}
if reply != nil {
t.Errorf("expected reply to be non-nil, got nil")
}
}