diff --git a/engine/account_test.go b/engine/account_test.go index 95e80e600..3d0aafd74 100644 --- a/engine/account_test.go +++ b/engine/account_test.go @@ -3324,3 +3324,21 @@ func TestAccEnableAccountAction(t *testing.T) { }) } } + +func TestEngineToStringJSON(t *testing.T) { + acc := &Account{ + ID: "acc_123", + AllowNegative: false, + Disabled: true, + UpdateTime: time.Now(), + executingTriggers: false, + } + want, err := json.Marshal(acc) + if err != nil { + t.Errorf("Error marshalling Account to JSON: %v", err) + } + got := acc.String() + if got != string(want) { + t.Errorf("Expected JSON: %s, got: %s", want, got) + } +} diff --git a/engine/calldesc_test.go b/engine/calldesc_test.go index f6e6257f9..d7d5db7c1 100644 --- a/engine/calldesc_test.go +++ b/engine/calldesc_test.go @@ -19,6 +19,7 @@ package engine import ( "bytes" + "encoding/json" "errors" "log" "os" @@ -2733,3 +2734,37 @@ func TestCallDescGetRatingPlansForPrefix(t *testing.T) { t.Error(err) } } + +func TestEngineCallDescriptorString(t *testing.T) { + TestCallDescriptor := &CallDescriptor{ + Category: "call", + Tenant: "cgrates.org", + Subject: "user", + Account: "testAccount", + Destination: "local", + TimeStart: time.Date(2022, time.January, 7, 16, 60, 0, 0, time.UTC), + TimeEnd: time.Date(2022, time.January, 7, 16, 60, 0, 0, time.UTC), + LoopIndex: 1.0, + DurationIndex: time.Minute * 3, + FallbackSubject: "testfallbacksubject", + ToR: utils.MetaVoice, + ExtraFields: map[string]string{"key1": "value1"}, + MaxRate: 10.0, + MaxRateUnit: time.Minute, + MaxCostSoFar: 0.5, + CgrID: "grid1", + RunID: "runID123", + ForceDuration: false, + PerformRounding: true, + DenyNegativeAccount: true, + DryRun: false, + } + want, err := json.Marshal(TestCallDescriptor) + if err != nil { + t.Errorf("Error marshalling CallDescriptor to JSON: %v", err) + } + got := TestCallDescriptor.String() + if got != string(want) { + t.Errorf("Expected CallDescriptor.String() to return %s, got %s", want, got) + } +} diff --git a/engine/cdr_test.go b/engine/cdr_test.go index a9e4e8165..cb967611e 100644 --- a/engine/cdr_test.go +++ b/engine/cdr_test.go @@ -18,6 +18,7 @@ along with this program. If not, see package engine import ( + "encoding/json" "reflect" "strconv" "testing" @@ -882,3 +883,35 @@ func TestCDRAddDefaults(t *testing.T) { t.Errorf("Expecting: %+v, received: %+v", eCDR, cdr) } } + +func TestEngineCDRString(t *testing.T) { + TestCDR := CDR{ + CGRID: "grid1", + RunID: "runid123", + OrderID: 12345, + OriginHost: "10.1.1.1", + Source: "testsrouce", + OriginID: "origin123", + ToR: "tortest", + RequestType: "prepaid", + Tenant: "cgrates.org", + Category: "rating", + Account: "testaccount", + Subject: "user", + Destination: "+1234567890", + SetupTime: time.Now(), + AnswerTime: time.Now().Add(time.Minute * 5), + Usage: time.Minute * 3, + ExtraFields: map[string]string{"key1": "value1"}, + ExtraInfo: "some additional information", + Partial: false, + PreRated: false, + CostSource: "rating_engine", + Cost: 1.50, + } + want, _ := json.Marshal(TestCDR) + got := TestCDR.String() + if string(got) != string(want) { + t.Errorf("Expected CDR.String() to return %s, got %s", want, got) + } +} diff --git a/engine/models_test.go b/engine/models_test.go index 348ea39e5..0700d2b2d 100644 --- a/engine/models_test.go +++ b/engine/models_test.go @@ -253,3 +253,12 @@ func TestEngineStatMdlTableName(t *testing.T) { t.Errorf("\nExpected: <%+v>\nReceived: <%+v>", exp, result) } } + +func TestEngineThresholdMdlTableName(t *testing.T) { + testStruct := ThresholdMdl{} + exp := utils.TBLTPThresholds + result := testStruct.TableName() + if !reflect.DeepEqual(exp, result) { + t.Errorf("\nExpected: <%+v>\nReceived: <%+v>", exp, result) + } +} diff --git a/engine/ratingprofile_test.go b/engine/ratingprofile_test.go index 30911214a..5993689cb 100644 --- a/engine/ratingprofile_test.go +++ b/engine/ratingprofile_test.go @@ -18,6 +18,7 @@ along with this program. If not, see package engine import ( + "reflect" "testing" "time" @@ -463,3 +464,66 @@ func TestRatingProfileGetRatingPlansPrefixAny(t *testing.T) { } } + +func TestEngineSwapRpasIndex(t *testing.T) { + activationTime1 := time.Now() + activationTime2 := activationTime1.Add(time.Hour) + plan1 := &RatingPlanActivation{ + ActivationTime: activationTime1, + RatingPlanId: "planTest1", + FallbackKeys: []string{"key1", "key2"}, + } + plan2 := &RatingPlanActivation{ + ActivationTime: activationTime2, + RatingPlanId: "planTest2", + FallbackKeys: []string{"key3"}, + } + initialRPAs := RatingPlanActivations{plan1, plan2} + index1 := 0 + index2 := 1 + want := RatingPlanActivations{plan2, plan1} + rpas := make(RatingPlanActivations, len(initialRPAs)) + copy(rpas, initialRPAs) + rpas.Swap(index1, index2) + if !reflect.DeepEqual(rpas, want) { + t.Errorf("Expected RatingPlanActivations after swap: %v, got: %v", want, rpas) + } +} + +func TestEngineEqualRpaOrpa(t *testing.T) { + activationTime1 := time.Now() + activationTime2 := activationTime1.Add(time.Hour) + plan1 := &RatingPlanActivation{ + ActivationTime: activationTime1, + RatingPlanId: "planId1", + FallbackKeys: []string{"key1", "key2"}, + } + plan2 := &RatingPlanActivation{ + ActivationTime: activationTime2, + RatingPlanId: "planId2", + FallbackKeys: []string{"key3"}, + } + tests := []struct { + name string + rpa *RatingPlanActivation + orpa *RatingPlanActivation + expected bool + }{ + {name: "Equal plans", rpa: plan1, orpa: plan1, expected: true}, + {name: "Different activation time", rpa: plan1, orpa: plan2, expected: false}, + {name: "Nil arguments (both nil)", rpa: nil, orpa: nil, expected: true}, + } + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + var result bool + if tc.rpa == nil && tc.orpa == nil { + result = tc.expected + } else { + result = tc.rpa.Equal(tc.orpa) + } + if result != tc.expected { + t.Errorf("Expected Equal(%v, %v) to be %v, got %v", tc.rpa, tc.orpa, tc.expected, result) + } + }) + } +} diff --git a/engine/units_counter_test.go b/engine/units_counter_test.go index 93acb0642..dccf07e11 100644 --- a/engine/units_counter_test.go +++ b/engine/units_counter_test.go @@ -18,6 +18,7 @@ along with this program. If not, see package engine import ( + "encoding/json" "reflect" "testing" @@ -949,3 +950,31 @@ func TestUnitCounterFilterFieldAsString(t *testing.T) { } } + +func TestEngineCounterFilterString(t *testing.T) { + testFilter := CounterFilter{ + Value: 12.5, + } + want, err := json.Marshal(testFilter) + if err != nil { + t.Errorf("Error marshalling CounterFilter to JSON: %v", err) + } + got := testFilter.String() + if got != string(want) { + t.Errorf("Expected JSON: %s, got: %s", want, got) + } +} + +func TestEngineUnitCounterString(t *testing.T) { + testCounter := UnitCounter{ + CounterType: "event", + } + want, err := json.Marshal(testCounter) + if err != nil { + t.Errorf("Error marshalling UnitCounter to JSON: %v", err) + } + got := testCounter.String() + if got != string(want) { + t.Errorf("Expected JSON: %s, got: %s", want, got) + } +}