From 97ff5fabc5c72db5b8928b1916224d0dcc2a29ee Mon Sep 17 00:00:00 2001 From: Trial97 Date: Wed, 24 Oct 2018 16:26:24 +0300 Subject: [PATCH] Added protection from panic to some integration tests --- apier/v1/attributes_it_test.go | 7 +++++++ apier/v1/filterindexecache_it_test.go | 7 +++++++ apier/v1/resourcesv1_it_test.go | 21 +++++++++++++++++++++ general_tests/oldtutorial_it_test.go | 7 +++++++ general_tests/tp_it_test.go | 14 ++++++++++++++ 5 files changed, 56 insertions(+) diff --git a/apier/v1/attributes_it_test.go b/apier/v1/attributes_it_test.go index d61f17684..54d39ce34 100644 --- a/apier/v1/attributes_it_test.go +++ b/apier/v1/attributes_it_test.go @@ -188,6 +188,13 @@ func testAttributeSGetAttributeForEvent(t *testing.T) { ev, &attrReply); err != nil { t.Error(err) } + if attrReply == nil { + t.Errorf("Expecting attrReply to not be nil") + // attrReply shoud not be nil so exit function + // to avoid nil segmentation fault; + // if this happens try to run this test manualy + return + } attrReply.Compile() // Populate private variables in RSRParsers if !reflect.DeepEqual(eAttrPrf.Attributes[0].Substitute[0], attrReply.Attributes[0].Substitute[0]) { t.Errorf("Expecting: %+v, received: %+v", eAttrPrf.Attributes[0].Substitute[0], attrReply.Attributes[0].Substitute[0]) diff --git a/apier/v1/filterindexecache_it_test.go b/apier/v1/filterindexecache_it_test.go index 9b26fe591..372a0be1c 100644 --- a/apier/v1/filterindexecache_it_test.go +++ b/apier/v1/filterindexecache_it_test.go @@ -381,6 +381,13 @@ func testV1FIdxCaUpdateThresholdProfileFromTP(t *testing.T) { t.Error(err) } time.Sleep(100 * time.Millisecond) + if reply == nil { + t.Errorf("Expecting reply to not be nil") + // reply shoud not be nil so exit function + // to avoid nil segmentation fault; + // if this happens try to run this test manualy + return + } reply.FilterIDs = []string{"TestFilter3"} if err := tFIdxCaRpc.Call("ApierV1.SetThresholdProfile", reply, &result); err != nil { diff --git a/apier/v1/resourcesv1_it_test.go b/apier/v1/resourcesv1_it_test.go index 4997c96f5..c66ca5663 100644 --- a/apier/v1/resourcesv1_it_test.go +++ b/apier/v1/resourcesv1_it_test.go @@ -150,6 +150,13 @@ func testV1RsGetResourcesForEvent(t *testing.T) { t.Error(err) } time.Sleep(time.Duration(500) * time.Millisecond) + if reply == nil { + t.Errorf("Expecting reply to not be nil") + // reply shoud not be nil so exit function + // to avoid nil segmentation fault; + // if this happens try to run this test manualy + return + } if len(*reply) != 1 { t.Errorf("Expecting: %+v, received: %+v", 1, len(*reply)) } @@ -475,6 +482,13 @@ func testV1RsReleaseResource(t *testing.T) { } else if len(*rs) != 2 { t.Errorf("Resources: %+v", rs) } + if rs == nil { + t.Errorf("Expecting rs to not be nil") + // rs shoud not be nil so exit function + // to avoid nil segmentation fault; + // if this happens try to run this test manualy + return + } // make sure Resource1 have no more active resources for _, r := range *rs { if r.ID == "ResGroup1" && @@ -518,6 +532,13 @@ func testV1RsDBStore(t *testing.T) { } else if len(*rs) != 2 { t.Errorf("Resources: %+v", rs) } + if rs == nil { + t.Errorf("Expecting rs to not be nil") + // rs shoud not be nil so exit function + // to avoid nil segmentation fault; + // if this happens try to run this test manualy + return + } // count resources before restart for _, r := range *rs { switch r.ID { diff --git a/general_tests/oldtutorial_it_test.go b/general_tests/oldtutorial_it_test.go index cad63d876..385299a67 100644 --- a/general_tests/oldtutorial_it_test.go +++ b/general_tests/oldtutorial_it_test.go @@ -122,6 +122,13 @@ func TestTutITCacheStats(t *testing.T) { if err := tutLocalRpc.Call("ApierV1.GetCacheKeys", argsAPI, &rcvKeys); err != nil { t.Error("Got error on ApierV1.GetCacheStats: ", err.Error()) } else { + if rcvKeys.DestinationIDs == nil { + t.Errorf("Expecting rcvKeys.DestinationIDs to not be nil") + // rcvKeys.DestinationIDs shoud not be nil so exit function + // to avoid nil segmentation fault; + // if this happens try to run this test manualy + return + } if len(*expKeys.DestinationIDs) != len(*rcvKeys.DestinationIDs) { t.Errorf("Expected: %+v, received: %+v", expKeys.DestinationIDs, rcvKeys.DestinationIDs) } diff --git a/general_tests/tp_it_test.go b/general_tests/tp_it_test.go index 23d609571..4d1f95415 100644 --- a/general_tests/tp_it_test.go +++ b/general_tests/tp_it_test.go @@ -144,6 +144,13 @@ func TestTpActionTriggers(t *testing.T) { } else if len(atrs) != 1 { t.Errorf("Calling v1.GetActionTriggers got: %v", atrs) } + if atrs == nil { + t.Errorf("Expecting atrs to not be nil") + // atrs shoud not be nil so exit function + // to avoid nil segmentation fault; + // if this happens try to run this test manualy + return + } if atrs[0].ID != "TestATR" || atrs[0].UniqueID != "Unique atr id" || *atrs[0].Balance.ID != "BID1" { @@ -157,6 +164,13 @@ func TestTpZeroCost(t *testing.T) { if err := tpRPC.Call("ApierV2.GetAccount", attrs, &acnt); err != nil { t.Error("Got error on ApierV2.GetAccount: ", err.Error()) } + if acnt == nil { + t.Errorf("Expecting acnt to not be nil") + // acnt shoud not be nil so exit function + // to avoid nil segmentation fault; + // if this happens try to run this test manualy + return + } balanceValueBefore := acnt.BalanceMap[utils.MONETARY][0].Value tStart := time.Date(2016, 3, 31, 0, 0, 0, 0, time.UTC) cd := engine.CallDescriptor{