From 56f9d16cc0bb2007b5e4e0016966ef9a9b2a827d Mon Sep 17 00:00:00 2001 From: andronache Date: Wed, 25 Nov 2020 11:55:27 +0200 Subject: [PATCH] Added tests in utils --- utils/coreutils_test.go | 14 +++++++------- utils/mapstorage_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/utils/coreutils_test.go b/utils/coreutils_test.go index 087212a99..16a4ea96a 100644 --- a/utils/coreutils_test.go +++ b/utils/coreutils_test.go @@ -1514,13 +1514,6 @@ func TestIsURL(t *testing.T) { } } -func TestComputeHashError(t *testing.T) { - _, err := ComputeHash("test1;test2;test3") - if err != nil { - t.Errorf("Expecting: , received: %+v", err) - } -} - func TestComputeHashMatch(t *testing.T) { lns, _ := ComputeHash("test1;test2;test3") if err := VerifyHash(lns, "test1;test2;test3"); err != true { @@ -1585,3 +1578,10 @@ func TestAESEncryptDecrypt(t *testing.T) { t.Errorf("Expecting: , received: <%+v>", dString) } } + +func TestBoolGenerator(t *testing.T) { + boolTest := BoolGenerator().RandomBool() + if boolTest != true && boolTest != false { + t.Errorf("Needs to be bool") + } +} diff --git a/utils/mapstorage_test.go b/utils/mapstorage_test.go index 314f852f9..d66123b64 100644 --- a/utils/mapstorage_test.go +++ b/utils/mapstorage_test.go @@ -748,3 +748,32 @@ func TestMapStorageCloneNil(t *testing.T) { t.Errorf("Expecting: , received: %+v", test.Clone()) } } + +func TestNavMapGetFieldAsMapStringInterfaceError(t *testing.T) { + nM := MapStorage{ + "AnotherFirstLevel": "ValAnotherFirstLevel", + "Slice": &[]struct{}{{}}, + "SliceString": []string{"1", "2"}, + "SliceInterface": map[string]interface{}{}, + } + path := []string{"SliceInterface[4]"} + _, err := nM.FieldAsInterface(path) + if err == nil || err.Error() != "NOT_FOUND" { + t.Errorf("Expecting: , received: %+v", err) + } + +} + +func TestNavMapGetFieldAsMapStringInterface(t *testing.T) { + nM := MapStorage{ + "FIELD": map[string]interface{}{ + "Field1": "Val1", + "Field2": "Val2"}, + } + path := []string{"FIELD[Field2]"} + result, _ := nM.FieldAsInterface(path) + if reflect.DeepEqual(result, "val2") { + t.Errorf("Expecting: , received: %+v", result) + } + +}