mirror of
https://gitee.com/milvus-io/milvus.git
synced 2025-12-07 09:38:39 +08:00
enhance: Add rules and fix for go_client e2e code style (#34033)
See also #31293 --------- Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
This commit is contained in:
parent
4e414fb7fc
commit
35ea775c14
6
Makefile
6
Makefile
@ -144,6 +144,7 @@ lint-fix: getdeps
|
|||||||
@$(INSTALL_PATH)/gofumpt -l -w cmd/
|
@$(INSTALL_PATH)/gofumpt -l -w cmd/
|
||||||
@$(INSTALL_PATH)/gofumpt -l -w pkg/
|
@$(INSTALL_PATH)/gofumpt -l -w pkg/
|
||||||
@$(INSTALL_PATH)/gofumpt -l -w client/
|
@$(INSTALL_PATH)/gofumpt -l -w client/
|
||||||
|
@$(INSTALL_PATH)/gofumpt -l -w tests/go_client/
|
||||||
@$(INSTALL_PATH)/gofumpt -l -w tests/integration/
|
@$(INSTALL_PATH)/gofumpt -l -w tests/integration/
|
||||||
@echo "Running gci fix"
|
@echo "Running gci fix"
|
||||||
@$(INSTALL_PATH)/gci write cmd/ --skip-generated -s standard -s default -s "prefix(github.com/milvus-io)" --custom-order
|
@$(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
|
#TODO: Check code specifications by golangci-lint
|
||||||
static-check: getdeps
|
static-check: getdeps
|
||||||
@echo "Running $@ check"
|
@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
|
@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
|
@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
|
@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
|
verifiers: build-cpp getdeps cppcheck fmt static-check
|
||||||
|
|
||||||
|
|||||||
11
tests/go_client/.golangci.yml
Normal file
11
tests/go_client/.golangci.yml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
include:
|
||||||
|
- "../../.golangci.yml"
|
||||||
|
|
||||||
|
linters-settings:
|
||||||
|
gocritic:
|
||||||
|
enabled-checks:
|
||||||
|
- ruleguard
|
||||||
|
settings:
|
||||||
|
ruleguard:
|
||||||
|
failOnError: true
|
||||||
|
rules: "ruleguard/rules.go"
|
||||||
@ -6,15 +6,13 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/milvus-io/milvus/client/v2/entity"
|
|
||||||
"github.com/milvus-io/milvus/pkg/log"
|
|
||||||
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
|
||||||
clientv2 "github.com/milvus-io/milvus/client/v2"
|
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/client/v2/index"
|
||||||
|
"github.com/milvus-io/milvus/pkg/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func LoggingUnaryInterceptor() grpc.UnaryClientInterceptor {
|
func LoggingUnaryInterceptor() grpc.UnaryClientInterceptor {
|
||||||
|
|||||||
@ -5,14 +5,13 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/milvus-io/milvus/client/v2/column"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/milvus-io/milvus/client/v2/entity"
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
|
||||||
"github.com/milvus-io/milvus/pkg/log"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
|
|
||||||
clientv2 "github.com/milvus-io/milvus/client/v2"
|
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) {
|
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:
|
case entity.FieldTypeArray:
|
||||||
log.Info("TODO support column element type")
|
log.Info("TODO support column element type")
|
||||||
default:
|
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.FieldTypeInt8, entity.FieldTypeInt16, entity.FieldTypeInt32, entity.FieldTypeInt64,
|
||||||
entity.FieldTypeFloat, entity.FieldTypeDouble, entity.FieldTypeString, entity.FieldTypeVarChar,
|
entity.FieldTypeFloat, entity.FieldTypeDouble, entity.FieldTypeString, entity.FieldTypeVarChar,
|
||||||
entity.FieldTypeArray, entity.FieldTypeFloatVector, entity.FieldTypeBinaryVector}))
|
entity.FieldTypeArray, entity.FieldTypeFloatVector, entity.FieldTypeBinaryVector,
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -8,14 +8,17 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/milvus-io/milvus/client/v2/entity"
|
|
||||||
"github.com/milvus-io/milvus/pkg/log"
|
|
||||||
"github.com/x448/float16"
|
"github.com/x448/float16"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
|
||||||
|
"github.com/milvus-io/milvus/client/v2/entity"
|
||||||
|
"github.com/milvus-io/milvus/pkg/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
var (
|
||||||
var r *rand.Rand
|
letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||||
|
r *rand.Rand
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
r = rand.New(rand.NewSource(time.Now().UnixNano()))
|
r = rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||||
@ -70,7 +73,7 @@ func GenInvalidNames() []string {
|
|||||||
|
|
||||||
func GenFloatVector(dim int) []float32 {
|
func GenFloatVector(dim int) []float32 {
|
||||||
vector := make([]float32, 0, dim)
|
vector := make([]float32, 0, dim)
|
||||||
for j := 0; j < int(dim); j++ {
|
for j := 0; j < dim; j++ {
|
||||||
vector = append(vector, rand.Float32())
|
vector = append(vector, rand.Float32())
|
||||||
}
|
}
|
||||||
return vector
|
return vector
|
||||||
@ -78,7 +81,7 @@ func GenFloatVector(dim int) []float32 {
|
|||||||
|
|
||||||
func GenFloat16Vector(dim int) []byte {
|
func GenFloat16Vector(dim int) []byte {
|
||||||
ret := make([]byte, dim*2)
|
ret := make([]byte, dim*2)
|
||||||
for i := 0; i < int(dim); i++ {
|
for i := 0; i < dim; i++ {
|
||||||
v := float16.Fromfloat32(rand.Float32()).Bits()
|
v := float16.Fromfloat32(rand.Float32()).Bits()
|
||||||
binary.LittleEndian.PutUint16(ret[i*2:], v)
|
binary.LittleEndian.PutUint16(ret[i*2:], v)
|
||||||
}
|
}
|
||||||
@ -87,7 +90,7 @@ func GenFloat16Vector(dim int) []byte {
|
|||||||
|
|
||||||
func GenBFloat16Vector(dim int) []byte {
|
func GenBFloat16Vector(dim int) []byte {
|
||||||
ret16 := make([]uint16, 0, dim)
|
ret16 := make([]uint16, 0, dim)
|
||||||
for i := 0; i < int(dim); i++ {
|
for i := 0; i < dim; i++ {
|
||||||
f := rand.Float32()
|
f := rand.Float32()
|
||||||
bits := math.Float32bits(f)
|
bits := math.Float32bits(f)
|
||||||
bits >>= 16
|
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("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("%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] >
|
{Expr: fmt.Sprintf("%s[-1] > 1", DefaultJSONFieldName), ErrNil: false, ErrMsg: "invalid expression"}, // json[-1] >
|
||||||
}
|
}
|
||||||
@ -69,6 +69,7 @@ require (
|
|||||||
github.com/prometheus/client_model v0.3.0 // indirect
|
github.com/prometheus/client_model v0.3.0 // indirect
|
||||||
github.com/prometheus/common v0.42.0 // indirect
|
github.com/prometheus/common v0.42.0 // indirect
|
||||||
github.com/prometheus/procfs v0.9.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/rogpeppe/go-internal v1.10.0 // indirect
|
||||||
github.com/samber/lo v1.27.0 // indirect
|
github.com/samber/lo v1.27.0 // indirect
|
||||||
github.com/shirou/gopsutil/v3 v3.22.9 // indirect
|
github.com/shirou/gopsutil/v3 v3.22.9 // indirect
|
||||||
|
|||||||
@ -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 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJfhI=
|
||||||
github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB/chUwxUZY=
|
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/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 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/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
|
||||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||||
|
|||||||
409
tests/go_client/ruleguard/rules.go
Normal file
409
tests/go_client/ruleguard/rules.go
Normal file
@ -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?`)
|
||||||
|
}
|
||||||
@ -7,11 +7,10 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/milvus-io/milvus/tests/go_client/testcases/helper"
|
|
||||||
|
|
||||||
clientv2 "github.com/milvus-io/milvus/client/v2"
|
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/base"
|
||||||
"github.com/milvus-io/milvus/tests/go_client/common"
|
"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
|
// test connect and close, connect again
|
||||||
@ -56,7 +55,8 @@ func TestConnectInvalidAddr(t *testing.T) {
|
|||||||
// connect
|
// connect
|
||||||
ctx := helper.CreateContext(t, time.Second*5)
|
ctx := helper.CreateContext(t, time.Second*5)
|
||||||
for _, invalidCfg := range genInvalidClientConfig() {
|
for _, invalidCfg := range genInvalidClientConfig() {
|
||||||
_, errConnect := base.NewMilvusClient(ctx, &invalidCfg)
|
cfg := invalidCfg
|
||||||
|
_, errConnect := base.NewMilvusClient(ctx, &cfg)
|
||||||
common.CheckErr(t, errConnect, false, "context deadline exceeded")
|
common.CheckErr(t, errConnect, false, "context deadline exceeded")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,16 +5,14 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
hp "github.com/milvus-io/milvus/tests/go_client/testcases/helper"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/milvus-io/milvus/pkg/log"
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
|
||||||
clientv2 "github.com/milvus-io/milvus/client/v2"
|
clientv2 "github.com/milvus-io/milvus/client/v2"
|
||||||
"github.com/milvus-io/milvus/client/v2/entity"
|
"github.com/milvus-io/milvus/client/v2/entity"
|
||||||
|
"github.com/milvus-io/milvus/pkg/log"
|
||||||
"github.com/milvus-io/milvus/tests/go_client/common"
|
"github.com/milvus-io/milvus/tests/go_client/common"
|
||||||
|
hp "github.com/milvus-io/milvus/tests/go_client/testcases/helper"
|
||||||
)
|
)
|
||||||
|
|
||||||
var prefix = "collection"
|
var prefix = "collection"
|
||||||
@ -229,6 +227,7 @@ func TestCreateCollectionPartitionKey(t *testing.T) {
|
|||||||
// verify partitions
|
// verify partitions
|
||||||
partitions, err := mc.ListPartitions(ctx, clientv2.NewListPartitionOption(collName))
|
partitions, err := mc.ListPartitions(ctx, clientv2.NewListPartitionOption(collName))
|
||||||
require.Len(t, partitions, common.DefaultPartitionNum)
|
require.Len(t, partitions, common.DefaultPartitionNum)
|
||||||
|
common.CheckErr(t, err, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,6 +252,7 @@ func TestCreateCollectionPartitionKeyNumPartition(t *testing.T) {
|
|||||||
// verify partitions num
|
// verify partitions num
|
||||||
partitions, err := mc.ListPartitions(ctx, clientv2.NewListPartitionOption(collName))
|
partitions, err := mc.ListPartitions(ctx, clientv2.NewListPartitionOption(collName))
|
||||||
require.Len(t, partitions, int(numPartition))
|
require.Len(t, partitions, int(numPartition))
|
||||||
|
common.CheckErr(t, err, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,6 +275,7 @@ func TestCreateCollectionDynamicSchema(t *testing.T) {
|
|||||||
require.True(t, has)
|
require.True(t, has)
|
||||||
|
|
||||||
coll, err := mc.DescribeCollection(ctx, clientv2.NewDescribeCollectionOption(schema.CollectionName))
|
coll, err := mc.DescribeCollection(ctx, clientv2.NewDescribeCollectionOption(schema.CollectionName))
|
||||||
|
common.CheckErr(t, err, true)
|
||||||
require.True(t, coll.Schema.EnableDynamicField)
|
require.True(t, coll.Schema.EnableDynamicField)
|
||||||
|
|
||||||
// insert dynamic
|
// insert dynamic
|
||||||
@ -307,6 +308,7 @@ func TestCreateCollectionDynamic(t *testing.T) {
|
|||||||
|
|
||||||
coll, err := mc.DescribeCollection(ctx, clientv2.NewDescribeCollectionOption(schema.CollectionName))
|
coll, err := mc.DescribeCollection(ctx, clientv2.NewDescribeCollectionOption(schema.CollectionName))
|
||||||
log.Info("collection dynamic", zap.Bool("collectionSchema", coll.Schema.EnableDynamicField))
|
log.Info("collection dynamic", zap.Bool("collectionSchema", coll.Schema.EnableDynamicField))
|
||||||
|
common.CheckErr(t, err, true)
|
||||||
// require.True(t, coll.Schema.Fields[0].IsDynamic)
|
// require.True(t, coll.Schema.Fields[0].IsDynamic)
|
||||||
|
|
||||||
// insert dynamic
|
// insert dynamic
|
||||||
@ -627,7 +629,6 @@ func TestPartitionKeyInvalidNumPartition(t *testing.T) {
|
|||||||
{-1, "the specified partitions should be greater than 0 if partition key is used"},
|
{-1, "the specified partitions should be greater than 0 if partition key is used"},
|
||||||
}
|
}
|
||||||
for _, npStruct := range invalidNumPartitionStruct {
|
for _, npStruct := range invalidNumPartitionStruct {
|
||||||
|
|
||||||
// create collection with num partitions
|
// create collection with num partitions
|
||||||
err := mc.CreateCollection(ctx, clientv2.NewCreateCollectionOption(collName, schema))
|
err := mc.CreateCollection(ctx, clientv2.NewCreateCollectionOption(collName, schema))
|
||||||
common.CheckErr(t, err, false, npStruct.errMsg)
|
common.CheckErr(t, err, false, npStruct.errMsg)
|
||||||
|
|||||||
@ -5,14 +5,14 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/milvus-io/milvus/pkg/log"
|
"github.com/stretchr/testify/require"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
|
||||||
clientv2 "github.com/milvus-io/milvus/client/v2"
|
clientv2 "github.com/milvus-io/milvus/client/v2"
|
||||||
"github.com/milvus-io/milvus/client/v2/entity"
|
"github.com/milvus-io/milvus/client/v2/entity"
|
||||||
|
"github.com/milvus-io/milvus/pkg/log"
|
||||||
"github.com/milvus-io/milvus/tests/go_client/common"
|
"github.com/milvus-io/milvus/tests/go_client/common"
|
||||||
hp "github.com/milvus-io/milvus/tests/go_client/testcases/helper"
|
hp "github.com/milvus-io/milvus/tests/go_client/testcases/helper"
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDelete(t *testing.T) {
|
func TestDelete(t *testing.T) {
|
||||||
@ -408,6 +408,7 @@ func TestDeletePartitionName(t *testing.T) {
|
|||||||
// query and verify
|
// query and verify
|
||||||
resQuery, err := mc.Query(ctx, clientv2.NewQueryOption(schema.CollectionName).WithFilter(exprQuery).WithOutputFields([]string{common.QueryCountFieldName}).
|
resQuery, err := mc.Query(ctx, clientv2.NewQueryOption(schema.CollectionName).WithFilter(exprQuery).WithOutputFields([]string{common.QueryCountFieldName}).
|
||||||
WithConsistencyLevel(entity.ClStrong))
|
WithConsistencyLevel(entity.ClStrong))
|
||||||
|
common.CheckErr(t, err, true)
|
||||||
count, _ := resQuery.Fields[0].GetAsInt64(0)
|
count, _ := resQuery.Fields[0].GetAsInt64(0)
|
||||||
require.Equal(t, int64(common.DefaultNb*2), count)
|
require.Equal(t, int64(common.DefaultNb*2), count)
|
||||||
|
|
||||||
@ -555,4 +556,3 @@ func TestDeleteDuplicatedPks(t *testing.T) {
|
|||||||
common.CheckErr(t, errQuery, true)
|
common.CheckErr(t, errQuery, true)
|
||||||
require.Equal(t, common.DefaultNb-1, resQuery.ResultCount)
|
require.Equal(t, common.DefaultNb-1, resQuery.ResultCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,11 +5,12 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"go.uber.org/zap"
|
||||||
|
|
||||||
"github.com/milvus-io/milvus/client/v2/column"
|
"github.com/milvus-io/milvus/client/v2/column"
|
||||||
"github.com/milvus-io/milvus/client/v2/entity"
|
"github.com/milvus-io/milvus/client/v2/entity"
|
||||||
"github.com/milvus-io/milvus/pkg/log"
|
"github.com/milvus-io/milvus/pkg/log"
|
||||||
"github.com/milvus-io/milvus/tests/go_client/common"
|
"github.com/milvus-io/milvus/tests/go_client/common"
|
||||||
"go.uber.org/zap"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// insert params
|
// insert params
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
package helper
|
package helper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"go.uber.org/zap"
|
||||||
|
|
||||||
"github.com/milvus-io/milvus/client/v2/entity"
|
"github.com/milvus-io/milvus/client/v2/entity"
|
||||||
"github.com/milvus-io/milvus/pkg/log"
|
"github.com/milvus-io/milvus/pkg/log"
|
||||||
"github.com/milvus-io/milvus/tests/go_client/common"
|
"github.com/milvus-io/milvus/tests/go_client/common"
|
||||||
"go.uber.org/zap"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type GetFieldNameOpt func(opt *getFieldNameOpt)
|
type GetFieldNameOpt func(opt *getFieldNameOpt)
|
||||||
@ -288,7 +289,6 @@ func (cf FieldsAllFields) GenFields(option GenFieldsOption) []*entity.Field {
|
|||||||
scalarField := entity.NewField().WithName(GetFieldNameByFieldType(fieldType)).WithDataType(fieldType)
|
scalarField := entity.NewField().WithName(GetFieldNameByFieldType(fieldType)).WithDataType(fieldType)
|
||||||
fields = append(fields, scalarField)
|
fields = append(fields, scalarField)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
for _, fieldType := range GetAllVectorFieldType() {
|
for _, fieldType := range GetAllVectorFieldType() {
|
||||||
if fieldType == entity.FieldTypeSparseVector {
|
if fieldType == entity.FieldTypeSparseVector {
|
||||||
@ -329,7 +329,6 @@ func (cf FieldsInt64VecAllScalar) GenFields(option GenFieldsOption) []*entity.Fi
|
|||||||
scalarField := entity.NewField().WithName(GetFieldNameByFieldType(fieldType)).WithDataType(fieldType)
|
scalarField := entity.NewField().WithName(GetFieldNameByFieldType(fieldType)).WithDataType(fieldType)
|
||||||
fields = append(fields, scalarField)
|
fields = append(fields, scalarField)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
vecField := entity.NewField().WithName(GetFieldNameByFieldType(entity.FieldTypeFloatVector)).WithDataType(entity.FieldTypeFloatVector).WithDim(option.Dim)
|
vecField := entity.NewField().WithName(GetFieldNameByFieldType(entity.FieldTypeFloatVector)).WithDataType(entity.FieldTypeFloatVector).WithDim(option.Dim)
|
||||||
fields = append(fields, vecField)
|
fields = append(fields, vecField)
|
||||||
|
|||||||
@ -5,13 +5,13 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"go.uber.org/zap"
|
||||||
|
|
||||||
clientv2 "github.com/milvus-io/milvus/client/v2"
|
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/pkg/log"
|
||||||
"github.com/milvus-io/milvus/tests/go_client/base"
|
"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/common"
|
||||||
"go.uber.org/zap"
|
|
||||||
|
|
||||||
"github.com/milvus-io/milvus/client/v2/entity"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func CreateContext(t *testing.T, timeout time.Duration) context.Context {
|
func CreateContext(t *testing.T, timeout time.Duration) context.Context {
|
||||||
@ -23,7 +23,6 @@ func CreateContext(t *testing.T, timeout time.Duration) context.Context {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// var ArrayFieldType =
|
// var ArrayFieldType =
|
||||||
|
|
||||||
func GetAllArrayElementType() []entity.FieldType {
|
func GetAllArrayElementType() []entity.FieldType {
|
||||||
return []entity.FieldType{
|
return []entity.FieldType{
|
||||||
entity.FieldTypeBool,
|
entity.FieldTypeBool,
|
||||||
@ -107,12 +106,14 @@ func GetInvalidPartitionKeyFieldType() []entity.FieldType {
|
|||||||
// ----------------- prepare data --------------------------
|
// ----------------- prepare data --------------------------
|
||||||
type CollectionPrepare struct{}
|
type CollectionPrepare struct{}
|
||||||
|
|
||||||
var CollPrepare CollectionPrepare
|
var (
|
||||||
var FieldsFact FieldsFactory
|
CollPrepare CollectionPrepare
|
||||||
|
FieldsFact FieldsFactory
|
||||||
|
)
|
||||||
|
|
||||||
func (chainTask *CollectionPrepare) CreateCollection(ctx context.Context, t *testing.T, mc *base.MilvusClient,
|
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)
|
fields := FieldsFact.GenFieldsForCollection(cp.CollectionFieldsType, fieldOpt)
|
||||||
schemaOpt.Fields = fields
|
schemaOpt.Fields = fields
|
||||||
schema := GenSchema(schemaOpt)
|
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,
|
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 == "" {
|
if nil == ip.Schema || ip.Schema.CollectionName == "" {
|
||||||
log.Fatal("[InsertData] Nil Schema is not expected")
|
log.Fatal("[InsertData] Nil Schema is not expected")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -79,7 +79,7 @@ func GenDynamicRow(index int) Dynamic {
|
|||||||
return dynamic
|
return dynamic
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenJsonRow(index int) *JSONStruct {
|
func GenJSONRow(index int) *JSONStruct {
|
||||||
var jsonStruct JSONStruct
|
var jsonStruct JSONStruct
|
||||||
_bool := &BoolStruct{
|
_bool := &BoolStruct{
|
||||||
Bool: index%2 == 0,
|
Bool: index%2 == 0,
|
||||||
@ -166,7 +166,7 @@ func GenAllFieldsRows(nb int, enableDynamicField bool, option GenDataOption) []i
|
|||||||
Float: float32(i + 1),
|
Float: float32(i + 1),
|
||||||
Double: float64(i + 1),
|
Double: float64(i + 1),
|
||||||
Varchar: strconv.Itoa(i + 1),
|
Varchar: strconv.Itoa(i + 1),
|
||||||
JSON: GenJsonRow(i + 1),
|
JSON: GenJSONRow(i + 1),
|
||||||
FloatVec: common.GenFloatVector(dim),
|
FloatVec: common.GenFloatVector(dim),
|
||||||
Fp16Vec: common.GenFloat16Vector(dim),
|
Fp16Vec: common.GenFloat16Vector(dim),
|
||||||
Bf16Vec: common.GenBFloat16Vector(dim),
|
Bf16Vec: common.GenBFloat16Vector(dim),
|
||||||
|
|||||||
@ -5,15 +5,14 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"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"
|
"github.com/stretchr/testify/require"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
|
||||||
clientv2 "github.com/milvus-io/milvus/client/v2"
|
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/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"
|
"github.com/milvus-io/milvus/tests/go_client/common"
|
||||||
hp "github.com/milvus-io/milvus/tests/go_client/testcases/helper"
|
hp "github.com/milvus-io/milvus/tests/go_client/testcases/helper"
|
||||||
)
|
)
|
||||||
|
|||||||
@ -10,14 +10,15 @@ import (
|
|||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
|
||||||
clientv2 "github.com/milvus-io/milvus/client/v2"
|
clientv2 "github.com/milvus-io/milvus/client/v2"
|
||||||
|
|
||||||
"github.com/milvus-io/milvus/pkg/log"
|
"github.com/milvus-io/milvus/pkg/log"
|
||||||
"github.com/milvus-io/milvus/tests/go_client/base"
|
"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/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
var addr = flag.String("addr", "localhost:19530", "server host and port")
|
var (
|
||||||
var defaultCfg clientv2.ClientConfig
|
addr = flag.String("addr", "localhost:19530", "server host and port")
|
||||||
|
defaultCfg clientv2.ClientConfig
|
||||||
|
)
|
||||||
|
|
||||||
// teardown
|
// teardown
|
||||||
func teardown() {
|
func teardown() {
|
||||||
|
|||||||
@ -4,12 +4,13 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"go.uber.org/zap"
|
||||||
|
|
||||||
clientv2 "github.com/milvus-io/milvus/client/v2"
|
clientv2 "github.com/milvus-io/milvus/client/v2"
|
||||||
"github.com/milvus-io/milvus/client/v2/entity"
|
"github.com/milvus-io/milvus/client/v2/entity"
|
||||||
"github.com/milvus-io/milvus/pkg/log"
|
"github.com/milvus-io/milvus/pkg/log"
|
||||||
"github.com/milvus-io/milvus/tests/go_client/common"
|
"github.com/milvus-io/milvus/tests/go_client/common"
|
||||||
hp "github.com/milvus-io/milvus/tests/go_client/testcases/helper"
|
hp "github.com/milvus-io/milvus/tests/go_client/testcases/helper"
|
||||||
"go.uber.org/zap"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSearch(t *testing.T) {
|
func TestSearch(t *testing.T) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user