From 37e5a54ea9ca931df80b5ec41c6181a82848f5ce Mon Sep 17 00:00:00 2001 From: gezimbll Date: Tue, 3 Oct 2023 10:59:32 -0400 Subject: [PATCH] Fixed config tests & added new stordb tests --- apier/v1/config_it_test.go | 129 +++++++++++----------- engine/z_filterindexer_it_test.go | 7 ++ engine/z_onstor_it_test.go | 35 ++++++ engine/z_stordb_it_test.go | 10 ++ general_tests/all_cfg_sect_rld_it_test.go | 2 +- 5 files changed, 119 insertions(+), 64 deletions(-) diff --git a/apier/v1/config_it_test.go b/apier/v1/config_it_test.go index 58b3349c8..4a8ab3e55 100644 --- a/apier/v1/config_it_test.go +++ b/apier/v1/config_it_test.go @@ -142,26 +142,27 @@ func testConfigSSetConfigSessionS(t *testing.T) { t.Errorf("Expected OK received: %s", reply) } exp := map[string]any{ - "enabled": true, - "channel_sync_interval": "0", - "alterable_fields": []any{}, - "client_protocol": 1., - "debit_interval": "0", - "listen_bijson": "127.0.0.1:2014", - "listen_bigob": "", - "session_ttl": "0", - "session_indexes": []any{utils.OriginID}, - "attributes_conns": []any{utils.MetaLocalHost}, - "cdrs_conns": []any{utils.MetaInternal}, - "chargers_conns": []any{utils.MetaInternal}, - "rals_conns": []any{utils.MetaInternal}, - "replication_conns": []any{}, - "resources_conns": []any{utils.MetaLocalHost}, - "routes_conns": []any{utils.MetaLocalHost}, - "scheduler_conns": []any{}, - "thresholds_conns": []any{}, - "stats_conns": []any{}, - "min_dur_low_balance": "0", + "enabled": true, + "channel_sync_interval": "0", + "alterable_fields": []any{}, + "client_protocol": 1., + "debit_interval": "0", + "listen_bijson": "127.0.0.1:2014", + "listen_bigob": "", + "stale_chan_max_extra_usage": "0", + "session_ttl": "0", + "session_indexes": []any{utils.OriginID}, + "attributes_conns": []any{utils.MetaLocalHost}, + "cdrs_conns": []any{utils.MetaInternal}, + "chargers_conns": []any{utils.MetaInternal}, + "rals_conns": []any{utils.MetaInternal}, + "replication_conns": []any{}, + "resources_conns": []any{utils.MetaLocalHost}, + "routes_conns": []any{utils.MetaLocalHost}, + "scheduler_conns": []any{}, + "thresholds_conns": []any{}, + "stats_conns": []any{}, + "min_dur_low_balance": "0", "stir": map[string]any{ "allowed_attest": []any{utils.MetaAny}, "default_attest": "A", @@ -234,28 +235,29 @@ func testConfigSSetConfigSessionS(t *testing.T) { func testConfigSv1GetJSONSectionWithoutTenant(t *testing.T) { exp := map[string]any{ - "enabled": true, - "listen_bijson": "127.0.0.1:2014", - "listen_bigob": "", - "chargers_conns": []any{utils.MetaInternal}, - "rals_conns": []any{utils.MetaInternal}, - "resources_conns": []any{utils.MetaLocalHost}, - "thresholds_conns": []any{}, - "stats_conns": []any{}, - "routes_conns": []any{utils.MetaLocalHost}, - "attributes_conns": []any{utils.MetaLocalHost}, - "cdrs_conns": []any{utils.MetaInternal}, - "replication_conns": []any{}, - "scheduler_conns": []any{}, - "session_indexes": []any{"OriginID"}, - "client_protocol": 1., - "terminate_attempts": 5., - "channel_sync_interval": "0", - "debit_interval": "0", - "session_ttl": "0", - "store_session_costs": false, - "min_dur_low_balance": "0", - "alterable_fields": []any{}, + "enabled": true, + "listen_bijson": "127.0.0.1:2014", + "listen_bigob": "", + "chargers_conns": []any{utils.MetaInternal}, + "rals_conns": []any{utils.MetaInternal}, + "resources_conns": []any{utils.MetaLocalHost}, + "thresholds_conns": []any{}, + "stats_conns": []any{}, + "routes_conns": []any{utils.MetaLocalHost}, + "attributes_conns": []any{utils.MetaLocalHost}, + "cdrs_conns": []any{utils.MetaInternal}, + "replication_conns": []any{}, + "scheduler_conns": []any{}, + "session_indexes": []any{"OriginID"}, + "client_protocol": 1., + "terminate_attempts": 5., + "channel_sync_interval": "0", + "debit_interval": "0", + "session_ttl": "0", + "stale_chan_max_extra_usage": "0", + "store_session_costs": false, + "min_dur_low_balance": "0", + "alterable_fields": []any{}, "stir": map[string]any{ "allowed_attest": []any{utils.MetaAny}, "default_attest": "A", @@ -273,27 +275,28 @@ func testConfigSv1GetJSONSectionWithoutTenant(t *testing.T) { if *encoding == utils.MetaGOB { var empty []string exp = map[string]any{ - "enabled": true, - "listen_bijson": "127.0.0.1:2014", - "chargers_conns": []string{utils.MetaInternal}, - "rals_conns": []string{utils.MetaInternal}, - "resources_conns": []string{utils.MetaLocalHost}, - "thresholds_conns": empty, - "stats_conns": empty, - "routes_conns": []string{utils.MetaLocalHost}, - "attributes_conns": []string{utils.MetaLocalHost}, - "cdrs_conns": []string{utils.MetaInternal}, - "replication_conns": empty, - "scheduler_conns": empty, - "session_indexes": []string{"OriginID"}, - "client_protocol": 1., - "terminate_attempts": 5, - "channel_sync_interval": "0", - "debit_interval": "0", - "session_ttl": "0", - "store_session_costs": false, - "min_dur_low_balance": "0", - "alterable_fields": empty, + "enabled": true, + "listen_bijson": "127.0.0.1:2014", + "chargers_conns": []string{utils.MetaInternal}, + "rals_conns": []string{utils.MetaInternal}, + "resources_conns": []string{utils.MetaLocalHost}, + "thresholds_conns": empty, + "stats_conns": empty, + "routes_conns": []string{utils.MetaLocalHost}, + "attributes_conns": []string{utils.MetaLocalHost}, + "cdrs_conns": []string{utils.MetaInternal}, + "replication_conns": empty, + "scheduler_conns": empty, + "session_indexes": []string{"OriginID"}, + "client_protocol": 1., + "terminate_attempts": 5, + "channel_sync_interval": "0", + "debit_interval": "0", + "session_ttl": "0", + "stale_chan_max_extra_usage": "0", + "store_session_costs": false, + "min_dur_low_balance": "0", + "alterable_fields": empty, "stir": map[string]any{ "allowed_attest": []string{utils.MetaAny}, "default_attest": "A", diff --git a/engine/z_filterindexer_it_test.go b/engine/z_filterindexer_it_test.go index 11c2cd589..2d22c44da 100644 --- a/engine/z_filterindexer_it_test.go +++ b/engine/z_filterindexer_it_test.go @@ -1695,6 +1695,13 @@ func testITTestIndexingThresholds(t *testing.T) { } else if !reflect.DeepEqual(eMp, rcvMp) { t.Errorf("Expecting: %+v, received: %+v", eMp, rcvMp) } + if err := dataManager.RemoveIndexes(utils.CacheThresholdFilterIndexes, th.Tenant, utils.EmptyString); err != nil { + t.Error(err) + } else if _, err := dataManager.GetIndexes( + utils.CacheThresholdFilterIndexes, th.Tenant, + utils.EmptyString, false, false); err == nil || err != utils.ErrNotFound { + t.Error(err) + } } func testITTestIndexingMetaNot(t *testing.T) { diff --git a/engine/z_onstor_it_test.go b/engine/z_onstor_it_test.go index ca03e8dc3..c0e3eef79 100644 --- a/engine/z_onstor_it_test.go +++ b/engine/z_onstor_it_test.go @@ -75,6 +75,7 @@ var ( testOnStorITAttributeProfile, testOnStorITFlush, testOnStorITIsDBEmpty, + testOnStorITDispatcherHost, testOnStorITTestAttributeSubstituteIface, testOnStorITChargerProfile, testOnStorITDispatcherProfile, @@ -2029,6 +2030,40 @@ func testOnStorITAttributeProfile(t *testing.T) { } } +func testOnStorITDispatcherHost(t *testing.T) { + dpp := &DispatcherHost{ + Tenant: "cgrates.org", + RemoteHost: &config.RemoteHost{ + ID: "ALL", + Address: "127.0.0.1", + Transport: utils.MetaJSON, + }, + } + if _, rcvErr := onStor.GetDispatcherHost("cgrates.org", "ALL2", + true, false, utils.NonTransactional); rcvErr != nil && rcvErr != utils.ErrDSPHostNotFound { + t.Error(rcvErr) + } + if err := onStor.SetDispatcherHost(dpp); err != nil { + t.Error(err) + } + //get from database + if rcv, err := onStor.GetDispatcherHost("cgrates.org", "ALL", + false, false, utils.NonTransactional); err != nil { + t.Error(err) + } else if !(reflect.DeepEqual(dpp, rcv)) { + t.Errorf("Expecting: %v, received: %v", dpp, rcv) + } + + if err := onStor.RemoveDispatcherHost(dpp.Tenant, dpp.ID); err != nil { + t.Error(err) + } + //check database if removed + if _, rcvErr := onStor.GetDispatcherHost("cgrates.org", "ALL", + false, false, utils.NonTransactional); rcvErr != nil && rcvErr != utils.ErrDSPHostNotFound { + t.Error(rcvErr) + } +} + func testOnStorITTestAttributeSubstituteIface(t *testing.T) { attrProfile := &AttributeProfile{ Tenant: "cgrates.org", diff --git a/engine/z_stordb_it_test.go b/engine/z_stordb_it_test.go index 66c7703e6..80e1d2ee6 100644 --- a/engine/z_stordb_it_test.go +++ b/engine/z_stordb_it_test.go @@ -24,6 +24,7 @@ import ( "path" "reflect" "runtime" + "slices" "sort" "strings" "testing" @@ -1635,6 +1636,15 @@ func testStorDBitCRUDTpResources(t *testing.T) { t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].ThresholdIDs, rcv[0].ThresholdIDs, rcv[1].ThresholdIDs) } } + + //tpIDs + expIds := []string{"testTag1", "testTag2"} + if tpIds, err := storDB.GetTpTableIds("testTPid", utils.TBLTPResources, utils.TPDistinctIds{utils.TenantCfg, utils.IDCfg}, nil, &utils.PaginatorWithSearch{}); err != nil { + t.Error(err) + } else if slices.Equal(tpIds, expIds) { + t.Errorf("Expected %+v,Received %+v", expIds, tpIds) + } + // REMOVE if err := storDB.RemTpData("", "testTPid", nil); err != nil { t.Error(err) diff --git a/general_tests/all_cfg_sect_rld_it_test.go b/general_tests/all_cfg_sect_rld_it_test.go index 4732a0f80..da02cb917 100644 --- a/general_tests/all_cfg_sect_rld_it_test.go +++ b/general_tests/all_cfg_sect_rld_it_test.go @@ -547,7 +547,7 @@ func testSectConfigSReloadSessions(t *testing.T) { } else if reply != utils.OK { t.Errorf("Expected OK received: %+v", reply) } - cfgStr := "{\"sessions\":{\"alterable_fields\":[],\"attributes_conns\":[\"*internal\"],\"cdrs_conns\":[\"*internal\"],\"channel_sync_interval\":\"0\",\"chargers_conns\":[\"*internal\"],\"client_protocol\":1,\"debit_interval\":\"0\",\"default_usage\":{\"*any\":\"3h0m0s\",\"*data\":\"1048576\",\"*sms\":\"1\",\"*voice\":\"3h0m0s\"},\"enabled\":true,\"listen_bigob\":\"\",\"listen_bijson\":\"127.0.0.1:2014\",\"min_dur_low_balance\":\"0\",\"rals_conns\":[\"*internal\"],\"replication_conns\":[],\"resources_conns\":[\"*internal\"],\"routes_conns\":[\"*internal\"],\"scheduler_conns\":[],\"session_indexes\":[\"OriginID\"],\"session_ttl\":\"0\",\"stats_conns\":[],\"stir\":{\"allowed_attest\":[\"*any\"],\"default_attest\":\"A\",\"payload_maxduration\":\"-1\",\"privatekey_path\":\"\",\"publickey_path\":\"\"},\"store_session_costs\":false,\"terminate_attempts\":5,\"thresholds_conns\":[]}}" + cfgStr := "{\"sessions\":{\"alterable_fields\":[],\"attributes_conns\":[\"*internal\"],\"cdrs_conns\":[\"*internal\"],\"channel_sync_interval\":\"0\",\"chargers_conns\":[\"*internal\"],\"client_protocol\":1,\"debit_interval\":\"0\",\"default_usage\":{\"*any\":\"3h0m0s\",\"*data\":\"1048576\",\"*sms\":\"1\",\"*voice\":\"3h0m0s\"},\"enabled\":true,\"listen_bigob\":\"\",\"listen_bijson\":\"127.0.0.1:2014\",\"min_dur_low_balance\":\"0\",\"rals_conns\":[\"*internal\"],\"replication_conns\":[],\"resources_conns\":[\"*internal\"],\"routes_conns\":[\"*internal\"],\"scheduler_conns\":[],\"session_indexes\":[\"OriginID\"],\"session_ttl\":\"0\",\"stale_chan_max_extra_usage\":\"0\",\"stats_conns\":[],\"stir\":{\"allowed_attest\":[\"*any\"],\"default_attest\":\"A\",\"payload_maxduration\":\"-1\",\"privatekey_path\":\"\",\"publickey_path\":\"\"},\"store_session_costs\":false,\"terminate_attempts\":5,\"thresholds_conns\":[]}}" var rpl string if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org",