Parcourir la source

Increase code coverage for set_matrix

Signed-off-by: Flavio Crisciani <flavio.crisciani@docker.com>
Flavio Crisciani il y a 7 ans
Parent
commit
b76166c110
1 fichiers modifiés avec 39 ajouts et 0 suppressions
  1. 39 0
      libnetwork/common/setmatrix_test.go

+ 39 - 0
libnetwork/common/setmatrix_test.go

@@ -3,6 +3,7 @@ package common
 import (
 import (
 	"context"
 	"context"
 	"strconv"
 	"strconv"
+	"strings"
 	"testing"
 	"testing"
 	"time"
 	"time"
 
 
@@ -66,6 +67,23 @@ func TestSetSerialInsertDelete(t *testing.T) {
 	if !b || i != 4 {
 	if !b || i != 4 {
 		t.Fatalf("error in cardinality count %t %d", b, i)
 		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")
 	b, i = s.Remove("a", "1")
 	if !b || i != 3 {
 	if !b || i != 3 {
@@ -96,6 +114,27 @@ func TestSetSerialInsertDelete(t *testing.T) {
 	if b || i != 0 {
 	if b || i != 0 {
 		t.Fatalf("error in cardinality count %t %d", b, i)
 		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) {
 func insertDeleteRotuine(ctx context.Context, endCh chan int, s SetMatrix, key, value string) {