From 5b26fc0101d946e7cb7a09c47834137ddaf618f8 Mon Sep 17 00:00:00 2001 From: demoManito <1430482733@qq.com> Date: Fri, 16 Sep 2022 17:08:29 +0800 Subject: [PATCH] fix test Signed-off-by: demoManito <1430482733@qq.com> --- client/pkg/types/set.go | 2 +- client/pkg/types/set_test.go | 7 +++---- tests/integration/clientv3/kv_test.go | 12 +++++------- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/client/pkg/types/set.go b/client/pkg/types/set.go index e7a3cdc9a..3e69c8d8b 100644 --- a/client/pkg/types/set.go +++ b/client/pkg/types/set.go @@ -90,7 +90,7 @@ func (us *unsafeSet) Length() int { // Values returns the values of the Set in an unspecified order. func (us *unsafeSet) Values() (values []string) { - values = make([]string, 0) + values = make([]string, 0, len(us.d)) for val := range us.d { values = append(values, val) } diff --git a/client/pkg/types/set_test.go b/client/pkg/types/set_test.go index b5ff18225..735720289 100644 --- a/client/pkg/types/set_test.go +++ b/client/pkg/types/set_test.go @@ -39,10 +39,9 @@ func equal(a, b []string) bool { func driveSetTests(t *testing.T, s Set) { // Verify operations on an empty set - var eValues []string values := s.Values() - if !reflect.DeepEqual(values, eValues) { - t.Fatalf("Expect values=%v got %v", eValues, values) + if len(values) != 0 { + t.Fatalf("Expect values=%v got %v", []string{}, values) } if l := s.Length(); l != 0 { t.Fatalf("Expected length=0, got %d", l) @@ -58,7 +57,7 @@ func driveSetTests(t *testing.T, s Set) { s.Add("bar") s.Add("baz") - eValues = []string{"foo", "bar", "baz"} + eValues := []string{"foo", "bar", "baz"} values = s.Values() if !equal(values, eValues) { t.Fatalf("Expect values=%v got %v", eValues, values) diff --git a/tests/integration/clientv3/kv_test.go b/tests/integration/clientv3/kv_test.go index 282c8152b..d5a1b0b2e 100644 --- a/tests/integration/clientv3/kv_test.go +++ b/tests/integration/clientv3/kv_test.go @@ -353,17 +353,15 @@ func TestKVDeleteRange(t *testing.T) { ctx := context.TODO() tests := []struct { - key string - opts []clientv3.OpOption - + key string + opts []clientv3.OpOption wkeys []string }{ // * { - key: "\x00", - opts: []clientv3.OpOption{clientv3.WithFromKey()}, - - wkeys: []string{}, + key: "\x00", + opts: []clientv3.OpOption{clientv3.WithFromKey()}, + wkeys: nil, }, }