Skip to content

Commit

Permalink
enhance: Add rules and fix for go_client e2e code style (milvus-io#34033
Browse files Browse the repository at this point in the history
)

See also milvus-io#31293

---------

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
  • Loading branch information
congqixia authored and yellow-shine committed Jul 2, 2024
1 parent 9b62675 commit 4c000f8
Show file tree
Hide file tree
Showing 21 changed files with 513 additions and 78 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions client/column/scalar_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions client/column/vector_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions tests/go_client/.golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
include:
- "../../.golangci.yml"

linters-settings:
gocritic:
enabled-checks:
- ruleguard
settings:
ruleguard:
failOnError: true
rules: "ruleguard/rules.go"
10 changes: 4 additions & 6 deletions tests/go_client/base/milvus_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions tests/go_client/common/response_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
}))
}
}

Expand Down
21 changes: 12 additions & 9 deletions tests/go_client/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down Expand Up @@ -70,15 +73,15 @@ 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
}

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)
}
Expand All @@ -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
Expand Down Expand Up @@ -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] >
}
{Expr: fmt.Sprintf("%s[-1] > 1", DefaultJSONFieldName), ErrNil: false, ErrMsg: "invalid expression"}, // json[-1] >
}
1 change: 1 addition & 0 deletions tests/go_client/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/go_client/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
Loading

0 comments on commit 4c000f8

Please sign in to comment.