From d0720765a15b5e94c9b3f55b3d81c054dc6e79a1 Mon Sep 17 00:00:00 2001 From: Congqi Xia Date: Thu, 20 Jun 2024 19:29:18 +0800 Subject: [PATCH 1/2] enhance: Add rules and fix for go_client e2e code style See also #31293 Signed-off-by: Congqi Xia --- Makefile | 6 + client/column/scalar_gen.go | 4 +- client/column/vector_gen.go | 8 +- tests/go_client/.golangci.yml | 11 + tests/go_client/base/milvus_client.go | 10 +- tests/go_client/common/response_checker.go | 15 +- tests/go_client/common/utils.go | 21 +- tests/go_client/ruleguard/rules.go | 409 ++++++++++++++++++ tests/go_client/testcases/client_test.go | 6 +- tests/go_client/testcases/collection_test.go | 19 +- tests/go_client/testcases/delete_test.go | 10 +- .../go_client/testcases/helper/data_helper.go | 3 +- .../testcases/helper/field_helper.go | 7 +- tests/go_client/testcases/helper/helper.go | 26 +- .../testcases/helper/index_helper.go | 2 +- .../go_client/testcases/helper/rows_helper.go | 6 +- tests/go_client/testcases/insert_test.go | 15 +- tests/go_client/testcases/main_test.go | 7 +- tests/go_client/testcases/search_test.go | 3 +- 19 files changed, 510 insertions(+), 78 deletions(-) create mode 100644 tests/go_client/.golangci.yml create mode 100644 tests/go_client/ruleguard/rules.go diff --git a/Makefile b/Makefile index 2a3372bad495..24a6e716540b 100644 --- a/Makefile +++ b/Makefile @@ -144,6 +144,7 @@ lint-fix: getdeps @$(INSTALL_PATH)/gofumpt -l -w cmd/ @$(INSTALL_PATH)/gofumpt -l -w pkg/ @$(INSTALL_PATH)/gofumpt -l -w client/ + @$(INSTALL_PATH)/gofumpt -l -w tests/go_client/ @$(INSTALL_PATH)/gofumpt -l -w tests/integration/ @echo "Running gci fix" @$(INSTALL_PATH)/gci write cmd/ --skip-generated -s standard -s default -s "prefix(github.com/milvus-io)" --custom-order @@ -159,9 +160,14 @@ lint-fix: getdeps #TODO: Check code specifications by golangci-lint static-check: getdeps @echo "Running $@ check" + @echo "Start check core packages" @source $(PWD)/scripts/setenv.sh && GO111MODULE=on $(INSTALL_PATH)/golangci-lint run --build-tags dynamic,test --timeout=30m --config $(PWD)/.golangci.yml + @echo "Start check pkg package" @source $(PWD)/scripts/setenv.sh && cd pkg && GO111MODULE=on $(INSTALL_PATH)/golangci-lint run --build-tags dynamic,test --timeout=30m --config $(PWD)/.golangci.yml + @echo "Start check client package" @source $(PWD)/scripts/setenv.sh && cd client && GO111MODULE=on $(INSTALL_PATH)/golangci-lint run --timeout=30m --config $(PWD)/client/.golangci.yml + @echo "Start check go_client e2e package" + @source $(PWD)/scripts/setenv.sh && cd tests/go_client && GO111MODULE=on $(INSTALL_PATH)/golangci-lint run --timeout=30m --config $(PWD)/client/.golangci.yml verifiers: build-cpp getdeps cppcheck fmt static-check diff --git a/client/column/scalar_gen.go b/client/column/scalar_gen.go index 9045a1b9b015..734ee127dc73 100644 --- a/client/column/scalar_gen.go +++ b/client/column/scalar_gen.go @@ -451,8 +451,8 @@ func (c *ColumnInt64) Slice(start, end int) Column { } return &ColumnInt64{ ColumnBase: c.ColumnBase, - name: c.name, - values: c.values[start: end], + name: c.name, + values: c.values[start:end], } } diff --git a/client/column/vector_gen.go b/client/column/vector_gen.go index 5d817d581261..e72a78ee0906 100644 --- a/client/column/vector_gen.go +++ b/client/column/vector_gen.go @@ -48,7 +48,7 @@ func (c *ColumnBinaryVector) Slice(start, end int) Column { return &ColumnBinaryVector{ ColumnBase: c.ColumnBase, name: c.name, - dim: c.dim, + dim: c.dim, values: c.values[start:end], } } @@ -153,7 +153,7 @@ func (c *ColumnFloatVector) Slice(start, end int) Column { return &ColumnFloatVector{ ColumnBase: c.ColumnBase, name: c.name, - dim: c.dim, + dim: c.dim, values: c.values[start:end], } } @@ -260,7 +260,7 @@ func (c *ColumnFloat16Vector) Slice(start, end int) Column { return &ColumnFloat16Vector{ ColumnBase: c.ColumnBase, name: c.name, - dim: c.dim, + dim: c.dim, values: c.values[start:end], } } @@ -365,7 +365,7 @@ func (c *ColumnBFloat16Vector) Slice(start, end int) Column { return &ColumnBFloat16Vector{ ColumnBase: c.ColumnBase, name: c.name, - dim: c.dim, + dim: c.dim, values: c.values[start:end], } } diff --git a/tests/go_client/.golangci.yml b/tests/go_client/.golangci.yml new file mode 100644 index 000000000000..dbc0867c58f4 --- /dev/null +++ b/tests/go_client/.golangci.yml @@ -0,0 +1,11 @@ +include: + - "../../.golangci.yml" + +linters-settings: + gocritic: + enabled-checks: + - ruleguard + settings: + ruleguard: + failOnError: true + rules: "ruleguard/rules.go" \ No newline at end of file diff --git a/tests/go_client/base/milvus_client.go b/tests/go_client/base/milvus_client.go index 4460a3106d4b..911906219b15 100644 --- a/tests/go_client/base/milvus_client.go +++ b/tests/go_client/base/milvus_client.go @@ -6,15 +6,13 @@ import ( "strings" "time" - "github.com/milvus-io/milvus/client/v2/entity" - "github.com/milvus-io/milvus/pkg/log" - "go.uber.org/zap" - "google.golang.org/grpc" clientv2 "github.com/milvus-io/milvus/client/v2" + "github.com/milvus-io/milvus/client/v2/entity" "github.com/milvus-io/milvus/client/v2/index" + "github.com/milvus-io/milvus/pkg/log" ) func LoggingUnaryInterceptor() grpc.UnaryClientInterceptor { @@ -116,7 +114,7 @@ func (mc *MilvusClient) ListCollections(ctx context.Context, option clientv2.Lis return collectionNames, err } -//DescribeCollection Describe collection +// DescribeCollection Describe collection func (mc *MilvusClient) DescribeCollection(ctx context.Context, option clientv2.DescribeCollectionOption, callOptions ...grpc.CallOption) (*entity.Collection, error) { collection, err := mc.mClient.DescribeCollection(ctx, option, callOptions...) return collection, err @@ -197,7 +195,7 @@ func (mc *MilvusClient) DropIndex(ctx context.Context, option clientv2.DropIndex // Insert insert data func (mc *MilvusClient) Insert(ctx context.Context, option clientv2.InsertOption, callOptions ...grpc.CallOption) (clientv2.InsertResult, error) { insertRes, err := mc.mClient.Insert(ctx, option, callOptions...) - if err == nil{ + if err == nil { log.Info("Insert", zap.Any("result", insertRes)) } return insertRes, err diff --git a/tests/go_client/common/response_checker.go b/tests/go_client/common/response_checker.go index 0160f23cbbb8..eed14d4f5edf 100644 --- a/tests/go_client/common/response_checker.go +++ b/tests/go_client/common/response_checker.go @@ -5,14 +5,13 @@ import ( "strings" "testing" - "github.com/milvus-io/milvus/client/v2/column" - "github.com/milvus-io/milvus/client/v2/entity" - "go.uber.org/zap" - - "github.com/milvus-io/milvus/pkg/log" "github.com/stretchr/testify/require" + "go.uber.org/zap" clientv2 "github.com/milvus-io/milvus/client/v2" + "github.com/milvus-io/milvus/client/v2/column" + "github.com/milvus-io/milvus/client/v2/entity" + "github.com/milvus-io/milvus/pkg/log" ) func CheckErr(t *testing.T, actualErr error, expErrNil bool, expErrorMsg ...string) { @@ -71,10 +70,12 @@ func EqualColumn(t *testing.T, columnA column.Column, columnB column.Column) { case entity.FieldTypeArray: log.Info("TODO support column element type") default: - log.Info("Support column type is:", zap.Any("FieldType", []entity.FieldType{entity.FieldTypeBool, + log.Info("Support column type is:", zap.Any("FieldType", []entity.FieldType{ + entity.FieldTypeBool, entity.FieldTypeInt8, entity.FieldTypeInt16, entity.FieldTypeInt32, entity.FieldTypeInt64, entity.FieldTypeFloat, entity.FieldTypeDouble, entity.FieldTypeString, entity.FieldTypeVarChar, - entity.FieldTypeArray, entity.FieldTypeFloatVector, entity.FieldTypeBinaryVector})) + entity.FieldTypeArray, entity.FieldTypeFloatVector, entity.FieldTypeBinaryVector, + })) } } diff --git a/tests/go_client/common/utils.go b/tests/go_client/common/utils.go index 97949bb00262..b87e4ff837a9 100644 --- a/tests/go_client/common/utils.go +++ b/tests/go_client/common/utils.go @@ -8,14 +8,17 @@ import ( "strings" "time" - "github.com/milvus-io/milvus/client/v2/entity" - "github.com/milvus-io/milvus/pkg/log" "github.com/x448/float16" "go.uber.org/zap" + + "github.com/milvus-io/milvus/client/v2/entity" + "github.com/milvus-io/milvus/pkg/log" ) -var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") -var r *rand.Rand +var ( + letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") + r *rand.Rand +) func init() { r = rand.New(rand.NewSource(time.Now().UnixNano())) @@ -70,7 +73,7 @@ func GenInvalidNames() []string { func GenFloatVector(dim int) []float32 { vector := make([]float32, 0, dim) - for j := 0; j < int(dim); j++ { + for j := 0; j < dim; j++ { vector = append(vector, rand.Float32()) } return vector @@ -78,7 +81,7 @@ func GenFloatVector(dim int) []float32 { func GenFloat16Vector(dim int) []byte { ret := make([]byte, dim*2) - for i := 0; i < int(dim); i++ { + for i := 0; i < dim; i++ { v := float16.Fromfloat32(rand.Float32()).Bits() binary.LittleEndian.PutUint16(ret[i*2:], v) } @@ -87,7 +90,7 @@ func GenFloat16Vector(dim int) []byte { func GenBFloat16Vector(dim int) []byte { ret16 := make([]uint16, 0, dim) - for i := 0; i < int(dim); i++ { + for i := 0; i < dim; i++ { f := rand.Float32() bits := math.Float32bits(f) bits >>= 16 @@ -151,5 +154,5 @@ var InvalidExpressions = []InvalidExprStruct{ {Expr: fmt.Sprintf("json_contains_aby (%s['list'], 2)", DefaultJSONFieldName), ErrNil: false, ErrMsg: "invalid expression: json_contains_aby"}, {Expr: fmt.Sprintf("json_contains_aby (%s['list'], 2)", DefaultJSONFieldName), ErrNil: false, ErrMsg: "invalid expression: json_contains_aby"}, {Expr: fmt.Sprintf("%s[-1] > %d", DefaultInt8ArrayField, TestCapacity), ErrNil: false, ErrMsg: "cannot parse expression"}, // array[-1] > - {Expr: fmt.Sprintf(fmt.Sprintf("%s[-1] > 1", DefaultJSONFieldName)), ErrNil: false, ErrMsg: "invalid expression"}, // json[-1] > -} \ No newline at end of file + {Expr: fmt.Sprintf("%s[-1] > 1", DefaultJSONFieldName), ErrNil: false, ErrMsg: "invalid expression"}, // json[-1] > +} diff --git a/tests/go_client/ruleguard/rules.go b/tests/go_client/ruleguard/rules.go new file mode 100644 index 000000000000..4959a8b5effa --- /dev/null +++ b/tests/go_client/ruleguard/rules.go @@ -0,0 +1,409 @@ +// Licensed to the LF AI & Data foundation under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package gorules + +import ( + "github.com/quasilyte/go-ruleguard/dsl" +) + +// This is a collection of rules for ruleguard: https://github.com/quasilyte/go-ruleguard + +// Remove extra conversions: mdempsky/unconvert +func unconvert(m dsl.Matcher) { + m.Match("int($x)").Where(m["x"].Type.Is("int") && !m["x"].Const).Report("unnecessary conversion").Suggest("$x") + + m.Match("float32($x)").Where(m["x"].Type.Is("float32") && !m["x"].Const).Report("unnecessary conversion").Suggest("$x") + m.Match("float64($x)").Where(m["x"].Type.Is("float64") && !m["x"].Const).Report("unnecessary conversion").Suggest("$x") + + // m.Match("byte($x)").Where(m["x"].Type.Is("byte")).Report("unnecessary conversion").Suggest("$x") + // m.Match("rune($x)").Where(m["x"].Type.Is("rune")).Report("unnecessary conversion").Suggest("$x") + m.Match("bool($x)").Where(m["x"].Type.Is("bool") && !m["x"].Const).Report("unnecessary conversion").Suggest("$x") + + m.Match("int8($x)").Where(m["x"].Type.Is("int8") && !m["x"].Const).Report("unnecessary conversion").Suggest("$x") + m.Match("int16($x)").Where(m["x"].Type.Is("int16") && !m["x"].Const).Report("unnecessary conversion").Suggest("$x") + m.Match("int32($x)").Where(m["x"].Type.Is("int32") && !m["x"].Const).Report("unnecessary conversion").Suggest("$x") + m.Match("int64($x)").Where(m["x"].Type.Is("int64") && !m["x"].Const).Report("unnecessary conversion").Suggest("$x") + + m.Match("uint8($x)").Where(m["x"].Type.Is("uint8") && !m["x"].Const).Report("unnecessary conversion").Suggest("$x") + m.Match("uint16($x)").Where(m["x"].Type.Is("uint16") && !m["x"].Const).Report("unnecessary conversion").Suggest("$x") + m.Match("uint32($x)").Where(m["x"].Type.Is("uint32") && !m["x"].Const).Report("unnecessary conversion").Suggest("$x") + m.Match("uint64($x)").Where(m["x"].Type.Is("uint64") && !m["x"].Const).Report("unnecessary conversion").Suggest("$x") + + m.Match("time.Duration($x)").Where(m["x"].Type.Is("time.Duration") && !m["x"].Text.Matches("^[0-9]*$")).Report("unnecessary conversion").Suggest("$x") +} + +// Don't use == or != with time.Time +// https://github.com/dominikh/go-tools/issues/47 : Wontfix +func timeeq(m dsl.Matcher) { + m.Match("$t0 == $t1").Where(m["t0"].Type.Is("time.Time")).Report("using == with time.Time") + m.Match("$t0 != $t1").Where(m["t0"].Type.Is("time.Time")).Report("using != with time.Time") + m.Match(`map[$k]$v`).Where(m["k"].Type.Is("time.Time")).Report("map with time.Time keys are easy to misuse") +} + +// err but no an error +func errnoterror(m dsl.Matcher) { + // Would be easier to check for all err identifiers instead, but then how do we get the type from m[] ? + + m.Match( + "if $*_, err := $x; $err != nil { $*_ } else if $_ { $*_ }", + "if $*_, err := $x; $err != nil { $*_ } else { $*_ }", + "if $*_, err := $x; $err != nil { $*_ }", + + "if $*_, err = $x; $err != nil { $*_ } else if $_ { $*_ }", + "if $*_, err = $x; $err != nil { $*_ } else { $*_ }", + "if $*_, err = $x; $err != nil { $*_ }", + + "$*_, err := $x; if $err != nil { $*_ } else if $_ { $*_ }", + "$*_, err := $x; if $err != nil { $*_ } else { $*_ }", + "$*_, err := $x; if $err != nil { $*_ }", + + "$*_, err = $x; if $err != nil { $*_ } else if $_ { $*_ }", + "$*_, err = $x; if $err != nil { $*_ } else { $*_ }", + "$*_, err = $x; if $err != nil { $*_ }", + ). + Where(m["err"].Text == "err" && !m["err"].Type.Is("error") && m["x"].Text != "recover()"). + Report("err variable not error type") +} + +// Identical if and else bodies +func ifbodythenbody(m dsl.Matcher) { + m.Match("if $*_ { $body } else { $body }"). + Report("identical if and else bodies") + + // Lots of false positives. + // m.Match("if $*_ { $body } else if $*_ { $body }"). + // Report("identical if and else bodies") +} + +// Odd inequality: A - B < 0 instead of != +// Too many false positives. +/* +func subtractnoteq(m dsl.Matcher) { + m.Match("$a - $b < 0").Report("consider $a != $b") + m.Match("$a - $b > 0").Report("consider $a != $b") + m.Match("0 < $a - $b").Report("consider $a != $b") + m.Match("0 > $a - $b").Report("consider $a != $b") +} +*/ + +// Self-assignment +func selfassign(m dsl.Matcher) { + m.Match("$x = $x").Report("useless self-assignment") +} + +// Odd nested ifs +func oddnestedif(m dsl.Matcher) { + m.Match("if $x { if $x { $*_ }; $*_ }", + "if $x == $y { if $x != $y {$*_ }; $*_ }", + "if $x != $y { if $x == $y {$*_ }; $*_ }", + "if $x { if !$x { $*_ }; $*_ }", + "if !$x { if $x { $*_ }; $*_ }"). + Report("odd nested ifs") + + m.Match("for $x { if $x { $*_ }; $*_ }", + "for $x == $y { if $x != $y {$*_ }; $*_ }", + "for $x != $y { if $x == $y {$*_ }; $*_ }", + "for $x { if !$x { $*_ }; $*_ }", + "for !$x { if $x { $*_ }; $*_ }"). + Report("odd nested for/ifs") +} + +// odd bitwise expressions +func oddbitwise(m dsl.Matcher) { + m.Match("$x | $x", + "$x | ^$x", + "^$x | $x"). + Report("odd bitwise OR") + + m.Match("$x & $x", + "$x & ^$x", + "^$x & $x"). + Report("odd bitwise AND") + + m.Match("$x &^ $x"). + Report("odd bitwise AND-NOT") +} + +// odd sequence of if tests with return +func ifreturn(m dsl.Matcher) { + m.Match("if $x { return $*_ }; if $x {$*_ }").Report("odd sequence of if test") + m.Match("if $x { return $*_ }; if !$x {$*_ }").Report("odd sequence of if test") + m.Match("if !$x { return $*_ }; if $x {$*_ }").Report("odd sequence of if test") + m.Match("if $x == $y { return $*_ }; if $x != $y {$*_ }").Report("odd sequence of if test") + m.Match("if $x != $y { return $*_ }; if $x == $y {$*_ }").Report("odd sequence of if test") +} + +func oddifsequence(m dsl.Matcher) { + /* + m.Match("if $x { $*_ }; if $x {$*_ }").Report("odd sequence of if test") + + m.Match("if $x == $y { $*_ }; if $y == $x {$*_ }").Report("odd sequence of if tests") + m.Match("if $x != $y { $*_ }; if $y != $x {$*_ }").Report("odd sequence of if tests") + + m.Match("if $x < $y { $*_ }; if $y > $x {$*_ }").Report("odd sequence of if tests") + m.Match("if $x <= $y { $*_ }; if $y >= $x {$*_ }").Report("odd sequence of if tests") + + m.Match("if $x > $y { $*_ }; if $y < $x {$*_ }").Report("odd sequence of if tests") + m.Match("if $x >= $y { $*_ }; if $y <= $x {$*_ }").Report("odd sequence of if tests") + */ +} + +// odd sequence of nested if tests +func nestedifsequence(m dsl.Matcher) { + /* + m.Match("if $x < $y { if $x >= $y {$*_ }; $*_ }").Report("odd sequence of nested if tests") + m.Match("if $x <= $y { if $x > $y {$*_ }; $*_ }").Report("odd sequence of nested if tests") + m.Match("if $x > $y { if $x <= $y {$*_ }; $*_ }").Report("odd sequence of nested if tests") + m.Match("if $x >= $y { if $x < $y {$*_ }; $*_ }").Report("odd sequence of nested if tests") + */ +} + +// odd sequence of assignments +func identicalassignments(m dsl.Matcher) { + m.Match("$x = $y; $y = $x").Report("odd sequence of assignments") +} + +func oddcompoundop(m dsl.Matcher) { + m.Match("$x += $x + $_", + "$x += $x - $_"). + Report("odd += expression") + + m.Match("$x -= $x + $_", + "$x -= $x - $_"). + Report("odd -= expression") +} + +func constswitch(m dsl.Matcher) { + m.Match("switch $x { $*_ }", "switch $*_; $x { $*_ }"). + Where(m["x"].Const && !m["x"].Text.Matches(`^runtime\.`)). + Report("constant switch") +} + +func oddcomparisons(m dsl.Matcher) { + m.Match( + "$x - $y == 0", + "$x - $y != 0", + "$x - $y < 0", + "$x - $y <= 0", + "$x - $y > 0", + "$x - $y >= 0", + "$x ^ $y == 0", + "$x ^ $y != 0", + ).Report("odd comparison") +} + +func oddmathbits(m dsl.Matcher) { + m.Match( + "64 - bits.LeadingZeros64($x)", + "32 - bits.LeadingZeros32($x)", + "16 - bits.LeadingZeros16($x)", + "8 - bits.LeadingZeros8($x)", + ).Report("odd math/bits expression: use bits.Len*() instead?") +} + +// func floateq(m dsl.Matcher) { +// m.Match( +// "$x == $y", +// "$x != $y", +// ). +// Where(m["x"].Type.Is("float32") && !m["x"].Const && !m["y"].Text.Matches("0(.0+)?") && !m.File().Name.Matches("floating_comparision.go")). +// Report("floating point tested for equality") + +// m.Match( +// "$x == $y", +// "$x != $y", +// ). +// Where(m["x"].Type.Is("float64") && !m["x"].Const && !m["y"].Text.Matches("0(.0+)?") && !m.File().Name.Matches("floating_comparision.go")). +// Report("floating point tested for equality") + +// m.Match("switch $x { $*_ }", "switch $*_; $x { $*_ }"). +// Where(m["x"].Type.Is("float32")). +// Report("floating point as switch expression") + +// m.Match("switch $x { $*_ }", "switch $*_; $x { $*_ }"). +// Where(m["x"].Type.Is("float64")). +// Report("floating point as switch expression") + +// } + +func badexponent(m dsl.Matcher) { + m.Match( + "2 ^ $x", + "10 ^ $x", + ). + Report("caret (^) is not exponentiation") +} + +func floatloop(m dsl.Matcher) { + m.Match( + "for $i := $x; $i < $y; $i += $z { $*_ }", + "for $i = $x; $i < $y; $i += $z { $*_ }", + ). + Where(m["i"].Type.Is("float64")). + Report("floating point for loop counter") + + m.Match( + "for $i := $x; $i < $y; $i += $z { $*_ }", + "for $i = $x; $i < $y; $i += $z { $*_ }", + ). + Where(m["i"].Type.Is("float32")). + Report("floating point for loop counter") +} + +func urlredacted(m dsl.Matcher) { + m.Match( + "log.Println($x, $*_)", + "log.Println($*_, $x, $*_)", + "log.Println($*_, $x)", + "log.Printf($*_, $x, $*_)", + "log.Printf($*_, $x)", + + "log.Println($x, $*_)", + "log.Println($*_, $x, $*_)", + "log.Println($*_, $x)", + "log.Printf($*_, $x, $*_)", + "log.Printf($*_, $x)", + ). + Where(m["x"].Type.Is("*url.URL")). + Report("consider $x.Redacted() when outputting URLs") +} + +func sprinterr(m dsl.Matcher) { + m.Match(`fmt.Sprint($err)`, + `fmt.Sprintf("%s", $err)`, + `fmt.Sprintf("%v", $err)`, + ). + Where(m["err"].Type.Is("error")). + Report("maybe call $err.Error() instead of fmt.Sprint()?") +} + +// disable this check, because it can not apply to generic type +// func largeloopcopy(m dsl.Matcher) { +// m.Match( +// `for $_, $v := range $_ { $*_ }`, +// ). +// Where(m["v"].Type.Size > 1024). +// Report(`loop copies large value each iteration`) +//} + +func joinpath(m dsl.Matcher) { + m.Match( + `strings.Join($_, "/")`, + `strings.Join($_, "\\")`, + "strings.Join($_, `\\`)", + ). + Report(`did you mean path.Join() or filepath.Join() ?`) +} + +func readfull(m dsl.Matcher) { + m.Match(`$n, $err := io.ReadFull($_, $slice) + if $err != nil || $n != len($slice) { + $*_ + }`, + `$n, $err := io.ReadFull($_, $slice) + if $n != len($slice) || $err != nil { + $*_ + }`, + `$n, $err = io.ReadFull($_, $slice) + if $err != nil || $n != len($slice) { + $*_ + }`, + `$n, $err = io.ReadFull($_, $slice) + if $n != len($slice) || $err != nil { + $*_ + }`, + `if $n, $err := io.ReadFull($_, $slice); $n != len($slice) || $err != nil { + $*_ + }`, + `if $n, $err := io.ReadFull($_, $slice); $err != nil || $n != len($slice) { + $*_ + }`, + `if $n, $err = io.ReadFull($_, $slice); $n != len($slice) || $err != nil { + $*_ + }`, + `if $n, $err = io.ReadFull($_, $slice); $err != nil || $n != len($slice) { + $*_ + }`, + ).Report("io.ReadFull() returns err == nil iff n == len(slice)") +} + +func nilerr(m dsl.Matcher) { + m.Match( + `if err == nil { return err }`, + `if err == nil { return $*_, err }`, + ). + Report(`return nil error instead of nil value`) +} + +func mailaddress(m dsl.Matcher) { + m.Match( + "fmt.Sprintf(`\"%s\" <%s>`, $NAME, $EMAIL)", + "fmt.Sprintf(`\"%s\"<%s>`, $NAME, $EMAIL)", + "fmt.Sprintf(`%s <%s>`, $NAME, $EMAIL)", + "fmt.Sprintf(`%s<%s>`, $NAME, $EMAIL)", + `fmt.Sprintf("\"%s\"<%s>", $NAME, $EMAIL)`, + `fmt.Sprintf("\"%s\" <%s>", $NAME, $EMAIL)`, + `fmt.Sprintf("%s<%s>", $NAME, $EMAIL)`, + `fmt.Sprintf("%s <%s>", $NAME, $EMAIL)`, + ). + Report("use net/mail Address.String() instead of fmt.Sprintf()"). + Suggest("(&mail.Address{Name:$NAME, Address:$EMAIL}).String()") +} + +func errnetclosed(m dsl.Matcher) { + m.Match( + `strings.Contains($err.Error(), $text)`, + ). + Where(m["text"].Text.Matches("\".*closed network connection.*\"")). + Report(`String matching against error texts is fragile; use net.ErrClosed instead`). + Suggest(`errors.Is($err, net.ErrClosed)`) +} + +func httpheaderadd(m dsl.Matcher) { + m.Match( + `$H.Add($KEY, $VALUE)`, + ). + Where(m["H"].Type.Is("http.Header")). + Report("use http.Header.Set method instead of Add to overwrite all existing header values"). + Suggest(`$H.Set($KEY, $VALUE)`) +} + +func hmacnew(m dsl.Matcher) { + m.Match("hmac.New(func() hash.Hash { return $x }, $_)", + `$f := func() hash.Hash { return $x } + $*_ + hmac.New($f, $_)`, + ).Where(m["x"].Pure). + Report("invalid hash passed to hmac.New()") +} + +func writestring(m dsl.Matcher) { + m.Match(`io.WriteString($w, string($b))`). + Where(m["b"].Type.Is("[]byte")). + Suggest("$w.Write($b)") +} + +func badlock(m dsl.Matcher) { + // Shouldn't give many false positives without type filter + // as Lock+Unlock pairs in combination with defer gives us pretty + // a good chance to guess correctly. If we constrain the type to sync.Mutex + // then it'll be harder to match embedded locks and custom methods + // that may forward the call to the sync.Mutex (or other synchronization primitive). + + m.Match(`$mu.Lock(); defer $mu.RUnlock()`).Report(`maybe $mu.RLock() was intended?`) + m.Match(`$mu.RLock(); defer $mu.Unlock()`).Report(`maybe $mu.Lock() was intended?`) +} diff --git a/tests/go_client/testcases/client_test.go b/tests/go_client/testcases/client_test.go index 5c203dfa7f25..7f7646260c50 100644 --- a/tests/go_client/testcases/client_test.go +++ b/tests/go_client/testcases/client_test.go @@ -7,11 +7,10 @@ import ( "testing" "time" - "github.com/milvus-io/milvus/tests/go_client/testcases/helper" - clientv2 "github.com/milvus-io/milvus/client/v2" "github.com/milvus-io/milvus/tests/go_client/base" "github.com/milvus-io/milvus/tests/go_client/common" + "github.com/milvus-io/milvus/tests/go_client/testcases/helper" ) // test connect and close, connect again @@ -56,7 +55,8 @@ func TestConnectInvalidAddr(t *testing.T) { // connect ctx := helper.CreateContext(t, time.Second*5) for _, invalidCfg := range genInvalidClientConfig() { - _, errConnect := base.NewMilvusClient(ctx, &invalidCfg) + cfg := invalidCfg + _, errConnect := base.NewMilvusClient(ctx, &cfg) common.CheckErr(t, errConnect, false, "context deadline exceeded") } } diff --git a/tests/go_client/testcases/collection_test.go b/tests/go_client/testcases/collection_test.go index 70211dbacdc1..c106cb28af4f 100644 --- a/tests/go_client/testcases/collection_test.go +++ b/tests/go_client/testcases/collection_test.go @@ -5,16 +5,14 @@ import ( "testing" "time" - hp "github.com/milvus-io/milvus/tests/go_client/testcases/helper" - "github.com/stretchr/testify/require" - - "github.com/milvus-io/milvus/pkg/log" "go.uber.org/zap" clientv2 "github.com/milvus-io/milvus/client/v2" "github.com/milvus-io/milvus/client/v2/entity" + "github.com/milvus-io/milvus/pkg/log" "github.com/milvus-io/milvus/tests/go_client/common" + hp "github.com/milvus-io/milvus/tests/go_client/testcases/helper" ) var prefix = "collection" @@ -42,7 +40,7 @@ func TestCreateCollection(t *testing.T) { } } -//func TestCreateCollection(t *testing.T) {} +// func TestCreateCollection(t *testing.T) {} func TestCreateAutoIdCollectionField(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) mc := createDefaultMilvusClient(ctx, t) @@ -229,6 +227,7 @@ func TestCreateCollectionPartitionKey(t *testing.T) { // verify partitions partitions, err := mc.ListPartitions(ctx, clientv2.NewListPartitionOption(collName)) require.Len(t, partitions, common.DefaultPartitionNum) + common.CheckErr(t, err, true) } } @@ -253,6 +252,7 @@ func TestCreateCollectionPartitionKeyNumPartition(t *testing.T) { // verify partitions num partitions, err := mc.ListPartitions(ctx, clientv2.NewListPartitionOption(collName)) require.Len(t, partitions, int(numPartition)) + common.CheckErr(t, err, true) } } @@ -275,6 +275,7 @@ func TestCreateCollectionDynamicSchema(t *testing.T) { require.True(t, has) coll, err := mc.DescribeCollection(ctx, clientv2.NewDescribeCollectionOption(schema.CollectionName)) + common.CheckErr(t, err, true) require.True(t, coll.Schema.EnableDynamicField) // insert dynamic @@ -307,7 +308,8 @@ func TestCreateCollectionDynamic(t *testing.T) { coll, err := mc.DescribeCollection(ctx, clientv2.NewDescribeCollectionOption(schema.CollectionName)) log.Info("collection dynamic", zap.Bool("collectionSchema", coll.Schema.EnableDynamicField)) - //require.True(t, coll.Schema.Fields[0].IsDynamic) + common.CheckErr(t, err, true) + // require.True(t, coll.Schema.Fields[0].IsDynamic) // insert dynamic columnOption := *hp.TNewDataOption() @@ -627,7 +629,6 @@ func TestPartitionKeyInvalidNumPartition(t *testing.T) { {-1, "the specified partitions should be greater than 0 if partition key is used"}, } for _, npStruct := range invalidNumPartitionStruct { - // create collection with num partitions err := mc.CreateCollection(ctx, clientv2.NewCreateCollectionOption(collName, schema)) common.CheckErr(t, err, false, npStruct.errMsg) @@ -910,7 +911,7 @@ func TestCreateMultiVectorExceed(t *testing.T) { common.CheckErr(t, err, false, fmt.Sprintf("maximum vector field's number should be limited to %d", common.MaxVectorFieldNum)) } -//func TestCreateCollection(t *testing.T) {} +// func TestCreateCollection(t *testing.T) {} func TestCreateCollectionInvalidShards(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) mc := createDefaultMilvusClient(ctx, t) @@ -938,7 +939,7 @@ func TestCreateCollectionInvalid(t *testing.T) { vecField := entity.NewField().WithName("vec").WithDataType(entity.FieldTypeFloatVector).WithDim(8) mSchemaErrs := []mSchemaErr{ {schema: nil, errMsg: "duplicated field name"}, - {schema: entity.NewSchema().WithField(vecField), errMsg: "collection name should not be empty"}, // no collection name + {schema: entity.NewSchema().WithField(vecField), errMsg: "collection name should not be empty"}, // no collection name {schema: entity.NewSchema().WithName("aaa").WithField(vecField), errMsg: "primary key is not specified"}, // no pk field {schema: entity.NewSchema().WithName("aaa").WithField(vecField).WithField(entity.NewField()), errMsg: "primary key is not specified"}, {schema: entity.NewSchema().WithName("aaa").WithField(vecField).WithField(entity.NewField().WithIsPrimaryKey(true)), errMsg: "the data type of primary key should be Int64 or VarChar"}, diff --git a/tests/go_client/testcases/delete_test.go b/tests/go_client/testcases/delete_test.go index ab2bb0f61801..056c16b2d022 100644 --- a/tests/go_client/testcases/delete_test.go +++ b/tests/go_client/testcases/delete_test.go @@ -5,14 +5,14 @@ import ( "testing" "time" - "github.com/milvus-io/milvus/pkg/log" + "github.com/stretchr/testify/require" "go.uber.org/zap" clientv2 "github.com/milvus-io/milvus/client/v2" "github.com/milvus-io/milvus/client/v2/entity" + "github.com/milvus-io/milvus/pkg/log" "github.com/milvus-io/milvus/tests/go_client/common" hp "github.com/milvus-io/milvus/tests/go_client/testcases/helper" - "github.com/stretchr/testify/require" ) func TestDelete(t *testing.T) { @@ -408,6 +408,7 @@ func TestDeletePartitionName(t *testing.T) { // query and verify resQuery, err := mc.Query(ctx, clientv2.NewQueryOption(schema.CollectionName).WithFilter(exprQuery).WithOutputFields([]string{common.QueryCountFieldName}). WithConsistencyLevel(entity.ClStrong)) + common.CheckErr(t, err, true) count, _ := resQuery.Fields[0].GetAsInt64(0) require.Equal(t, int64(common.DefaultNb*2), count) @@ -443,7 +444,7 @@ func TestDeleteComplexExpr(t *testing.T) { exprLimits := []exprCount{ {expr: fmt.Sprintf("%s >= 1000 || %s > 2000", common.DefaultInt64FieldName, common.DefaultInt64FieldName), count: 2000}, - //json and dynamic field filter expr: == < in bool/ list/ int + // json and dynamic field filter expr: == < in bool/ list/ int {expr: fmt.Sprintf("%s['number'] < 100 and %s['number'] != 0", common.DefaultJSONFieldName, common.DefaultJSONFieldName), count: 50}, {expr: fmt.Sprintf("%s < 100", common.DefaultDynamicNumberField), count: 100}, {expr: fmt.Sprintf("%s == false", common.DefaultDynamicBoolField), count: 2000}, @@ -496,7 +497,7 @@ func TestDeleteComplexExpr(t *testing.T) { resDe, err := mc.Delete(ctx, clientv2.NewDeleteOption(schema.CollectionName).WithExpr(exprLimit.expr)) common.CheckErr(t, err, true) log.Debug("delete count", zap.Bool("equal", int64(exprLimit.count) == resDe.DeleteCount)) - //require.Equal(t, int64(exprLimit.count), resDe.DeleteCount) + // require.Equal(t, int64(exprLimit.count), resDe.DeleteCount) resQuery, err := mc.Query(ctx, clientv2.NewQueryOption(schema.CollectionName).WithFilter(exprLimit.expr).WithConsistencyLevel(entity.ClStrong)) common.CheckErr(t, err, true) @@ -555,4 +556,3 @@ func TestDeleteDuplicatedPks(t *testing.T) { common.CheckErr(t, errQuery, true) require.Equal(t, common.DefaultNb-1, resQuery.ResultCount) } - diff --git a/tests/go_client/testcases/helper/data_helper.go b/tests/go_client/testcases/helper/data_helper.go index 160bba153b0c..06397d3fb50b 100644 --- a/tests/go_client/testcases/helper/data_helper.go +++ b/tests/go_client/testcases/helper/data_helper.go @@ -5,11 +5,12 @@ import ( "encoding/json" "strconv" + "go.uber.org/zap" + "github.com/milvus-io/milvus/client/v2/column" "github.com/milvus-io/milvus/client/v2/entity" "github.com/milvus-io/milvus/pkg/log" "github.com/milvus-io/milvus/tests/go_client/common" - "go.uber.org/zap" ) // insert params diff --git a/tests/go_client/testcases/helper/field_helper.go b/tests/go_client/testcases/helper/field_helper.go index 926c8fc00849..07ecc0163506 100644 --- a/tests/go_client/testcases/helper/field_helper.go +++ b/tests/go_client/testcases/helper/field_helper.go @@ -1,10 +1,11 @@ package helper import ( + "go.uber.org/zap" + "github.com/milvus-io/milvus/client/v2/entity" "github.com/milvus-io/milvus/pkg/log" "github.com/milvus-io/milvus/tests/go_client/common" - "go.uber.org/zap" ) type GetFieldNameOpt func(opt *getFieldNameOpt) @@ -73,7 +74,7 @@ func GetFieldNameByFieldType(t entity.FieldType, opts ...GetFieldNameOpt) string case entity.FieldTypeVarChar: return common.DefaultVarcharFieldName case entity.FieldTypeJSON: - if opt.isDynamic{ + if opt.isDynamic { return common.DefaultDynamicFieldName } return common.DefaultJSONFieldName @@ -288,7 +289,6 @@ func (cf FieldsAllFields) GenFields(option GenFieldsOption) []*entity.Field { scalarField := entity.NewField().WithName(GetFieldNameByFieldType(fieldType)).WithDataType(fieldType) fields = append(fields, scalarField) } - } for _, fieldType := range GetAllVectorFieldType() { if fieldType == entity.FieldTypeSparseVector { @@ -329,7 +329,6 @@ func (cf FieldsInt64VecAllScalar) GenFields(option GenFieldsOption) []*entity.Fi scalarField := entity.NewField().WithName(GetFieldNameByFieldType(fieldType)).WithDataType(fieldType) fields = append(fields, scalarField) } - } vecField := entity.NewField().WithName(GetFieldNameByFieldType(entity.FieldTypeFloatVector)).WithDataType(entity.FieldTypeFloatVector).WithDim(option.Dim) fields = append(fields, vecField) diff --git a/tests/go_client/testcases/helper/helper.go b/tests/go_client/testcases/helper/helper.go index 35fa8e387fb7..7ce8e6f09b02 100644 --- a/tests/go_client/testcases/helper/helper.go +++ b/tests/go_client/testcases/helper/helper.go @@ -5,13 +5,13 @@ import ( "testing" "time" + "go.uber.org/zap" + clientv2 "github.com/milvus-io/milvus/client/v2" + "github.com/milvus-io/milvus/client/v2/entity" "github.com/milvus-io/milvus/pkg/log" "github.com/milvus-io/milvus/tests/go_client/base" "github.com/milvus-io/milvus/tests/go_client/common" - "go.uber.org/zap" - - "github.com/milvus-io/milvus/client/v2/entity" ) func CreateContext(t *testing.T, timeout time.Duration) context.Context { @@ -22,8 +22,7 @@ func CreateContext(t *testing.T, timeout time.Duration) context.Context { return ctx } -//var ArrayFieldType = - +// var ArrayFieldType = func GetAllArrayElementType() []entity.FieldType { return []entity.FieldType{ entity.FieldTypeBool, @@ -68,7 +67,7 @@ func GetAllFieldsType() []entity.FieldType { entity.FieldTypeFloatVector, entity.FieldTypeFloat16Vector, entity.FieldTypeBFloat16Vector, - //entity.FieldTypeSparseVector, max vector fields num is 4 + // entity.FieldTypeSparseVector, max vector fields num is 4 ) return allFieldType } @@ -107,12 +106,14 @@ func GetInvalidPartitionKeyFieldType() []entity.FieldType { // ----------------- prepare data -------------------------- type CollectionPrepare struct{} -var CollPrepare CollectionPrepare -var FieldsFact FieldsFactory +var ( + CollPrepare CollectionPrepare + FieldsFact FieldsFactory +) func (chainTask *CollectionPrepare) CreateCollection(ctx context.Context, t *testing.T, mc *base.MilvusClient, - cp *CreateCollectionParams, fieldOpt *GenFieldsOption, schemaOpt *GenSchemaOption) (*CollectionPrepare, *entity.Schema) { - + cp *CreateCollectionParams, fieldOpt *GenFieldsOption, schemaOpt *GenSchemaOption, +) (*CollectionPrepare, *entity.Schema) { fields := FieldsFact.GenFieldsForCollection(cp.CollectionFieldsType, fieldOpt) schemaOpt.Fields = fields schema := GenSchema(schemaOpt) @@ -128,7 +129,8 @@ func (chainTask *CollectionPrepare) CreateCollection(ctx context.Context, t *tes } func (chainTask *CollectionPrepare) InsertData(ctx context.Context, t *testing.T, mc *base.MilvusClient, - ip *InsertParams, option *GenDataOption) (*CollectionPrepare, clientv2.InsertResult) { + ip *InsertParams, option *GenDataOption, +) (*CollectionPrepare, clientv2.InsertResult) { if nil == ip.Schema || ip.Schema.CollectionName == "" { log.Fatal("[InsertData] Nil Schema is not expected") } @@ -138,7 +140,7 @@ func (chainTask *CollectionPrepare) InsertData(ctx context.Context, t *testing.T if field.IsDynamic { insertOpt.WithColumns(GenDynamicColumnData(option.start, ip.Nb)...) } else { - if field.DataType == entity.FieldTypeArray{ + if field.DataType == entity.FieldTypeArray { option.TWithElementType(field.ElementType) } column := GenColumnData(ip.Nb, field.DataType, *option) diff --git a/tests/go_client/testcases/helper/index_helper.go b/tests/go_client/testcases/helper/index_helper.go index e69d4e5931a2..e18c3280a7a8 100644 --- a/tests/go_client/testcases/helper/index_helper.go +++ b/tests/go_client/testcases/helper/index_helper.go @@ -14,7 +14,7 @@ func GetDefaultVectorIndex(fieldType entity.FieldType) index.Index { return index.NewGenericIndex(common.DefaultBinaryVecFieldName, map[string]string{"nlist": "64", index.MetricTypeKey: "JACCARD", index.IndexTypeKey: "BIN_IVF_FLAT"}) // return binary index case entity.FieldTypeSparseVector: - return index.NewGenericIndex(common.DefaultSparseVecFieldName, map[string]string{"drop_ratio_build": "0.1", index.MetricTypeKey: "IP", index.IndexTypeKey: "SPARSE_INVERTED_INDEX"}) + return index.NewGenericIndex(common.DefaultSparseVecFieldName, map[string]string{"drop_ratio_build": "0.1", index.MetricTypeKey: "IP", index.IndexTypeKey: "SPARSE_INVERTED_INDEX"}) default: return nil // return auto index diff --git a/tests/go_client/testcases/helper/rows_helper.go b/tests/go_client/testcases/helper/rows_helper.go index 2e6534ee3997..275355ecba96 100644 --- a/tests/go_client/testcases/helper/rows_helper.go +++ b/tests/go_client/testcases/helper/rows_helper.go @@ -79,7 +79,7 @@ func GenDynamicRow(index int) Dynamic { return dynamic } -func GenJsonRow(index int) *JSONStruct { +func GenJSONRow(index int) *JSONStruct { var jsonStruct JSONStruct _bool := &BoolStruct{ Bool: index%2 == 0, @@ -130,7 +130,7 @@ func GenInt64VarcharSparseRows(nb int, enableDynamicField bool, autoID bool, opt // BaseRow generate insert rows for i := start; i < start+nb; i++ { vec := common.GenSparseVector(2) - //log.Info("", zap.Any("SparseVec", vec)) + // log.Info("", zap.Any("SparseVec", vec)) baseRow := BaseRow{ Varchar: strconv.Itoa(i + 1), SparseVec: vec, @@ -166,7 +166,7 @@ func GenAllFieldsRows(nb int, enableDynamicField bool, option GenDataOption) []i Float: float32(i + 1), Double: float64(i + 1), Varchar: strconv.Itoa(i + 1), - JSON: GenJsonRow(i + 1), + JSON: GenJSONRow(i + 1), FloatVec: common.GenFloatVector(dim), Fp16Vec: common.GenFloat16Vector(dim), Bf16Vec: common.GenBFloat16Vector(dim), diff --git a/tests/go_client/testcases/insert_test.go b/tests/go_client/testcases/insert_test.go index be44548a2c8d..e5d2921cd6c4 100644 --- a/tests/go_client/testcases/insert_test.go +++ b/tests/go_client/testcases/insert_test.go @@ -5,15 +5,14 @@ import ( "testing" "time" - "github.com/milvus-io/milvus/client/v2/index" - - "github.com/milvus-io/milvus/client/v2/column" - "github.com/milvus-io/milvus/pkg/log" "github.com/stretchr/testify/require" "go.uber.org/zap" clientv2 "github.com/milvus-io/milvus/client/v2" + "github.com/milvus-io/milvus/client/v2/column" "github.com/milvus-io/milvus/client/v2/entity" + "github.com/milvus-io/milvus/client/v2/index" + "github.com/milvus-io/milvus/pkg/log" "github.com/milvus-io/milvus/tests/go_client/common" hp "github.com/milvus-io/milvus/tests/go_client/testcases/helper" ) @@ -475,13 +474,13 @@ func TestInsertSparseVectorSamePosition(t *testing.T) { cp := hp.NewCreateCollectionParams(hp.Int64VarcharSparseVec) _, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) - //insert data column + // insert data column columnOpt := hp.TNewDataOption() data := []column.Column{ hp.GenColumnData(1, entity.FieldTypeInt64, *columnOpt), hp.GenColumnData(1, entity.FieldTypeVarChar, *columnOpt), } - //invalid sparse vector: position > (maximum of uint32 - 1) + // invalid sparse vector: position > (maximum of uint32 - 1) sparseVec, err := entity.NewSliceSparseEmbedding([]uint32{2, 10, 2}, []float32{0.4, 0.5, 0.6}) common.CheckErr(t, err, true) data = append(data, column.NewColumnSparseVectors(common.DefaultSparseVecFieldName, []entity.SparseEmbedding{sparseVec})) @@ -607,7 +606,7 @@ func TestInsertSparseRows(t *testing.T) { // BaseRow generate insert rows for i := 0; i < common.DefaultNb; i++ { vec := common.GenSparseVector(500) - //log.Info("", zap.Any("SparseVec", vec)) + // log.Info("", zap.Any("SparseVec", vec)) baseRow := hp.BaseRow{ Int64: int64(i + 1), SparseVec: vec, @@ -657,7 +656,7 @@ func TestInsertRowMismatchFields(t *testing.T) { cp := hp.NewCreateCollectionParams(hp.Int64Vec) _, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption().TWithDim(8), hp.TNewSchemaOption()) - //rows fields < schema fields + // rows fields < schema fields rowsLess := make([]interface{}, 0, 10) for i := 1; i < 11; i++ { row := hp.BaseRow{ diff --git a/tests/go_client/testcases/main_test.go b/tests/go_client/testcases/main_test.go index e9078c1cfad7..c3d2eb1b9752 100644 --- a/tests/go_client/testcases/main_test.go +++ b/tests/go_client/testcases/main_test.go @@ -10,14 +10,15 @@ import ( "go.uber.org/zap" clientv2 "github.com/milvus-io/milvus/client/v2" - "github.com/milvus-io/milvus/pkg/log" "github.com/milvus-io/milvus/tests/go_client/base" "github.com/milvus-io/milvus/tests/go_client/common" ) -var addr = flag.String("addr", "localhost:19530", "server host and port") -var defaultCfg clientv2.ClientConfig +var ( + addr = flag.String("addr", "localhost:19530", "server host and port") + defaultCfg clientv2.ClientConfig +) // teardown func teardown() { diff --git a/tests/go_client/testcases/search_test.go b/tests/go_client/testcases/search_test.go index 88951ee9d6ba..a190f35a0033 100644 --- a/tests/go_client/testcases/search_test.go +++ b/tests/go_client/testcases/search_test.go @@ -4,12 +4,13 @@ import ( "testing" "time" + "go.uber.org/zap" + clientv2 "github.com/milvus-io/milvus/client/v2" "github.com/milvus-io/milvus/client/v2/entity" "github.com/milvus-io/milvus/pkg/log" "github.com/milvus-io/milvus/tests/go_client/common" hp "github.com/milvus-io/milvus/tests/go_client/testcases/helper" - "go.uber.org/zap" ) func TestSearch(t *testing.T) { From 5a11bd53da3c1b655809728321af0e01b3c0dd4a Mon Sep 17 00:00:00 2001 From: Congqi Xia Date: Thu, 20 Jun 2024 20:58:40 +0800 Subject: [PATCH 2/2] fix dsl dep Signed-off-by: Congqi Xia --- tests/go_client/go.mod | 1 + tests/go_client/go.sum | 2 ++ 2 files changed, 3 insertions(+) diff --git a/tests/go_client/go.mod b/tests/go_client/go.mod index 2bd796fbaa08..ba8105116425 100644 --- a/tests/go_client/go.mod +++ b/tests/go_client/go.mod @@ -69,6 +69,7 @@ require ( github.com/prometheus/client_model v0.3.0 // indirect github.com/prometheus/common v0.42.0 // indirect github.com/prometheus/procfs v0.9.0 // indirect + github.com/quasilyte/go-ruleguard/dsl v0.3.22 // indirect github.com/rogpeppe/go-internal v1.10.0 // indirect github.com/samber/lo v1.27.0 // indirect github.com/shirou/gopsutil/v3 v3.22.9 // indirect diff --git a/tests/go_client/go.sum b/tests/go_client/go.sum index 818480c239f1..a9f92bb07dd1 100644 --- a/tests/go_client/go.sum +++ b/tests/go_client/go.sum @@ -490,6 +490,8 @@ github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1 github.com/prometheus/procfs v0.9.0 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJfhI= github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB/chUwxUZY= github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= +github.com/quasilyte/go-ruleguard/dsl v0.3.22 h1:wd8zkOhSNr+I+8Qeciml08ivDt1pSXe60+5DqOpCjPE= +github.com/quasilyte/go-ruleguard/dsl v0.3.22/go.mod h1:KeCP03KrjuSO0H1kTuZQCWlQPulDV6YMIXmpQss17rU= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=