From b76166c1104a80ef05613a02804314f24e779a07 Mon Sep 17 00:00:00 2001 From: Flavio Crisciani Date: Tue, 29 Aug 2017 17:49:42 -0700 Subject: [PATCH] Increase code coverage for set_matrix Signed-off-by: Flavio Crisciani --- libnetwork/common/setmatrix_test.go | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/libnetwork/common/setmatrix_test.go b/libnetwork/common/setmatrix_test.go index d87ffc7dfe..875bbfbf71 100644 --- a/libnetwork/common/setmatrix_test.go +++ b/libnetwork/common/setmatrix_test.go @@ -3,6 +3,7 @@ package common import ( "context" "strconv" + "strings" "testing" "time" @@ -66,6 +67,23 @@ func TestSetSerialInsertDelete(t *testing.T) { if !b || i != 4 { t.Fatalf("error in cardinality count %t %d", b, i) } + keys := s.Keys() + if len(keys) != 1 { + t.Fatalf("error in keys %v", keys) + } + str, b := s.String("a") + if !b || + !strings.Contains(str, "1") || + !strings.Contains(str, "2") || + !strings.Contains(str, "3") || + !strings.Contains(str, "4") { + t.Fatalf("error in string %t %s", b, str) + } + + _, b = s.Get("a") + if !b { + t.Fatalf("error in get %t", b) + } b, i = s.Remove("a", "1") if !b || i != 3 { @@ -96,6 +114,27 @@ func TestSetSerialInsertDelete(t *testing.T) { if b || i != 0 { t.Fatalf("error in cardinality count %t %d", b, i) } + + str, b = s.String("a") + if b || str != "" { + t.Fatalf("error in string %t %s", b, str) + } + + keys = s.Keys() + if len(keys) > 0 { + t.Fatalf("error in keys %v", keys) + } + + // Negative tests + _, b = s.Get("not exists") + if b { + t.Fatalf("error should not happen %t", b) + } + + b1, b := s.Contains("not exists", "a") + if b1 || b { + t.Fatalf("error should not happen %t %t", b1, b) + } } func insertDeleteRotuine(ctx context.Context, endCh chan int, s SetMatrix, key, value string) {