diff --git a/agents/fsevent_test.go b/agents/fsevent_test.go index 0f5d8b600..e057dc749 100644 --- a/agents/fsevent_test.go +++ b/agents/fsevent_test.go @@ -27,6 +27,7 @@ import ( "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" "github.com/cgrates/cgrates/utils" + "github.com/google/go-cmp/cmp" ) var hangupEv string = `Event-Name: CHANNEL_HANGUP_COMPLETE @@ -1116,3 +1117,24 @@ func TestFsEvV1TerminateSessionArgs(t *testing.T) { t.Errorf("Expecting: %+v, received: %+v", expected.TerminateSession, rcv.TerminateSession) } } + +func TestAgentsFSEventGetSessionIds(t *testing.T) { + uuid := "test-uuid" + fsev := FSEvent{UUID: uuid} + got := fsev.GetSessionIds() + want := []string{uuid} + if diff := cmp.Diff(got, want); diff != "" { + t.Errorf("GetSessionIds() returned incorrect result (-got +want):\n%s", diff) + } +} + +func TestAgentsFSEventString(t *testing.T) { + fsev := &FSEvent{ + "key1": "value1", + } + got := fsev.String() + want := "key1 = value1\n==============================================================" + if got != want { + t.Errorf("fsev.String() = %q, want %q", got, want) + } +} diff --git a/agents/kamevent_test.go b/agents/kamevent_test.go index 27dbdfc48..5b97b4599 100644 --- a/agents/kamevent_test.go +++ b/agents/kamevent_test.go @@ -26,6 +26,7 @@ import ( "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" "github.com/cgrates/cgrates/utils" + "github.com/google/go-cmp/cmp" ) var kamEv = KamEvent{KamTRIndex: "29223", KamTRLabel: "698469260", @@ -504,3 +505,31 @@ func TestKamEvAsKamProcessEventReply(t *testing.T) { t.Errorf("Expecting: %+v, received: %+v", expected, rcv) } } + +func TestAgentsNewKamSessionDisconnect(t *testing.T) { + hEntry := "entry123" + hID := "id123" + reason := "test reason" + got := NewKamSessionDisconnect(hEntry, hID, reason) + want := &KamSessionDisconnect{ + Event: CGR_SESSION_DISCONNECT, + HashEntry: hEntry, + HashId: hID, + Reason: reason, + } + if diff := cmp.Diff(got, want); diff != "" { + t.Errorf("NewKamSessionDisconnect() mismatch (-got +want):\n%s", diff) + } +} + +func TestAgentsKamEvent_String(t *testing.T) { + ke := KamEvent{ + "EventName": "TestEvent", + "Data": "TestData", + } + got := ke.String() + want := `{"Data":"TestData","EventName":"TestEvent"}` + if got != want { + t.Errorf("KamEvent.String() = %v, want %v", got, want) + } +} diff --git a/dispatchers/responder_test.go b/dispatchers/responder_test.go index eae337ee7..3a1298965 100644 --- a/dispatchers/responder_test.go +++ b/dispatchers/responder_test.go @@ -384,3 +384,29 @@ func TestDspResponderGetCostOnRatingPlans(t *testing.T) { // t.Error(err) // } // } + +func TestDspResponderGetMaxSessionTimeOnAccountsNil(t *testing.T) { + cgrCfg := config.NewDefaultCGRConfig() + dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) + cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} + CGREvent := &utils.GetMaxSessionTimeOnAccountsArgs{} + + var reply *map[string]any + err := dspSrv.ResponderGetMaxSessionTimeOnAccounts(context.Background(), CGREvent, reply) + expected := "MANDATORY_IE_MISSING: [ApiKey]" + if err == nil || err.Error() != expected { + t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, err) + } +} + +func TestDspResponderGetMaxSessionTimeOnAccountsErrorNil(t *testing.T) { + cgrCfg := config.NewDefaultCGRConfig() + dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) + CGREvent := &utils.GetMaxSessionTimeOnAccountsArgs{} + var reply *map[string]any + err := dspSrv.ResponderGetMaxSessionTimeOnAccounts(context.Background(), CGREvent, reply) + expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" + if err == nil || err.Error() != expected { + t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, err) + } +} diff --git a/engine/libattributes_test.go b/engine/libattributes_test.go index 6a78d5b8d..4141808dd 100644 --- a/engine/libattributes_test.go +++ b/engine/libattributes_test.go @@ -26,6 +26,7 @@ import ( "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" + "github.com/google/go-cmp/cmp" ) func TestConvertExternalToProfile(t *testing.T) { @@ -244,3 +245,21 @@ func TestLibAttributesTenantIDMetaPrefix(t *testing.T) { t.Errorf("expected: <%+v>, \nreceived: <%+v>", exp, rcv) } } + +func TestEngineAttributeProfilesSort(t *testing.T) { + + unsorted := AttributeProfiles{ + {Weight: 10}, + {Weight: 2}, + {Weight: 15}, + } + expected := AttributeProfiles{ + {Weight: 15}, + {Weight: 10}, + {Weight: 2}, + } + unsorted.Sort() + if !cmp.Equal(unsorted, expected) { + t.Errorf("Sort failed. Expected %v, got %v", expected, unsorted) + } +} diff --git a/engine/models_test.go b/engine/models_test.go index c985fdac6..348ea39e5 100644 --- a/engine/models_test.go +++ b/engine/models_test.go @@ -226,3 +226,30 @@ func TestModelsAsMapStringInterface(t *testing.T) { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) } } + +func TestEngineSharedGroupMdlTableName(t *testing.T) { + testStruct := SharedGroupMdl{} + exp := utils.TBLTPSharedGroups + result := testStruct.TableName() + if !reflect.DeepEqual(exp, result) { + t.Errorf("\nExpected: <%+v>\nReceived: <%+v>", exp, result) + } +} + +func TestEngineResourceMdlTableName(t *testing.T) { + testStruct := ResourceMdl{} + exp := utils.TBLTPResources + result := testStruct.TableName() + if !reflect.DeepEqual(exp, result) { + t.Errorf("\nExpected: <%+v>\nReceived: <%+v>", exp, result) + } +} + +func TestEngineStatMdlTableName(t *testing.T) { + testStruct := StatMdl{} + exp := utils.TBLTPStats + result := testStruct.TableName() + if !reflect.DeepEqual(exp, result) { + t.Errorf("\nExpected: <%+v>\nReceived: <%+v>", exp, result) + } +}