From a263e25858c6ca4f2435bafd4cde1c47ddaecf73 Mon Sep 17 00:00:00 2001 From: armirveliaj Date: Tue, 23 Jul 2024 09:22:00 -0400 Subject: [PATCH] Add new unit tests on agents --- agents/kamagent_test.go | 28 ++++++++++++++++++++++++++++ agents/libdiam_test.go | 20 ++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/agents/kamagent_test.go b/agents/kamagent_test.go index 0680f3d75..683e7562e 100644 --- a/agents/kamagent_test.go +++ b/agents/kamagent_test.go @@ -22,6 +22,7 @@ import ( "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" + "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" "github.com/cgrates/kamevapi" ) @@ -79,3 +80,30 @@ func TestKAShutdown(t *testing.T) { } } + +func TestNewKamailioAgent(t *testing.T) { + kaCfg := &config.KamAgentCfg{} + connMgr := &engine.ConnManager{} + timezone := "UTC" + ka := NewKamailioAgent(kaCfg, connMgr, timezone) + + if ka.cfg != kaCfg { + t.Errorf("Expected cfg = %v, got %v", kaCfg, ka.cfg) + } + + if ka.connMgr != connMgr { + t.Errorf("Expected connMgr = %v, got %v", connMgr, ka.connMgr) + } + + if ka.timezone != timezone { + t.Errorf("Expected timezone = %v, got %v", timezone, ka.timezone) + } + + if len(ka.conns) != len(kaCfg.EvapiConns) { + t.Errorf("Expected conns length = %d, got %d", len(kaCfg.EvapiConns), len(ka.conns)) + } + + if ka.activeSessionIDs == nil { + t.Errorf("Expected activeSessionIDs to be initialized, got nil") + } +} diff --git a/agents/libdiam_test.go b/agents/libdiam_test.go index 98630f05e..d49e1efb4 100644 --- a/agents/libdiam_test.go +++ b/agents/libdiam_test.go @@ -20,6 +20,8 @@ package agents import ( "net" + "os" + "path/filepath" "reflect" "strings" "testing" @@ -1205,3 +1207,21 @@ func TestHeaderLenDiam(t *testing.T) { } } +func TestLoadDictionaries(t *testing.T) { + tempDir, err := os.MkdirTemp("", "testdicts") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(tempDir) + xmlFilePath := filepath.Join(tempDir, "test.xml") + xmlContent := `` + err = os.WriteFile(xmlFilePath, []byte(xmlContent), 0644) + if err != nil { + t.Fatal(err) + } + componentID := "testComponent" + err = loadDictionaries(tempDir, componentID) + if err == nil { + t.Errorf("loadDictionaries() error = %v, wantErr %v", err, false) + } +}