From 6ec3dc01bcbc3428ab67f7834950734e77e8a8f4 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Wed, 16 Jun 2021 19:34:04 +0300 Subject: [PATCH] Updated index health tests --- apier/v1/filter_indexes_health_it_test.go | 6 +- engine/libindex.go | 2 +- engine/z_libindex_health_test.go | 120 +++++++++++++++++++++- 3 files changed, 122 insertions(+), 6 deletions(-) diff --git a/apier/v1/filter_indexes_health_it_test.go b/apier/v1/filter_indexes_health_it_test.go index d5174467f..84ff7bae8 100644 --- a/apier/v1/filter_indexes_health_it_test.go +++ b/apier/v1/filter_indexes_health_it_test.go @@ -118,7 +118,11 @@ func testV1FIdxHAccountActionPlansHealth(t *testing.T) { }, &reply); err != nil { t.Error(err) } - exp := engine.IndexHealthReply{} + exp := engine.IndexHealthReply{ + MissingObjects: []string{}, + MissingIndexes: map[string][]string{}, + BrokenReferences: map[string][]string{}, + } if !reflect.DeepEqual(exp, reply) { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(exp), utils.ToJSON(reply)) } diff --git a/engine/libindex.go b/engine/libindex.go index f07c30a4a..ff4c8bea3 100644 --- a/engine/libindex.go +++ b/engine/libindex.go @@ -934,7 +934,7 @@ func GetAccountActionPlanIndexHealth(dm *DataManager, objLimit, indexLimit int, return } err = nil - brokenRef[apID] = append(brokenRef[apID], acntID) + missingIndex[apID] = append(missingIndex[apID], acntID) continue } if !utils.IsSliceMember(ids, apID) { // the index doesn't exits for this actionPlan diff --git a/engine/z_libindex_health_test.go b/engine/z_libindex_health_test.go index a3466e4f0..736f23b2f 100644 --- a/engine/z_libindex_health_test.go +++ b/engine/z_libindex_health_test.go @@ -18,7 +18,14 @@ along with this program. If not, see package engine -/* +import ( + "reflect" + "testing" + + "github.com/cgrates/cgrates/config" + "github.com/cgrates/cgrates/utils" +) + func TestHealthAccountAction(t *testing.T) { Cache.Clear(nil) cfg := config.NewDefaultCGRConfig() @@ -35,11 +42,116 @@ func TestHealthAccountAction(t *testing.T) { }, true, utils.NonTransactional); err != nil { t.Fatal(err) } + + exp := &IndexHealthReply{ + MissingObjects: []string{"AP1"}, + MissingIndexes: map[string][]string{"AP2": {"1002"}}, + BrokenReferences: map[string][]string{"AP2": {"1001"}}, + } if rply, err := GetAccountActionPlanIndexHealth(dm, -1, -1, -1, -1, false, false); err != nil { t.Fatal(err) - } else { - t.Error(utils.ToJSON(rply)) + } else if !reflect.DeepEqual(exp, rply) { + t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(exp), utils.ToJSON(rply)) + } +} + +func TestHealthAccountAction2(t *testing.T) { + Cache.Clear(nil) + cfg := config.NewDefaultCGRConfig() + db := NewInternalDB(nil, nil, true) + dm := NewDataManager(db, cfg.CacheCfg(), nil) + + if err := dm.SetAccountActionPlans("1001", []string{"AP1", "AP2"}, true); err != nil { + t.Fatal(err) + } + if err := dm.SetActionPlan("AP2", &ActionPlan{ + Id: "AP2", + AccountIDs: utils.NewStringMap("1001"), + ActionTimings: []*ActionTiming{{}}, + }, true, utils.NonTransactional); err != nil { + t.Fatal(err) } + exp := &IndexHealthReply{ + MissingObjects: []string{"AP1"}, + MissingIndexes: map[string][]string{}, + BrokenReferences: map[string][]string{}, + } + if rply, err := GetAccountActionPlanIndexHealth(dm, -1, -1, -1, -1, false, false); err != nil { + t.Fatal(err) + } else if !reflect.DeepEqual(exp, rply) { + t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(exp), utils.ToJSON(rply)) + } +} + +func TestHealthAccountAction3(t *testing.T) { + Cache.Clear(nil) + cfg := config.NewDefaultCGRConfig() + db := NewInternalDB(nil, nil, true) + dm := NewDataManager(db, cfg.CacheCfg(), nil) + + if err := dm.SetAccountActionPlans("1002", []string{"AP1"}, true); err != nil { + t.Fatal(err) + } + if err := dm.SetActionPlan("AP1", &ActionPlan{ + Id: "AP1", + AccountIDs: utils.NewStringMap("1002"), + ActionTimings: []*ActionTiming{{}}, + }, true, utils.NonTransactional); err != nil { + t.Fatal(err) + } + if err := dm.SetActionPlan("AP2", &ActionPlan{ + Id: "AP2", + AccountIDs: utils.NewStringMap("1002"), + ActionTimings: []*ActionTiming{{}}, + }, true, utils.NonTransactional); err != nil { + t.Fatal(err) + } + + exp := &IndexHealthReply{ + MissingObjects: []string{}, + MissingIndexes: map[string][]string{"AP2": {"1002"}}, + BrokenReferences: map[string][]string{}, + } + if rply, err := GetAccountActionPlanIndexHealth(dm, -1, -1, -1, -1, false, false); err != nil { + t.Fatal(err) + } else if !reflect.DeepEqual(exp, rply) { + t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(exp), utils.ToJSON(rply)) + } +} + +func TestHealthAccountAction4(t *testing.T) { + Cache.Clear(nil) + cfg := config.NewDefaultCGRConfig() + db := NewInternalDB(nil, nil, true) + dm := NewDataManager(db, cfg.CacheCfg(), nil) + + if err := dm.SetAccountActionPlans("1002", []string{"AP2"}, true); err != nil { + t.Fatal(err) + } + if err := dm.SetActionPlan("AP1", &ActionPlan{ + Id: "AP1", + AccountIDs: utils.NewStringMap("1002"), + ActionTimings: []*ActionTiming{{}}, + }, true, utils.NonTransactional); err != nil { + t.Fatal(err) + } + if err := dm.SetActionPlan("AP2", &ActionPlan{ + Id: "AP2", + AccountIDs: utils.NewStringMap("1001"), + ActionTimings: []*ActionTiming{{}}, + }, true, utils.NonTransactional); err != nil { + t.Fatal(err) + } + + exp := &IndexHealthReply{ + MissingObjects: []string{}, + MissingIndexes: map[string][]string{}, + BrokenReferences: map[string][]string{"AP2": {"1001"}, "AP1": {"1002"}}, + } + if rply, err := GetAccountActionPlanIndexHealth(dm, -1, -1, -1, -1, false, false); err != nil { + t.Fatal(err) + } else if !reflect.DeepEqual(exp, rply) { + t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(exp), utils.ToJSON(rply)) + } } -*/