From b048761da9a1b180ac9cf9cec00d3200042c3da8 Mon Sep 17 00:00:00 2001 From: kevindiu Date: Tue, 22 Nov 2022 10:29:45 +0900 Subject: [PATCH 1/4] remove test for test regeneration Signed-off-by: kevindiu --- pkg/manager/index/config/config_test.go | 103 -- .../index/handler/grpc/handler_test.go | 196 --- pkg/manager/index/handler/grpc/option_test.go | 141 --- .../index/handler/rest/handler_test.go | 287 ----- pkg/manager/index/handler/rest/option_test.go | 141 --- pkg/manager/index/router/option_test.go | 257 ---- pkg/manager/index/router/router_test.go | 100 -- pkg/manager/index/service/indexer_test.go | 1078 ---------------- pkg/manager/index/service/indexinfos_test.go | 1127 ----------------- pkg/manager/index/service/option_test.go | 1070 ---------------- pkg/manager/index/usecase/indexer_test.go | 623 --------- 11 files changed, 5123 deletions(-) delete mode 100644 pkg/manager/index/config/config_test.go delete mode 100644 pkg/manager/index/handler/grpc/handler_test.go delete mode 100644 pkg/manager/index/handler/grpc/option_test.go delete mode 100644 pkg/manager/index/handler/rest/handler_test.go delete mode 100644 pkg/manager/index/handler/rest/option_test.go delete mode 100644 pkg/manager/index/router/option_test.go delete mode 100644 pkg/manager/index/router/router_test.go delete mode 100644 pkg/manager/index/service/indexer_test.go delete mode 100644 pkg/manager/index/service/indexinfos_test.go delete mode 100644 pkg/manager/index/service/option_test.go delete mode 100644 pkg/manager/index/usecase/indexer_test.go diff --git a/pkg/manager/index/config/config_test.go b/pkg/manager/index/config/config_test.go deleted file mode 100644 index dec3921e4a..0000000000 --- a/pkg/manager/index/config/config_test.go +++ /dev/null @@ -1,103 +0,0 @@ -// -// Copyright (C) 2019-2022 vdaas.org vald team -// -// Licensed 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 -// -// https://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 setting stores all server application settings -package config - -import ( - "reflect" - "testing" - - "github.com/vdaas/vald/internal/errors" - "github.com/vdaas/vald/internal/test/goleak" -) - -func TestNewConfig(t *testing.T) { - type args struct { - path string - } - type want struct { - wantCfg *Data - err error - } - type test struct { - name string - args args - want want - checkFunc func(want, *Data, error) error - beforeFunc func(args) - afterFunc func(args) - } - defaultCheckFunc := func(w want, gotCfg *Data, err error) error { - if !errors.Is(err, w.err) { - return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) - } - if !reflect.DeepEqual(gotCfg, w.wantCfg) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", gotCfg, w.wantCfg) - } - return nil - } - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - path: "", - }, - want: want{}, - checkFunc: defaultCheckFunc, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - path: "", - }, - want: want{}, - checkFunc: defaultCheckFunc, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - checkFunc := test.checkFunc - if test.checkFunc == nil { - checkFunc = defaultCheckFunc - } - - gotCfg, err := NewConfig(test.args.path) - if err := checkFunc(test.want, gotCfg, err); err != nil { - tt.Errorf("error = %v", err) - } - }) - } -} diff --git a/pkg/manager/index/handler/grpc/handler_test.go b/pkg/manager/index/handler/grpc/handler_test.go deleted file mode 100644 index acaf71ec0b..0000000000 --- a/pkg/manager/index/handler/grpc/handler_test.go +++ /dev/null @@ -1,196 +0,0 @@ -// -// Copyright (C) 2019-2022 vdaas.org vald team -// -// Licensed 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 -// -// https://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 grpc provides grpc server logic -package grpc - -import ( - "context" - "reflect" - "testing" - - "github.com/vdaas/vald/apis/grpc/v1/manager/index" - "github.com/vdaas/vald/apis/grpc/v1/payload" - "github.com/vdaas/vald/internal/errors" - "github.com/vdaas/vald/internal/test/goleak" - "github.com/vdaas/vald/pkg/manager/index/service" -) - -func TestNew(t *testing.T) { - type args struct { - opts []Option - } - type want struct { - want index.IndexServer - } - type test struct { - name string - args args - want want - checkFunc func(want, index.IndexServer) error - beforeFunc func(args) - afterFunc func(args) - } - defaultCheckFunc := func(w want, got index.IndexServer) error { - if !reflect.DeepEqual(got, w.want) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) - } - return nil - } - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - opts: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - opts: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - checkFunc := test.checkFunc - if test.checkFunc == nil { - checkFunc = defaultCheckFunc - } - - got := New(test.args.opts...) - if err := checkFunc(test.want, got); err != nil { - tt.Errorf("error = %v", err) - } - }) - } -} - -func Test_server_IndexInfo(t *testing.T) { - type args struct { - ctx context.Context - in1 *payload.Empty - } - type fields struct { - indexer service.Indexer - } - type want struct { - wantRes *payload.Info_Index_Count - err error - } - type test struct { - name string - args args - fields fields - want want - checkFunc func(want, *payload.Info_Index_Count, error) error - beforeFunc func(args) - afterFunc func(args) - } - defaultCheckFunc := func(w want, gotRes *payload.Info_Index_Count, err error) error { - if !errors.Is(err, w.err) { - return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) - } - if !reflect.DeepEqual(gotRes, w.wantRes) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", gotRes, w.wantRes) - } - return nil - } - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - ctx: nil, - in1: nil, - }, - fields: fields { - indexer: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - ctx: nil, - in1: nil, - }, - fields: fields { - indexer: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - checkFunc := test.checkFunc - if test.checkFunc == nil { - checkFunc = defaultCheckFunc - } - s := &server{ - indexer: test.fields.indexer, - } - - gotRes, err := s.IndexInfo(test.args.ctx, test.args.in1) - if err := checkFunc(test.want, gotRes, err); err != nil { - tt.Errorf("error = %v", err) - } - }) - } -} diff --git a/pkg/manager/index/handler/grpc/option_test.go b/pkg/manager/index/handler/grpc/option_test.go deleted file mode 100644 index 0f341097e8..0000000000 --- a/pkg/manager/index/handler/grpc/option_test.go +++ /dev/null @@ -1,141 +0,0 @@ -// -// Copyright (C) 2019-2022 vdaas.org vald team -// -// Licensed 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 -// -// https://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 grpc provides grpc server logic -package grpc - -import ( - "testing" - - "github.com/vdaas/vald/internal/test/goleak" - "github.com/vdaas/vald/pkg/manager/index/service" -) - -func TestWithIndexer(t *testing.T) { - // Change interface type to the type of object you are testing - type T = interface{} - type args struct { - i service.Indexer - } - type want struct { - obj *T - // Uncomment this line if the option returns an error, otherwise delete it - // err error - } - type test struct { - name string - args args - want want - // Use the first line if the option returns an error. otherwise use the second line - // checkFunc func(want, *T, error) error - // checkFunc func(want, *T) error - beforeFunc func(args) - afterFunc func(args) - } - - // Uncomment this block if the option returns an error, otherwise delete it - /* - defaultCheckFunc := func(w want, obj *T, err error) error { - if !errors.Is(err, w.err) { - return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) - } - if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", obj, w.obj) - } - return nil - } - */ - - // Uncomment this block if the option do not returns an error, otherwise delete it - /* - defaultCheckFunc := func(w want, obj *T) error { - if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", obj, w.obj) - } - return nil - } - */ - - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - i: nil, - }, - want: want { - obj: new(T), - }, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - i: nil, - }, - want: want { - obj: new(T), - }, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - - // Uncomment this block if the option returns an error, otherwise delete it - /* - if test.checkFunc == nil { - test.checkFunc = defaultCheckFunc - } - - got := WithIndexer(test.args.i) - obj := new(T) - if err := checkFunc(test.want, obj, got(obj)); err != nil { - tt.Errorf("error = %v", err) - } - */ - - // Uncomment this block if the option do not return an error, otherwise delete it - /* - if test.checkFunc == nil { - test.checkFunc = defaultCheckFunc - } - got := WithIndexer(test.args.i) - obj := new(T) - got(obj) - if err := checkFunc(test.want, obj); err != nil { - tt.Errorf("error = %v", err) - } - */ - }) - } -} diff --git a/pkg/manager/index/handler/rest/handler_test.go b/pkg/manager/index/handler/rest/handler_test.go deleted file mode 100644 index 819a246df0..0000000000 --- a/pkg/manager/index/handler/rest/handler_test.go +++ /dev/null @@ -1,287 +0,0 @@ -// -// Copyright (C) 2019-2022 vdaas.org vald team -// -// Licensed 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 -// -// https://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 rest provides rest api logic -package rest - -import ( - "net/http" - "reflect" - "testing" - - "github.com/vdaas/vald/apis/grpc/v1/manager/index" - "github.com/vdaas/vald/internal/errors" - "github.com/vdaas/vald/internal/test/goleak" -) - -func TestNew(t *testing.T) { - type args struct { - opts []Option - } - type want struct { - want Handler - } - type test struct { - name string - args args - want want - checkFunc func(want, Handler) error - beforeFunc func(args) - afterFunc func(args) - } - defaultCheckFunc := func(w want, got Handler) error { - if !reflect.DeepEqual(got, w.want) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) - } - return nil - } - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - opts: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - opts: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - checkFunc := test.checkFunc - if test.checkFunc == nil { - checkFunc = defaultCheckFunc - } - - got := New(test.args.opts...) - if err := checkFunc(test.want, got); err != nil { - tt.Errorf("error = %v", err) - } - }) - } -} - -func Test_handler_Index(t *testing.T) { - type args struct { - w http.ResponseWriter - r *http.Request - } - type fields struct { - indexer index.IndexServer - } - type want struct { - want int - err error - } - type test struct { - name string - args args - fields fields - want want - checkFunc func(want, int, error) error - beforeFunc func(args) - afterFunc func(args) - } - defaultCheckFunc := func(w want, got int, err error) error { - if !errors.Is(err, w.err) { - return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) - } - if !reflect.DeepEqual(got, w.want) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) - } - return nil - } - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - w: nil, - r: nil, - }, - fields: fields { - indexer: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - w: nil, - r: nil, - }, - fields: fields { - indexer: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - checkFunc := test.checkFunc - if test.checkFunc == nil { - checkFunc = defaultCheckFunc - } - h := &handler{ - indexer: test.fields.indexer, - } - - got, err := h.Index(test.args.w, test.args.r) - if err := checkFunc(test.want, got, err); err != nil { - tt.Errorf("error = %v", err) - } - }) - } -} - -func Test_handler_IndexInfo(t *testing.T) { - type args struct { - w http.ResponseWriter - r *http.Request - } - type fields struct { - indexer index.IndexServer - } - type want struct { - wantCode int - err error - } - type test struct { - name string - args args - fields fields - want want - checkFunc func(want, int, error) error - beforeFunc func(args) - afterFunc func(args) - } - defaultCheckFunc := func(w want, gotCode int, err error) error { - if !errors.Is(err, w.err) { - return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) - } - if !reflect.DeepEqual(gotCode, w.wantCode) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", gotCode, w.wantCode) - } - return nil - } - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - w: nil, - r: nil, - }, - fields: fields { - indexer: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - w: nil, - r: nil, - }, - fields: fields { - indexer: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - checkFunc := test.checkFunc - if test.checkFunc == nil { - checkFunc = defaultCheckFunc - } - h := &handler{ - indexer: test.fields.indexer, - } - - gotCode, err := h.IndexInfo(test.args.w, test.args.r) - if err := checkFunc(test.want, gotCode, err); err != nil { - tt.Errorf("error = %v", err) - } - }) - } -} diff --git a/pkg/manager/index/handler/rest/option_test.go b/pkg/manager/index/handler/rest/option_test.go deleted file mode 100644 index 90f09f5983..0000000000 --- a/pkg/manager/index/handler/rest/option_test.go +++ /dev/null @@ -1,141 +0,0 @@ -// -// Copyright (C) 2019-2022 vdaas.org vald team -// -// Licensed 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 -// -// https://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 rest provides rest api logic -package rest - -import ( - "testing" - - "github.com/vdaas/vald/apis/grpc/v1/manager/index" - "github.com/vdaas/vald/internal/test/goleak" -) - -func TestWithIndexer(t *testing.T) { - // Change interface type to the type of object you are testing - type T = interface{} - type args struct { - i index.IndexServer - } - type want struct { - obj *T - // Uncomment this line if the option returns an error, otherwise delete it - // err error - } - type test struct { - name string - args args - want want - // Use the first line if the option returns an error. otherwise use the second line - // checkFunc func(want, *T, error) error - // checkFunc func(want, *T) error - beforeFunc func(args) - afterFunc func(args) - } - - // Uncomment this block if the option returns an error, otherwise delete it - /* - defaultCheckFunc := func(w want, obj *T, err error) error { - if !errors.Is(err, w.err) { - return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) - } - if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", obj, w.obj) - } - return nil - } - */ - - // Uncomment this block if the option do not returns an error, otherwise delete it - /* - defaultCheckFunc := func(w want, obj *T) error { - if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", obj, w.obj) - } - return nil - } - */ - - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - i: nil, - }, - want: want { - obj: new(T), - }, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - i: nil, - }, - want: want { - obj: new(T), - }, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - - // Uncomment this block if the option returns an error, otherwise delete it - /* - if test.checkFunc == nil { - test.checkFunc = defaultCheckFunc - } - - got := WithIndexer(test.args.i) - obj := new(T) - if err := checkFunc(test.want, obj, got(obj)); err != nil { - tt.Errorf("error = %v", err) - } - */ - - // Uncomment this block if the option do not return an error, otherwise delete it - /* - if test.checkFunc == nil { - test.checkFunc = defaultCheckFunc - } - got := WithIndexer(test.args.i) - obj := new(T) - got(obj) - if err := checkFunc(test.want, obj); err != nil { - tt.Errorf("error = %v", err) - } - */ - }) - } -} diff --git a/pkg/manager/index/router/option_test.go b/pkg/manager/index/router/option_test.go deleted file mode 100644 index 52d72d5b85..0000000000 --- a/pkg/manager/index/router/option_test.go +++ /dev/null @@ -1,257 +0,0 @@ -// -// Copyright (C) 2019-2022 vdaas.org vald team -// -// Licensed 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 -// -// https://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 router provides implementation of Go API for routing http Handler wrapped by rest.Func -package router - -import ( - "testing" - - "github.com/vdaas/vald/internal/test/goleak" - "github.com/vdaas/vald/pkg/manager/index/handler/rest" -) - -func TestWithHandler(t *testing.T) { - // Change interface type to the type of object you are testing - type T = interface{} - type args struct { - h rest.Handler - } - type want struct { - obj *T - // Uncomment this line if the option returns an error, otherwise delete it - // err error - } - type test struct { - name string - args args - want want - // Use the first line if the option returns an error. otherwise use the second line - // checkFunc func(want, *T, error) error - // checkFunc func(want, *T) error - beforeFunc func(args) - afterFunc func(args) - } - - // Uncomment this block if the option returns an error, otherwise delete it - /* - defaultCheckFunc := func(w want, obj *T, err error) error { - if !errors.Is(err, w.err) { - return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) - } - if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", obj, w.obj) - } - return nil - } - */ - - // Uncomment this block if the option do not returns an error, otherwise delete it - /* - defaultCheckFunc := func(w want, obj *T) error { - if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", obj, w.obj) - } - return nil - } - */ - - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - h: nil, - }, - want: want { - obj: new(T), - }, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - h: nil, - }, - want: want { - obj: new(T), - }, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - - // Uncomment this block if the option returns an error, otherwise delete it - /* - if test.checkFunc == nil { - test.checkFunc = defaultCheckFunc - } - - got := WithHandler(test.args.h) - obj := new(T) - if err := checkFunc(test.want, obj, got(obj)); err != nil { - tt.Errorf("error = %v", err) - } - */ - - // Uncomment this block if the option do not return an error, otherwise delete it - /* - if test.checkFunc == nil { - test.checkFunc = defaultCheckFunc - } - got := WithHandler(test.args.h) - obj := new(T) - got(obj) - if err := checkFunc(test.want, obj); err != nil { - tt.Errorf("error = %v", err) - } - */ - }) - } -} - -func TestWithTimeout(t *testing.T) { - // Change interface type to the type of object you are testing - type T = interface{} - type args struct { - timeout string - } - type want struct { - obj *T - // Uncomment this line if the option returns an error, otherwise delete it - // err error - } - type test struct { - name string - args args - want want - // Use the first line if the option returns an error. otherwise use the second line - // checkFunc func(want, *T, error) error - // checkFunc func(want, *T) error - beforeFunc func(args) - afterFunc func(args) - } - - // Uncomment this block if the option returns an error, otherwise delete it - /* - defaultCheckFunc := func(w want, obj *T, err error) error { - if !errors.Is(err, w.err) { - return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) - } - if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", obj, w.obj) - } - return nil - } - */ - - // Uncomment this block if the option do not returns an error, otherwise delete it - /* - defaultCheckFunc := func(w want, obj *T) error { - if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", obj, w.obj) - } - return nil - } - */ - - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - timeout: "", - }, - want: want { - obj: new(T), - }, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - timeout: "", - }, - want: want { - obj: new(T), - }, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - - // Uncomment this block if the option returns an error, otherwise delete it - /* - if test.checkFunc == nil { - test.checkFunc = defaultCheckFunc - } - - got := WithTimeout(test.args.timeout) - obj := new(T) - if err := checkFunc(test.want, obj, got(obj)); err != nil { - tt.Errorf("error = %v", err) - } - */ - - // Uncomment this block if the option do not return an error, otherwise delete it - /* - if test.checkFunc == nil { - test.checkFunc = defaultCheckFunc - } - got := WithTimeout(test.args.timeout) - obj := new(T) - got(obj) - if err := checkFunc(test.want, obj); err != nil { - tt.Errorf("error = %v", err) - } - */ - }) - } -} diff --git a/pkg/manager/index/router/router_test.go b/pkg/manager/index/router/router_test.go deleted file mode 100644 index b274161d1d..0000000000 --- a/pkg/manager/index/router/router_test.go +++ /dev/null @@ -1,100 +0,0 @@ -// -// Copyright (C) 2019-2022 vdaas.org vald team -// -// Licensed 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 -// -// https://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 router provides implementation of Go API for routing http Handler wrapped by rest.Func -package router - -import ( - "net/http" - "reflect" - "testing" - - "github.com/vdaas/vald/internal/errors" - "github.com/vdaas/vald/internal/test/goleak" -) - -func TestNew(t *testing.T) { - type args struct { - opts []Option - } - type want struct { - want http.Handler - } - type test struct { - name string - args args - want want - checkFunc func(want, http.Handler) error - beforeFunc func(args) - afterFunc func(args) - } - defaultCheckFunc := func(w want, got http.Handler) error { - if !reflect.DeepEqual(got, w.want) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) - } - return nil - } - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - opts: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - opts: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - checkFunc := test.checkFunc - if test.checkFunc == nil { - checkFunc = defaultCheckFunc - } - - got := New(test.args.opts...) - if err := checkFunc(test.want, got); err != nil { - tt.Errorf("error = %v", err) - } - }) - } -} diff --git a/pkg/manager/index/service/indexer_test.go b/pkg/manager/index/service/indexer_test.go deleted file mode 100644 index 86be1968c6..0000000000 --- a/pkg/manager/index/service/indexer_test.go +++ /dev/null @@ -1,1078 +0,0 @@ -// -// Copyright (C) 2019-2022 vdaas.org vald team -// -// Licensed 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 -// -// https://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 service -package service - -import ( - "context" - "reflect" - "sync" - "sync/atomic" - "testing" - "time" - - "github.com/vdaas/vald/internal/client/v1/client/discoverer" - "github.com/vdaas/vald/internal/errgroup" - "github.com/vdaas/vald/internal/errors" - "github.com/vdaas/vald/internal/test/goleak" -) - -func TestNew(t *testing.T) { - type args struct { - opts []Option - } - type want struct { - wantIdx Indexer - err error - } - type test struct { - name string - args args - want want - checkFunc func(want, Indexer, error) error - beforeFunc func(args) - afterFunc func(args) - } - defaultCheckFunc := func(w want, gotIdx Indexer, err error) error { - if !errors.Is(err, w.err) { - return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) - } - if !reflect.DeepEqual(gotIdx, w.wantIdx) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", gotIdx, w.wantIdx) - } - return nil - } - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - opts: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - opts: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - checkFunc := test.checkFunc - if test.checkFunc == nil { - checkFunc = defaultCheckFunc - } - - gotIdx, err := New(test.args.opts...) - if err := checkFunc(test.want, gotIdx, err); err != nil { - tt.Errorf("error = %v", err) - } - }) - } -} - -func Test_index_Start(t *testing.T) { - type args struct { - ctx context.Context - } - type fields struct { - client discoverer.Client - eg errgroup.Group - creationPoolSize uint32 - indexDuration time.Duration - indexDurationLimit time.Duration - saveIndexDurationLimit time.Duration - saveIndexWaitDuration time.Duration - saveIndexTargetAddrCh chan string - schMap sync.Map - concurrency int - indexInfos indexInfos - indexing atomic.Value - minUncommitted uint32 - uuidsCount uint32 - uncommittedUUIDsCount uint32 - } - type want struct { - want <-chan error - err error - } - type test struct { - name string - args args - fields fields - want want - checkFunc func(want, <-chan error, error) error - beforeFunc func(args) - afterFunc func(args) - } - defaultCheckFunc := func(w want, got <-chan error, err error) error { - if !errors.Is(err, w.err) { - return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) - } - if !reflect.DeepEqual(got, w.want) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) - } - return nil - } - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - ctx: nil, - }, - fields: fields { - client: nil, - eg: nil, - creationPoolSize: 0, - indexDuration: nil, - indexDurationLimit: nil, - saveIndexDurationLimit: nil, - saveIndexWaitDuration: nil, - saveIndexTargetAddrCh: nil, - schMap: sync.Map{}, - concurrency: 0, - indexInfos: indexInfos{}, - indexing: nil, - minUncommitted: 0, - uuidsCount: 0, - uncommittedUUIDsCount: 0, - }, - want: want{}, - checkFunc: defaultCheckFunc, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - ctx: nil, - }, - fields: fields { - client: nil, - eg: nil, - creationPoolSize: 0, - indexDuration: nil, - indexDurationLimit: nil, - saveIndexDurationLimit: nil, - saveIndexWaitDuration: nil, - saveIndexTargetAddrCh: nil, - schMap: sync.Map{}, - concurrency: 0, - indexInfos: indexInfos{}, - indexing: nil, - minUncommitted: 0, - uuidsCount: 0, - uncommittedUUIDsCount: 0, - }, - want: want{}, - checkFunc: defaultCheckFunc, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - checkFunc := test.checkFunc - if test.checkFunc == nil { - checkFunc = defaultCheckFunc - } - idx := &index{ - client: test.fields.client, - eg: test.fields.eg, - creationPoolSize: test.fields.creationPoolSize, - indexDuration: test.fields.indexDuration, - indexDurationLimit: test.fields.indexDurationLimit, - saveIndexDurationLimit: test.fields.saveIndexDurationLimit, - saveIndexWaitDuration: test.fields.saveIndexWaitDuration, - saveIndexTargetAddrCh: test.fields.saveIndexTargetAddrCh, - schMap: test.fields.schMap, - concurrency: test.fields.concurrency, - indexInfos: test.fields.indexInfos, - indexing: test.fields.indexing, - minUncommitted: test.fields.minUncommitted, - uuidsCount: test.fields.uuidsCount, - uncommittedUUIDsCount: test.fields.uncommittedUUIDsCount, - } - - got, err := idx.Start(test.args.ctx) - if err := checkFunc(test.want, got, err); err != nil { - tt.Errorf("error = %v", err) - } - }) - } -} - -func Test_index_execute(t *testing.T) { - type args struct { - ctx context.Context - enableLowIndexSkip bool - immediateSaving bool - } - type fields struct { - client discoverer.Client - eg errgroup.Group - creationPoolSize uint32 - indexDuration time.Duration - indexDurationLimit time.Duration - saveIndexDurationLimit time.Duration - saveIndexWaitDuration time.Duration - saveIndexTargetAddrCh chan string - schMap sync.Map - concurrency int - indexInfos indexInfos - indexing atomic.Value - minUncommitted uint32 - uuidsCount uint32 - uncommittedUUIDsCount uint32 - } - type want struct { - err error - } - type test struct { - name string - args args - fields fields - want want - checkFunc func(want, error) error - beforeFunc func(args) - afterFunc func(args) - } - defaultCheckFunc := func(w want, err error) error { - if !errors.Is(err, w.err) { - return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) - } - return nil - } - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - ctx: nil, - enableLowIndexSkip: false, - immediateSaving: false, - }, - fields: fields { - client: nil, - eg: nil, - creationPoolSize: 0, - indexDuration: nil, - indexDurationLimit: nil, - saveIndexDurationLimit: nil, - saveIndexWaitDuration: nil, - saveIndexTargetAddrCh: nil, - schMap: sync.Map{}, - concurrency: 0, - indexInfos: indexInfos{}, - indexing: nil, - minUncommitted: 0, - uuidsCount: 0, - uncommittedUUIDsCount: 0, - }, - want: want{}, - checkFunc: defaultCheckFunc, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - ctx: nil, - enableLowIndexSkip: false, - immediateSaving: false, - }, - fields: fields { - client: nil, - eg: nil, - creationPoolSize: 0, - indexDuration: nil, - indexDurationLimit: nil, - saveIndexDurationLimit: nil, - saveIndexWaitDuration: nil, - saveIndexTargetAddrCh: nil, - schMap: sync.Map{}, - concurrency: 0, - indexInfos: indexInfos{}, - indexing: nil, - minUncommitted: 0, - uuidsCount: 0, - uncommittedUUIDsCount: 0, - }, - want: want{}, - checkFunc: defaultCheckFunc, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - checkFunc := test.checkFunc - if test.checkFunc == nil { - checkFunc = defaultCheckFunc - } - idx := &index{ - client: test.fields.client, - eg: test.fields.eg, - creationPoolSize: test.fields.creationPoolSize, - indexDuration: test.fields.indexDuration, - indexDurationLimit: test.fields.indexDurationLimit, - saveIndexDurationLimit: test.fields.saveIndexDurationLimit, - saveIndexWaitDuration: test.fields.saveIndexWaitDuration, - saveIndexTargetAddrCh: test.fields.saveIndexTargetAddrCh, - schMap: test.fields.schMap, - concurrency: test.fields.concurrency, - indexInfos: test.fields.indexInfos, - indexing: test.fields.indexing, - minUncommitted: test.fields.minUncommitted, - uuidsCount: test.fields.uuidsCount, - uncommittedUUIDsCount: test.fields.uncommittedUUIDsCount, - } - - err := idx.execute(test.args.ctx, test.args.enableLowIndexSkip, test.args.immediateSaving) - if err := checkFunc(test.want, err); err != nil { - tt.Errorf("error = %v", err) - } - }) - } -} - -func Test_index_waitForNextSaving(t *testing.T) { - type args struct { - ctx context.Context - } - type fields struct { - client discoverer.Client - eg errgroup.Group - creationPoolSize uint32 - indexDuration time.Duration - indexDurationLimit time.Duration - saveIndexDurationLimit time.Duration - saveIndexWaitDuration time.Duration - saveIndexTargetAddrCh chan string - schMap sync.Map - concurrency int - indexInfos indexInfos - indexing atomic.Value - minUncommitted uint32 - uuidsCount uint32 - uncommittedUUIDsCount uint32 - } - type want struct{} - type test struct { - name string - args args - fields fields - want want - checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) - } - defaultCheckFunc := func(w want) error { - return nil - } - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - ctx: nil, - }, - fields: fields { - client: nil, - eg: nil, - creationPoolSize: 0, - indexDuration: nil, - indexDurationLimit: nil, - saveIndexDurationLimit: nil, - saveIndexWaitDuration: nil, - saveIndexTargetAddrCh: nil, - schMap: sync.Map{}, - concurrency: 0, - indexInfos: indexInfos{}, - indexing: nil, - minUncommitted: 0, - uuidsCount: 0, - uncommittedUUIDsCount: 0, - }, - want: want{}, - checkFunc: defaultCheckFunc, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - ctx: nil, - }, - fields: fields { - client: nil, - eg: nil, - creationPoolSize: 0, - indexDuration: nil, - indexDurationLimit: nil, - saveIndexDurationLimit: nil, - saveIndexWaitDuration: nil, - saveIndexTargetAddrCh: nil, - schMap: sync.Map{}, - concurrency: 0, - indexInfos: indexInfos{}, - indexing: nil, - minUncommitted: 0, - uuidsCount: 0, - uncommittedUUIDsCount: 0, - }, - want: want{}, - checkFunc: defaultCheckFunc, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - checkFunc := test.checkFunc - if test.checkFunc == nil { - checkFunc = defaultCheckFunc - } - idx := &index{ - client: test.fields.client, - eg: test.fields.eg, - creationPoolSize: test.fields.creationPoolSize, - indexDuration: test.fields.indexDuration, - indexDurationLimit: test.fields.indexDurationLimit, - saveIndexDurationLimit: test.fields.saveIndexDurationLimit, - saveIndexWaitDuration: test.fields.saveIndexWaitDuration, - saveIndexTargetAddrCh: test.fields.saveIndexTargetAddrCh, - schMap: test.fields.schMap, - concurrency: test.fields.concurrency, - indexInfos: test.fields.indexInfos, - indexing: test.fields.indexing, - minUncommitted: test.fields.minUncommitted, - uuidsCount: test.fields.uuidsCount, - uncommittedUUIDsCount: test.fields.uncommittedUUIDsCount, - } - - idx.waitForNextSaving(test.args.ctx) - if err := checkFunc(test.want); err != nil { - tt.Errorf("error = %v", err) - } - }) - } -} - -func Test_index_loadInfos(t *testing.T) { - type args struct { - ctx context.Context - } - type fields struct { - client discoverer.Client - eg errgroup.Group - creationPoolSize uint32 - indexDuration time.Duration - indexDurationLimit time.Duration - saveIndexDurationLimit time.Duration - saveIndexWaitDuration time.Duration - saveIndexTargetAddrCh chan string - schMap sync.Map - concurrency int - indexInfos indexInfos - indexing atomic.Value - minUncommitted uint32 - uuidsCount uint32 - uncommittedUUIDsCount uint32 - } - type want struct { - err error - } - type test struct { - name string - args args - fields fields - want want - checkFunc func(want, error) error - beforeFunc func(args) - afterFunc func(args) - } - defaultCheckFunc := func(w want, err error) error { - if !errors.Is(err, w.err) { - return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) - } - return nil - } - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - ctx: nil, - }, - fields: fields { - client: nil, - eg: nil, - creationPoolSize: 0, - indexDuration: nil, - indexDurationLimit: nil, - saveIndexDurationLimit: nil, - saveIndexWaitDuration: nil, - saveIndexTargetAddrCh: nil, - schMap: sync.Map{}, - concurrency: 0, - indexInfos: indexInfos{}, - indexing: nil, - minUncommitted: 0, - uuidsCount: 0, - uncommittedUUIDsCount: 0, - }, - want: want{}, - checkFunc: defaultCheckFunc, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - ctx: nil, - }, - fields: fields { - client: nil, - eg: nil, - creationPoolSize: 0, - indexDuration: nil, - indexDurationLimit: nil, - saveIndexDurationLimit: nil, - saveIndexWaitDuration: nil, - saveIndexTargetAddrCh: nil, - schMap: sync.Map{}, - concurrency: 0, - indexInfos: indexInfos{}, - indexing: nil, - minUncommitted: 0, - uuidsCount: 0, - uncommittedUUIDsCount: 0, - }, - want: want{}, - checkFunc: defaultCheckFunc, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - checkFunc := test.checkFunc - if test.checkFunc == nil { - checkFunc = defaultCheckFunc - } - idx := &index{ - client: test.fields.client, - eg: test.fields.eg, - creationPoolSize: test.fields.creationPoolSize, - indexDuration: test.fields.indexDuration, - indexDurationLimit: test.fields.indexDurationLimit, - saveIndexDurationLimit: test.fields.saveIndexDurationLimit, - saveIndexWaitDuration: test.fields.saveIndexWaitDuration, - saveIndexTargetAddrCh: test.fields.saveIndexTargetAddrCh, - schMap: test.fields.schMap, - concurrency: test.fields.concurrency, - indexInfos: test.fields.indexInfos, - indexing: test.fields.indexing, - minUncommitted: test.fields.minUncommitted, - uuidsCount: test.fields.uuidsCount, - uncommittedUUIDsCount: test.fields.uncommittedUUIDsCount, - } - - err := idx.loadInfos(test.args.ctx) - if err := checkFunc(test.want, err); err != nil { - tt.Errorf("error = %v", err) - } - }) - } -} - -func Test_index_IsIndexing(t *testing.T) { - type fields struct { - client discoverer.Client - eg errgroup.Group - creationPoolSize uint32 - indexDuration time.Duration - indexDurationLimit time.Duration - saveIndexDurationLimit time.Duration - saveIndexWaitDuration time.Duration - saveIndexTargetAddrCh chan string - schMap sync.Map - concurrency int - indexInfos indexInfos - indexing atomic.Value - minUncommitted uint32 - uuidsCount uint32 - uncommittedUUIDsCount uint32 - } - type want struct { - want bool - } - type test struct { - name string - fields fields - want want - checkFunc func(want, bool) error - beforeFunc func() - afterFunc func() - } - defaultCheckFunc := func(w want, got bool) error { - if !reflect.DeepEqual(got, w.want) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) - } - return nil - } - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - fields: fields { - client: nil, - eg: nil, - creationPoolSize: 0, - indexDuration: nil, - indexDurationLimit: nil, - saveIndexDurationLimit: nil, - saveIndexWaitDuration: nil, - saveIndexTargetAddrCh: nil, - schMap: sync.Map{}, - concurrency: 0, - indexInfos: indexInfos{}, - indexing: nil, - minUncommitted: 0, - uuidsCount: 0, - uncommittedUUIDsCount: 0, - }, - want: want{}, - checkFunc: defaultCheckFunc, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - fields: fields { - client: nil, - eg: nil, - creationPoolSize: 0, - indexDuration: nil, - indexDurationLimit: nil, - saveIndexDurationLimit: nil, - saveIndexWaitDuration: nil, - saveIndexTargetAddrCh: nil, - schMap: sync.Map{}, - concurrency: 0, - indexInfos: indexInfos{}, - indexing: nil, - minUncommitted: 0, - uuidsCount: 0, - uncommittedUUIDsCount: 0, - }, - want: want{}, - checkFunc: defaultCheckFunc, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc() - } - if test.afterFunc != nil { - defer test.afterFunc() - } - checkFunc := test.checkFunc - if test.checkFunc == nil { - checkFunc = defaultCheckFunc - } - idx := &index{ - client: test.fields.client, - eg: test.fields.eg, - creationPoolSize: test.fields.creationPoolSize, - indexDuration: test.fields.indexDuration, - indexDurationLimit: test.fields.indexDurationLimit, - saveIndexDurationLimit: test.fields.saveIndexDurationLimit, - saveIndexWaitDuration: test.fields.saveIndexWaitDuration, - saveIndexTargetAddrCh: test.fields.saveIndexTargetAddrCh, - schMap: test.fields.schMap, - concurrency: test.fields.concurrency, - indexInfos: test.fields.indexInfos, - indexing: test.fields.indexing, - minUncommitted: test.fields.minUncommitted, - uuidsCount: test.fields.uuidsCount, - uncommittedUUIDsCount: test.fields.uncommittedUUIDsCount, - } - - got := idx.IsIndexing() - if err := checkFunc(test.want, got); err != nil { - tt.Errorf("error = %v", err) - } - }) - } -} - -func Test_index_NumberOfUUIDs(t *testing.T) { - type fields struct { - client discoverer.Client - eg errgroup.Group - creationPoolSize uint32 - indexDuration time.Duration - indexDurationLimit time.Duration - saveIndexDurationLimit time.Duration - saveIndexWaitDuration time.Duration - saveIndexTargetAddrCh chan string - schMap sync.Map - concurrency int - indexInfos indexInfos - indexing atomic.Value - minUncommitted uint32 - uuidsCount uint32 - uncommittedUUIDsCount uint32 - } - type want struct { - want uint32 - } - type test struct { - name string - fields fields - want want - checkFunc func(want, uint32) error - beforeFunc func() - afterFunc func() - } - defaultCheckFunc := func(w want, got uint32) error { - if !reflect.DeepEqual(got, w.want) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) - } - return nil - } - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - fields: fields { - client: nil, - eg: nil, - creationPoolSize: 0, - indexDuration: nil, - indexDurationLimit: nil, - saveIndexDurationLimit: nil, - saveIndexWaitDuration: nil, - saveIndexTargetAddrCh: nil, - schMap: sync.Map{}, - concurrency: 0, - indexInfos: indexInfos{}, - indexing: nil, - minUncommitted: 0, - uuidsCount: 0, - uncommittedUUIDsCount: 0, - }, - want: want{}, - checkFunc: defaultCheckFunc, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - fields: fields { - client: nil, - eg: nil, - creationPoolSize: 0, - indexDuration: nil, - indexDurationLimit: nil, - saveIndexDurationLimit: nil, - saveIndexWaitDuration: nil, - saveIndexTargetAddrCh: nil, - schMap: sync.Map{}, - concurrency: 0, - indexInfos: indexInfos{}, - indexing: nil, - minUncommitted: 0, - uuidsCount: 0, - uncommittedUUIDsCount: 0, - }, - want: want{}, - checkFunc: defaultCheckFunc, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc() - } - if test.afterFunc != nil { - defer test.afterFunc() - } - checkFunc := test.checkFunc - if test.checkFunc == nil { - checkFunc = defaultCheckFunc - } - idx := &index{ - client: test.fields.client, - eg: test.fields.eg, - creationPoolSize: test.fields.creationPoolSize, - indexDuration: test.fields.indexDuration, - indexDurationLimit: test.fields.indexDurationLimit, - saveIndexDurationLimit: test.fields.saveIndexDurationLimit, - saveIndexWaitDuration: test.fields.saveIndexWaitDuration, - saveIndexTargetAddrCh: test.fields.saveIndexTargetAddrCh, - schMap: test.fields.schMap, - concurrency: test.fields.concurrency, - indexInfos: test.fields.indexInfos, - indexing: test.fields.indexing, - minUncommitted: test.fields.minUncommitted, - uuidsCount: test.fields.uuidsCount, - uncommittedUUIDsCount: test.fields.uncommittedUUIDsCount, - } - - got := idx.NumberOfUUIDs() - if err := checkFunc(test.want, got); err != nil { - tt.Errorf("error = %v", err) - } - }) - } -} - -func Test_index_NumberOfUncommittedUUIDs(t *testing.T) { - type fields struct { - client discoverer.Client - eg errgroup.Group - creationPoolSize uint32 - indexDuration time.Duration - indexDurationLimit time.Duration - saveIndexDurationLimit time.Duration - saveIndexWaitDuration time.Duration - saveIndexTargetAddrCh chan string - schMap sync.Map - concurrency int - indexInfos indexInfos - indexing atomic.Value - minUncommitted uint32 - uuidsCount uint32 - uncommittedUUIDsCount uint32 - } - type want struct { - want uint32 - } - type test struct { - name string - fields fields - want want - checkFunc func(want, uint32) error - beforeFunc func() - afterFunc func() - } - defaultCheckFunc := func(w want, got uint32) error { - if !reflect.DeepEqual(got, w.want) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) - } - return nil - } - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - fields: fields { - client: nil, - eg: nil, - creationPoolSize: 0, - indexDuration: nil, - indexDurationLimit: nil, - saveIndexDurationLimit: nil, - saveIndexWaitDuration: nil, - saveIndexTargetAddrCh: nil, - schMap: sync.Map{}, - concurrency: 0, - indexInfos: indexInfos{}, - indexing: nil, - minUncommitted: 0, - uuidsCount: 0, - uncommittedUUIDsCount: 0, - }, - want: want{}, - checkFunc: defaultCheckFunc, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - fields: fields { - client: nil, - eg: nil, - creationPoolSize: 0, - indexDuration: nil, - indexDurationLimit: nil, - saveIndexDurationLimit: nil, - saveIndexWaitDuration: nil, - saveIndexTargetAddrCh: nil, - schMap: sync.Map{}, - concurrency: 0, - indexInfos: indexInfos{}, - indexing: nil, - minUncommitted: 0, - uuidsCount: 0, - uncommittedUUIDsCount: 0, - }, - want: want{}, - checkFunc: defaultCheckFunc, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc() - } - if test.afterFunc != nil { - defer test.afterFunc() - } - checkFunc := test.checkFunc - if test.checkFunc == nil { - checkFunc = defaultCheckFunc - } - idx := &index{ - client: test.fields.client, - eg: test.fields.eg, - creationPoolSize: test.fields.creationPoolSize, - indexDuration: test.fields.indexDuration, - indexDurationLimit: test.fields.indexDurationLimit, - saveIndexDurationLimit: test.fields.saveIndexDurationLimit, - saveIndexWaitDuration: test.fields.saveIndexWaitDuration, - saveIndexTargetAddrCh: test.fields.saveIndexTargetAddrCh, - schMap: test.fields.schMap, - concurrency: test.fields.concurrency, - indexInfos: test.fields.indexInfos, - indexing: test.fields.indexing, - minUncommitted: test.fields.minUncommitted, - uuidsCount: test.fields.uuidsCount, - uncommittedUUIDsCount: test.fields.uncommittedUUIDsCount, - } - - got := idx.NumberOfUncommittedUUIDs() - if err := checkFunc(test.want, got); err != nil { - tt.Errorf("error = %v", err) - } - }) - } -} diff --git a/pkg/manager/index/service/indexinfos_test.go b/pkg/manager/index/service/indexinfos_test.go deleted file mode 100644 index 200acd6e07..0000000000 --- a/pkg/manager/index/service/indexinfos_test.go +++ /dev/null @@ -1,1127 +0,0 @@ -// -// Copyright (C) 2019-2022 vdaas.org vald team -// -// Licensed 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 -// -// https://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 service - -import ( - "reflect" - "sync" - "sync/atomic" - "testing" - "unsafe" - - "github.com/vdaas/vald/apis/grpc/v1/payload" - "github.com/vdaas/vald/internal/errors" - "github.com/vdaas/vald/internal/test/goleak" -) - -func Test_newEntryIndexInfos(t *testing.T) { - type args struct { - i *payload.Info_Index_Count - } - type want struct { - want *entryIndexInfos - } - type test struct { - name string - args args - want want - checkFunc func(want, *entryIndexInfos) error - beforeFunc func(args) - afterFunc func(args) - } - defaultCheckFunc := func(w want, got *entryIndexInfos) error { - if !reflect.DeepEqual(got, w.want) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) - } - return nil - } - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - i: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - i: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - checkFunc := test.checkFunc - if test.checkFunc == nil { - checkFunc = defaultCheckFunc - } - - got := newEntryIndexInfos(test.args.i) - if err := checkFunc(test.want, got); err != nil { - tt.Errorf("error = %v", err) - } - }) - } -} - -func Test_indexInfos_Load(t *testing.T) { - type args struct { - key string - } - type fields struct { - mu sync.Mutex - read atomic.Value - dirty map[string]*entryIndexInfos - misses int - } - type want struct { - wantValue *payload.Info_Index_Count - wantOk bool - } - type test struct { - name string - args args - fields fields - want want - checkFunc func(want, *payload.Info_Index_Count, bool) error - beforeFunc func(args) - afterFunc func(args) - } - defaultCheckFunc := func(w want, gotValue *payload.Info_Index_Count, gotOk bool) error { - if !reflect.DeepEqual(gotValue, w.wantValue) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", gotValue, w.wantValue) - } - if !reflect.DeepEqual(gotOk, w.wantOk) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", gotOk, w.wantOk) - } - return nil - } - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - key: "", - }, - fields: fields { - mu: sync.Mutex{}, - read: nil, - dirty: nil, - misses: 0, - }, - want: want{}, - checkFunc: defaultCheckFunc, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - key: "", - }, - fields: fields { - mu: sync.Mutex{}, - read: nil, - dirty: nil, - misses: 0, - }, - want: want{}, - checkFunc: defaultCheckFunc, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - checkFunc := test.checkFunc - if test.checkFunc == nil { - checkFunc = defaultCheckFunc - } - m := &indexInfos{ - mu: test.fields.mu, - read: test.fields.read, - dirty: test.fields.dirty, - misses: test.fields.misses, - } - - gotValue, gotOk := m.Load(test.args.key) - if err := checkFunc(test.want, gotValue, gotOk); err != nil { - tt.Errorf("error = %v", err) - } - }) - } -} - -func Test_entryIndexInfos_load(t *testing.T) { - type fields struct { - p unsafe.Pointer - } - type want struct { - wantValue *payload.Info_Index_Count - wantOk bool - } - type test struct { - name string - fields fields - want want - checkFunc func(want, *payload.Info_Index_Count, bool) error - beforeFunc func() - afterFunc func() - } - defaultCheckFunc := func(w want, gotValue *payload.Info_Index_Count, gotOk bool) error { - if !reflect.DeepEqual(gotValue, w.wantValue) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", gotValue, w.wantValue) - } - if !reflect.DeepEqual(gotOk, w.wantOk) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", gotOk, w.wantOk) - } - return nil - } - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - fields: fields { - p: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - fields: fields { - p: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc() - } - if test.afterFunc != nil { - defer test.afterFunc() - } - checkFunc := test.checkFunc - if test.checkFunc == nil { - checkFunc = defaultCheckFunc - } - e := &entryIndexInfos{ - p: test.fields.p, - } - - gotValue, gotOk := e.load() - if err := checkFunc(test.want, gotValue, gotOk); err != nil { - tt.Errorf("error = %v", err) - } - }) - } -} - -func Test_indexInfos_Store(t *testing.T) { - type args struct { - key string - value *payload.Info_Index_Count - } - type fields struct { - mu sync.Mutex - read atomic.Value - dirty map[string]*entryIndexInfos - misses int - } - type want struct{} - type test struct { - name string - args args - fields fields - want want - checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) - } - defaultCheckFunc := func(w want) error { - return nil - } - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - key: "", - value: nil, - }, - fields: fields { - mu: sync.Mutex{}, - read: nil, - dirty: nil, - misses: 0, - }, - want: want{}, - checkFunc: defaultCheckFunc, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - key: "", - value: nil, - }, - fields: fields { - mu: sync.Mutex{}, - read: nil, - dirty: nil, - misses: 0, - }, - want: want{}, - checkFunc: defaultCheckFunc, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - checkFunc := test.checkFunc - if test.checkFunc == nil { - checkFunc = defaultCheckFunc - } - m := &indexInfos{ - mu: test.fields.mu, - read: test.fields.read, - dirty: test.fields.dirty, - misses: test.fields.misses, - } - - m.Store(test.args.key, test.args.value) - if err := checkFunc(test.want); err != nil { - tt.Errorf("error = %v", err) - } - }) - } -} - -func Test_entryIndexInfos_tryStore(t *testing.T) { - type args struct { - i **payload.Info_Index_Count - } - type fields struct { - p unsafe.Pointer - } - type want struct { - want bool - } - type test struct { - name string - args args - fields fields - want want - checkFunc func(want, bool) error - beforeFunc func(args) - afterFunc func(args) - } - defaultCheckFunc := func(w want, got bool) error { - if !reflect.DeepEqual(got, w.want) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) - } - return nil - } - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - i: nil, - }, - fields: fields { - p: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - i: nil, - }, - fields: fields { - p: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - checkFunc := test.checkFunc - if test.checkFunc == nil { - checkFunc = defaultCheckFunc - } - e := &entryIndexInfos{ - p: test.fields.p, - } - - got := e.tryStore(test.args.i) - if err := checkFunc(test.want, got); err != nil { - tt.Errorf("error = %v", err) - } - }) - } -} - -func Test_entryIndexInfos_unexpungeLocked(t *testing.T) { - type fields struct { - p unsafe.Pointer - } - type want struct { - wantWasExpunged bool - } - type test struct { - name string - fields fields - want want - checkFunc func(want, bool) error - beforeFunc func() - afterFunc func() - } - defaultCheckFunc := func(w want, gotWasExpunged bool) error { - if !reflect.DeepEqual(gotWasExpunged, w.wantWasExpunged) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", gotWasExpunged, w.wantWasExpunged) - } - return nil - } - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - fields: fields { - p: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - fields: fields { - p: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc() - } - if test.afterFunc != nil { - defer test.afterFunc() - } - checkFunc := test.checkFunc - if test.checkFunc == nil { - checkFunc = defaultCheckFunc - } - e := &entryIndexInfos{ - p: test.fields.p, - } - - gotWasExpunged := e.unexpungeLocked() - if err := checkFunc(test.want, gotWasExpunged); err != nil { - tt.Errorf("error = %v", err) - } - }) - } -} - -func Test_entryIndexInfos_storeLocked(t *testing.T) { - type args struct { - i **payload.Info_Index_Count - } - type fields struct { - p unsafe.Pointer - } - type want struct{} - type test struct { - name string - args args - fields fields - want want - checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) - } - defaultCheckFunc := func(w want) error { - return nil - } - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - i: nil, - }, - fields: fields { - p: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - i: nil, - }, - fields: fields { - p: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - checkFunc := test.checkFunc - if test.checkFunc == nil { - checkFunc = defaultCheckFunc - } - e := &entryIndexInfos{ - p: test.fields.p, - } - - e.storeLocked(test.args.i) - if err := checkFunc(test.want); err != nil { - tt.Errorf("error = %v", err) - } - }) - } -} - -func Test_indexInfos_Delete(t *testing.T) { - type args struct { - key string - } - type fields struct { - mu sync.Mutex - read atomic.Value - dirty map[string]*entryIndexInfos - misses int - } - type want struct{} - type test struct { - name string - args args - fields fields - want want - checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) - } - defaultCheckFunc := func(w want) error { - return nil - } - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - key: "", - }, - fields: fields { - mu: sync.Mutex{}, - read: nil, - dirty: nil, - misses: 0, - }, - want: want{}, - checkFunc: defaultCheckFunc, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - key: "", - }, - fields: fields { - mu: sync.Mutex{}, - read: nil, - dirty: nil, - misses: 0, - }, - want: want{}, - checkFunc: defaultCheckFunc, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - checkFunc := test.checkFunc - if test.checkFunc == nil { - checkFunc = defaultCheckFunc - } - m := &indexInfos{ - mu: test.fields.mu, - read: test.fields.read, - dirty: test.fields.dirty, - misses: test.fields.misses, - } - - m.Delete(test.args.key) - if err := checkFunc(test.want); err != nil { - tt.Errorf("error = %v", err) - } - }) - } -} - -func Test_entryIndexInfos_delete(t *testing.T) { - type fields struct { - p unsafe.Pointer - } - type want struct { - wantHadValue bool - } - type test struct { - name string - fields fields - want want - checkFunc func(want, bool) error - beforeFunc func() - afterFunc func() - } - defaultCheckFunc := func(w want, gotHadValue bool) error { - if !reflect.DeepEqual(gotHadValue, w.wantHadValue) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", gotHadValue, w.wantHadValue) - } - return nil - } - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - fields: fields { - p: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - fields: fields { - p: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc() - } - if test.afterFunc != nil { - defer test.afterFunc() - } - checkFunc := test.checkFunc - if test.checkFunc == nil { - checkFunc = defaultCheckFunc - } - e := &entryIndexInfos{ - p: test.fields.p, - } - - gotHadValue := e.delete() - if err := checkFunc(test.want, gotHadValue); err != nil { - tt.Errorf("error = %v", err) - } - }) - } -} - -func Test_indexInfos_Range(t *testing.T) { - type args struct { - f func(key string, value *payload.Info_Index_Count) bool - } - type fields struct { - mu sync.Mutex - read atomic.Value - dirty map[string]*entryIndexInfos - misses int - } - type want struct{} - type test struct { - name string - args args - fields fields - want want - checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) - } - defaultCheckFunc := func(w want) error { - return nil - } - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - f: nil, - }, - fields: fields { - mu: sync.Mutex{}, - read: nil, - dirty: nil, - misses: 0, - }, - want: want{}, - checkFunc: defaultCheckFunc, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - f: nil, - }, - fields: fields { - mu: sync.Mutex{}, - read: nil, - dirty: nil, - misses: 0, - }, - want: want{}, - checkFunc: defaultCheckFunc, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - checkFunc := test.checkFunc - if test.checkFunc == nil { - checkFunc = defaultCheckFunc - } - m := &indexInfos{ - mu: test.fields.mu, - read: test.fields.read, - dirty: test.fields.dirty, - misses: test.fields.misses, - } - - m.Range(test.args.f) - if err := checkFunc(test.want); err != nil { - tt.Errorf("error = %v", err) - } - }) - } -} - -func Test_indexInfos_missLocked(t *testing.T) { - type fields struct { - mu sync.Mutex - read atomic.Value - dirty map[string]*entryIndexInfos - misses int - } - type want struct{} - type test struct { - name string - fields fields - want want - checkFunc func(want) error - beforeFunc func() - afterFunc func() - } - defaultCheckFunc := func(w want) error { - return nil - } - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - fields: fields { - mu: sync.Mutex{}, - read: nil, - dirty: nil, - misses: 0, - }, - want: want{}, - checkFunc: defaultCheckFunc, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - fields: fields { - mu: sync.Mutex{}, - read: nil, - dirty: nil, - misses: 0, - }, - want: want{}, - checkFunc: defaultCheckFunc, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc() - } - if test.afterFunc != nil { - defer test.afterFunc() - } - checkFunc := test.checkFunc - if test.checkFunc == nil { - checkFunc = defaultCheckFunc - } - m := &indexInfos{ - mu: test.fields.mu, - read: test.fields.read, - dirty: test.fields.dirty, - misses: test.fields.misses, - } - - m.missLocked() - if err := checkFunc(test.want); err != nil { - tt.Errorf("error = %v", err) - } - }) - } -} - -func Test_indexInfos_dirtyLocked(t *testing.T) { - type fields struct { - mu sync.Mutex - read atomic.Value - dirty map[string]*entryIndexInfos - misses int - } - type want struct{} - type test struct { - name string - fields fields - want want - checkFunc func(want) error - beforeFunc func() - afterFunc func() - } - defaultCheckFunc := func(w want) error { - return nil - } - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - fields: fields { - mu: sync.Mutex{}, - read: nil, - dirty: nil, - misses: 0, - }, - want: want{}, - checkFunc: defaultCheckFunc, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - fields: fields { - mu: sync.Mutex{}, - read: nil, - dirty: nil, - misses: 0, - }, - want: want{}, - checkFunc: defaultCheckFunc, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc() - } - if test.afterFunc != nil { - defer test.afterFunc() - } - checkFunc := test.checkFunc - if test.checkFunc == nil { - checkFunc = defaultCheckFunc - } - m := &indexInfos{ - mu: test.fields.mu, - read: test.fields.read, - dirty: test.fields.dirty, - misses: test.fields.misses, - } - - m.dirtyLocked() - if err := checkFunc(test.want); err != nil { - tt.Errorf("error = %v", err) - } - }) - } -} - -func Test_entryIndexInfos_tryExpungeLocked(t *testing.T) { - type fields struct { - p unsafe.Pointer - } - type want struct { - wantIsExpunged bool - } - type test struct { - name string - fields fields - want want - checkFunc func(want, bool) error - beforeFunc func() - afterFunc func() - } - defaultCheckFunc := func(w want, gotIsExpunged bool) error { - if !reflect.DeepEqual(gotIsExpunged, w.wantIsExpunged) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", gotIsExpunged, w.wantIsExpunged) - } - return nil - } - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - fields: fields { - p: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - fields: fields { - p: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc() - } - if test.afterFunc != nil { - defer test.afterFunc() - } - checkFunc := test.checkFunc - if test.checkFunc == nil { - checkFunc = defaultCheckFunc - } - e := &entryIndexInfos{ - p: test.fields.p, - } - - gotIsExpunged := e.tryExpungeLocked() - if err := checkFunc(test.want, gotIsExpunged); err != nil { - tt.Errorf("error = %v", err) - } - }) - } -} diff --git a/pkg/manager/index/service/option_test.go b/pkg/manager/index/service/option_test.go deleted file mode 100644 index 91f0d88656..0000000000 --- a/pkg/manager/index/service/option_test.go +++ /dev/null @@ -1,1070 +0,0 @@ -// -// Copyright (C) 2019-2022 vdaas.org vald team -// -// Licensed 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 -// -// https://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 service -package service - -import ( - "testing" - - "github.com/vdaas/vald/internal/client/v1/client/discoverer" - "github.com/vdaas/vald/internal/errgroup" - "github.com/vdaas/vald/internal/test/goleak" -) - -func TestWithIndexingConcurrency(t *testing.T) { - // Change interface type to the type of object you are testing - type T = interface{} - type args struct { - c int - } - type want struct { - obj *T - // Uncomment this line if the option returns an error, otherwise delete it - // err error - } - type test struct { - name string - args args - want want - // Use the first line if the option returns an error. otherwise use the second line - // checkFunc func(want, *T, error) error - // checkFunc func(want, *T) error - beforeFunc func(args) - afterFunc func(args) - } - - // Uncomment this block if the option returns an error, otherwise delete it - /* - defaultCheckFunc := func(w want, obj *T, err error) error { - if !errors.Is(err, w.err) { - return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) - } - if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", obj, w.obj) - } - return nil - } - */ - - // Uncomment this block if the option do not returns an error, otherwise delete it - /* - defaultCheckFunc := func(w want, obj *T) error { - if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", obj, w.obj) - } - return nil - } - */ - - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - c: 0, - }, - want: want { - obj: new(T), - }, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - c: 0, - }, - want: want { - obj: new(T), - }, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - - // Uncomment this block if the option returns an error, otherwise delete it - /* - if test.checkFunc == nil { - test.checkFunc = defaultCheckFunc - } - - got := WithIndexingConcurrency(test.args.c) - obj := new(T) - if err := checkFunc(test.want, obj, got(obj)); err != nil { - tt.Errorf("error = %v", err) - } - */ - - // Uncomment this block if the option do not return an error, otherwise delete it - /* - if test.checkFunc == nil { - test.checkFunc = defaultCheckFunc - } - got := WithIndexingConcurrency(test.args.c) - obj := new(T) - got(obj) - if err := checkFunc(test.want, obj); err != nil { - tt.Errorf("error = %v", err) - } - */ - }) - } -} - -func TestWithIndexingDuration(t *testing.T) { - // Change interface type to the type of object you are testing - type T = interface{} - type args struct { - dur string - } - type want struct { - obj *T - // Uncomment this line if the option returns an error, otherwise delete it - // err error - } - type test struct { - name string - args args - want want - // Use the first line if the option returns an error. otherwise use the second line - // checkFunc func(want, *T, error) error - // checkFunc func(want, *T) error - beforeFunc func(args) - afterFunc func(args) - } - - // Uncomment this block if the option returns an error, otherwise delete it - /* - defaultCheckFunc := func(w want, obj *T, err error) error { - if !errors.Is(err, w.err) { - return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) - } - if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", obj, w.obj) - } - return nil - } - */ - - // Uncomment this block if the option do not returns an error, otherwise delete it - /* - defaultCheckFunc := func(w want, obj *T) error { - if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", obj, w.obj) - } - return nil - } - */ - - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - dur: "", - }, - want: want { - obj: new(T), - }, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - dur: "", - }, - want: want { - obj: new(T), - }, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - - // Uncomment this block if the option returns an error, otherwise delete it - /* - if test.checkFunc == nil { - test.checkFunc = defaultCheckFunc - } - - got := WithIndexingDuration(test.args.dur) - obj := new(T) - if err := checkFunc(test.want, obj, got(obj)); err != nil { - tt.Errorf("error = %v", err) - } - */ - - // Uncomment this block if the option do not return an error, otherwise delete it - /* - if test.checkFunc == nil { - test.checkFunc = defaultCheckFunc - } - got := WithIndexingDuration(test.args.dur) - obj := new(T) - got(obj) - if err := checkFunc(test.want, obj); err != nil { - tt.Errorf("error = %v", err) - } - */ - }) - } -} - -func TestWithIndexingDurationLimit(t *testing.T) { - // Change interface type to the type of object you are testing - type T = interface{} - type args struct { - dur string - } - type want struct { - obj *T - // Uncomment this line if the option returns an error, otherwise delete it - // err error - } - type test struct { - name string - args args - want want - // Use the first line if the option returns an error. otherwise use the second line - // checkFunc func(want, *T, error) error - // checkFunc func(want, *T) error - beforeFunc func(args) - afterFunc func(args) - } - - // Uncomment this block if the option returns an error, otherwise delete it - /* - defaultCheckFunc := func(w want, obj *T, err error) error { - if !errors.Is(err, w.err) { - return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) - } - if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", obj, w.obj) - } - return nil - } - */ - - // Uncomment this block if the option do not returns an error, otherwise delete it - /* - defaultCheckFunc := func(w want, obj *T) error { - if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", obj, w.obj) - } - return nil - } - */ - - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - dur: "", - }, - want: want { - obj: new(T), - }, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - dur: "", - }, - want: want { - obj: new(T), - }, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - - // Uncomment this block if the option returns an error, otherwise delete it - /* - if test.checkFunc == nil { - test.checkFunc = defaultCheckFunc - } - - got := WithIndexingDurationLimit(test.args.dur) - obj := new(T) - if err := checkFunc(test.want, obj, got(obj)); err != nil { - tt.Errorf("error = %v", err) - } - */ - - // Uncomment this block if the option do not return an error, otherwise delete it - /* - if test.checkFunc == nil { - test.checkFunc = defaultCheckFunc - } - got := WithIndexingDurationLimit(test.args.dur) - obj := new(T) - got(obj) - if err := checkFunc(test.want, obj); err != nil { - tt.Errorf("error = %v", err) - } - */ - }) - } -} - -func TestWithSaveIndexDurationLimit(t *testing.T) { - // Change interface type to the type of object you are testing - type T = interface{} - type args struct { - dur string - } - type want struct { - obj *T - // Uncomment this line if the option returns an error, otherwise delete it - // err error - } - type test struct { - name string - args args - want want - // Use the first line if the option returns an error. otherwise use the second line - // checkFunc func(want, *T, error) error - // checkFunc func(want, *T) error - beforeFunc func(args) - afterFunc func(args) - } - - // Uncomment this block if the option returns an error, otherwise delete it - /* - defaultCheckFunc := func(w want, obj *T, err error) error { - if !errors.Is(err, w.err) { - return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) - } - if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", obj, w.obj) - } - return nil - } - */ - - // Uncomment this block if the option do not returns an error, otherwise delete it - /* - defaultCheckFunc := func(w want, obj *T) error { - if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", obj, w.obj) - } - return nil - } - */ - - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - dur: "", - }, - want: want { - obj: new(T), - }, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - dur: "", - }, - want: want { - obj: new(T), - }, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - - // Uncomment this block if the option returns an error, otherwise delete it - /* - if test.checkFunc == nil { - test.checkFunc = defaultCheckFunc - } - - got := WithSaveIndexDurationLimit(test.args.dur) - obj := new(T) - if err := checkFunc(test.want, obj, got(obj)); err != nil { - tt.Errorf("error = %v", err) - } - */ - - // Uncomment this block if the option do not return an error, otherwise delete it - /* - if test.checkFunc == nil { - test.checkFunc = defaultCheckFunc - } - got := WithSaveIndexDurationLimit(test.args.dur) - obj := new(T) - got(obj) - if err := checkFunc(test.want, obj); err != nil { - tt.Errorf("error = %v", err) - } - */ - }) - } -} - -func TestWithSaveIndexWaitDuration(t *testing.T) { - // Change interface type to the type of object you are testing - type T = interface{} - type args struct { - dur string - } - type want struct { - obj *T - // Uncomment this line if the option returns an error, otherwise delete it - // err error - } - type test struct { - name string - args args - want want - // Use the first line if the option returns an error. otherwise use the second line - // checkFunc func(want, *T, error) error - // checkFunc func(want, *T) error - beforeFunc func(args) - afterFunc func(args) - } - - // Uncomment this block if the option returns an error, otherwise delete it - /* - defaultCheckFunc := func(w want, obj *T, err error) error { - if !errors.Is(err, w.err) { - return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) - } - if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", obj, w.obj) - } - return nil - } - */ - - // Uncomment this block if the option do not returns an error, otherwise delete it - /* - defaultCheckFunc := func(w want, obj *T) error { - if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", obj, w.obj) - } - return nil - } - */ - - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - dur: "", - }, - want: want { - obj: new(T), - }, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - dur: "", - }, - want: want { - obj: new(T), - }, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - - // Uncomment this block if the option returns an error, otherwise delete it - /* - if test.checkFunc == nil { - test.checkFunc = defaultCheckFunc - } - - got := WithSaveIndexWaitDuration(test.args.dur) - obj := new(T) - if err := checkFunc(test.want, obj, got(obj)); err != nil { - tt.Errorf("error = %v", err) - } - */ - - // Uncomment this block if the option do not return an error, otherwise delete it - /* - if test.checkFunc == nil { - test.checkFunc = defaultCheckFunc - } - got := WithSaveIndexWaitDuration(test.args.dur) - obj := new(T) - got(obj) - if err := checkFunc(test.want, obj); err != nil { - tt.Errorf("error = %v", err) - } - */ - }) - } -} - -func TestWithMinUncommitted(t *testing.T) { - // Change interface type to the type of object you are testing - type T = interface{} - type args struct { - n uint32 - } - type want struct { - obj *T - // Uncomment this line if the option returns an error, otherwise delete it - // err error - } - type test struct { - name string - args args - want want - // Use the first line if the option returns an error. otherwise use the second line - // checkFunc func(want, *T, error) error - // checkFunc func(want, *T) error - beforeFunc func(args) - afterFunc func(args) - } - - // Uncomment this block if the option returns an error, otherwise delete it - /* - defaultCheckFunc := func(w want, obj *T, err error) error { - if !errors.Is(err, w.err) { - return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) - } - if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", obj, w.obj) - } - return nil - } - */ - - // Uncomment this block if the option do not returns an error, otherwise delete it - /* - defaultCheckFunc := func(w want, obj *T) error { - if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", obj, w.obj) - } - return nil - } - */ - - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - n: 0, - }, - want: want { - obj: new(T), - }, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - n: 0, - }, - want: want { - obj: new(T), - }, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - - // Uncomment this block if the option returns an error, otherwise delete it - /* - if test.checkFunc == nil { - test.checkFunc = defaultCheckFunc - } - - got := WithMinUncommitted(test.args.n) - obj := new(T) - if err := checkFunc(test.want, obj, got(obj)); err != nil { - tt.Errorf("error = %v", err) - } - */ - - // Uncomment this block if the option do not return an error, otherwise delete it - /* - if test.checkFunc == nil { - test.checkFunc = defaultCheckFunc - } - got := WithMinUncommitted(test.args.n) - obj := new(T) - got(obj) - if err := checkFunc(test.want, obj); err != nil { - tt.Errorf("error = %v", err) - } - */ - }) - } -} - -func TestWithCreationPoolSize(t *testing.T) { - // Change interface type to the type of object you are testing - type T = interface{} - type args struct { - size uint32 - } - type want struct { - obj *T - // Uncomment this line if the option returns an error, otherwise delete it - // err error - } - type test struct { - name string - args args - want want - // Use the first line if the option returns an error. otherwise use the second line - // checkFunc func(want, *T, error) error - // checkFunc func(want, *T) error - beforeFunc func(args) - afterFunc func(args) - } - - // Uncomment this block if the option returns an error, otherwise delete it - /* - defaultCheckFunc := func(w want, obj *T, err error) error { - if !errors.Is(err, w.err) { - return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) - } - if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", obj, w.obj) - } - return nil - } - */ - - // Uncomment this block if the option do not returns an error, otherwise delete it - /* - defaultCheckFunc := func(w want, obj *T) error { - if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", obj, w.obj) - } - return nil - } - */ - - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - size: 0, - }, - want: want { - obj: new(T), - }, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - size: 0, - }, - want: want { - obj: new(T), - }, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - - // Uncomment this block if the option returns an error, otherwise delete it - /* - if test.checkFunc == nil { - test.checkFunc = defaultCheckFunc - } - - got := WithCreationPoolSize(test.args.size) - obj := new(T) - if err := checkFunc(test.want, obj, got(obj)); err != nil { - tt.Errorf("error = %v", err) - } - */ - - // Uncomment this block if the option do not return an error, otherwise delete it - /* - if test.checkFunc == nil { - test.checkFunc = defaultCheckFunc - } - got := WithCreationPoolSize(test.args.size) - obj := new(T) - got(obj) - if err := checkFunc(test.want, obj); err != nil { - tt.Errorf("error = %v", err) - } - */ - }) - } -} - -func TestWithDiscoverer(t *testing.T) { - // Change interface type to the type of object you are testing - type T = interface{} - type args struct { - c discoverer.Client - } - type want struct { - obj *T - // Uncomment this line if the option returns an error, otherwise delete it - // err error - } - type test struct { - name string - args args - want want - // Use the first line if the option returns an error. otherwise use the second line - // checkFunc func(want, *T, error) error - // checkFunc func(want, *T) error - beforeFunc func(args) - afterFunc func(args) - } - - // Uncomment this block if the option returns an error, otherwise delete it - /* - defaultCheckFunc := func(w want, obj *T, err error) error { - if !errors.Is(err, w.err) { - return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) - } - if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", obj, w.obj) - } - return nil - } - */ - - // Uncomment this block if the option do not returns an error, otherwise delete it - /* - defaultCheckFunc := func(w want, obj *T) error { - if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", obj, w.obj) - } - return nil - } - */ - - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - c: nil, - }, - want: want { - obj: new(T), - }, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - c: nil, - }, - want: want { - obj: new(T), - }, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - - // Uncomment this block if the option returns an error, otherwise delete it - /* - if test.checkFunc == nil { - test.checkFunc = defaultCheckFunc - } - - got := WithDiscoverer(test.args.c) - obj := new(T) - if err := checkFunc(test.want, obj, got(obj)); err != nil { - tt.Errorf("error = %v", err) - } - */ - - // Uncomment this block if the option do not return an error, otherwise delete it - /* - if test.checkFunc == nil { - test.checkFunc = defaultCheckFunc - } - got := WithDiscoverer(test.args.c) - obj := new(T) - got(obj) - if err := checkFunc(test.want, obj); err != nil { - tt.Errorf("error = %v", err) - } - */ - }) - } -} - -func TestWithErrGroup(t *testing.T) { - // Change interface type to the type of object you are testing - type T = interface{} - type args struct { - eg errgroup.Group - } - type want struct { - obj *T - // Uncomment this line if the option returns an error, otherwise delete it - // err error - } - type test struct { - name string - args args - want want - // Use the first line if the option returns an error. otherwise use the second line - // checkFunc func(want, *T, error) error - // checkFunc func(want, *T) error - beforeFunc func(args) - afterFunc func(args) - } - - // Uncomment this block if the option returns an error, otherwise delete it - /* - defaultCheckFunc := func(w want, obj *T, err error) error { - if !errors.Is(err, w.err) { - return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) - } - if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", obj, w.obj) - } - return nil - } - */ - - // Uncomment this block if the option do not returns an error, otherwise delete it - /* - defaultCheckFunc := func(w want, obj *T) error { - if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", obj, w.obj) - } - return nil - } - */ - - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - eg: nil, - }, - want: want { - obj: new(T), - }, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - eg: nil, - }, - want: want { - obj: new(T), - }, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - - // Uncomment this block if the option returns an error, otherwise delete it - /* - if test.checkFunc == nil { - test.checkFunc = defaultCheckFunc - } - - got := WithErrGroup(test.args.eg) - obj := new(T) - if err := checkFunc(test.want, obj, got(obj)); err != nil { - tt.Errorf("error = %v", err) - } - */ - - // Uncomment this block if the option do not return an error, otherwise delete it - /* - if test.checkFunc == nil { - test.checkFunc = defaultCheckFunc - } - got := WithErrGroup(test.args.eg) - obj := new(T) - got(obj) - if err := checkFunc(test.want, obj); err != nil { - tt.Errorf("error = %v", err) - } - */ - }) - } -} diff --git a/pkg/manager/index/usecase/indexer_test.go b/pkg/manager/index/usecase/indexer_test.go deleted file mode 100644 index 9037fe1b2b..0000000000 --- a/pkg/manager/index/usecase/indexer_test.go +++ /dev/null @@ -1,623 +0,0 @@ -// -// Copyright (C) 2019-2022 vdaas.org vald team -// -// Licensed 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 -// -// https://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 usecase - -import ( - "context" - "reflect" - "testing" - - "github.com/vdaas/vald/internal/errgroup" - "github.com/vdaas/vald/internal/errors" - "github.com/vdaas/vald/internal/observability" - "github.com/vdaas/vald/internal/runner" - "github.com/vdaas/vald/internal/servers/starter" - "github.com/vdaas/vald/internal/test/goleak" - "github.com/vdaas/vald/pkg/manager/index/config" - "github.com/vdaas/vald/pkg/manager/index/service" -) - -func TestNew(t *testing.T) { - type args struct { - cfg *config.Data - } - type want struct { - wantR runner.Runner - err error - } - type test struct { - name string - args args - want want - checkFunc func(want, runner.Runner, error) error - beforeFunc func(args) - afterFunc func(args) - } - defaultCheckFunc := func(w want, gotR runner.Runner, err error) error { - if !errors.Is(err, w.err) { - return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) - } - if !reflect.DeepEqual(gotR, w.wantR) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", gotR, w.wantR) - } - return nil - } - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - cfg: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - cfg: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - checkFunc := test.checkFunc - if test.checkFunc == nil { - checkFunc = defaultCheckFunc - } - - gotR, err := New(test.args.cfg) - if err := checkFunc(test.want, gotR, err); err != nil { - tt.Errorf("error = %v", err) - } - }) - } -} - -func Test_run_PreStart(t *testing.T) { - type args struct { - ctx context.Context - } - type fields struct { - eg errgroup.Group - cfg *config.Data - server starter.Server - observability observability.Observability - indexer service.Indexer - } - type want struct { - err error - } - type test struct { - name string - args args - fields fields - want want - checkFunc func(want, error) error - beforeFunc func(args) - afterFunc func(args) - } - defaultCheckFunc := func(w want, err error) error { - if !errors.Is(err, w.err) { - return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) - } - return nil - } - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - ctx: nil, - }, - fields: fields { - eg: nil, - cfg: nil, - server: nil, - observability: nil, - indexer: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - ctx: nil, - }, - fields: fields { - eg: nil, - cfg: nil, - server: nil, - observability: nil, - indexer: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - checkFunc := test.checkFunc - if test.checkFunc == nil { - checkFunc = defaultCheckFunc - } - r := &run{ - eg: test.fields.eg, - cfg: test.fields.cfg, - server: test.fields.server, - observability: test.fields.observability, - indexer: test.fields.indexer, - } - - err := r.PreStart(test.args.ctx) - if err := checkFunc(test.want, err); err != nil { - tt.Errorf("error = %v", err) - } - }) - } -} - -func Test_run_Start(t *testing.T) { - type args struct { - ctx context.Context - } - type fields struct { - eg errgroup.Group - cfg *config.Data - server starter.Server - observability observability.Observability - indexer service.Indexer - } - type want struct { - want <-chan error - err error - } - type test struct { - name string - args args - fields fields - want want - checkFunc func(want, <-chan error, error) error - beforeFunc func(args) - afterFunc func(args) - } - defaultCheckFunc := func(w want, got <-chan error, err error) error { - if !errors.Is(err, w.err) { - return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) - } - if !reflect.DeepEqual(got, w.want) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) - } - return nil - } - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - ctx: nil, - }, - fields: fields { - eg: nil, - cfg: nil, - server: nil, - observability: nil, - indexer: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - ctx: nil, - }, - fields: fields { - eg: nil, - cfg: nil, - server: nil, - observability: nil, - indexer: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - checkFunc := test.checkFunc - if test.checkFunc == nil { - checkFunc = defaultCheckFunc - } - r := &run{ - eg: test.fields.eg, - cfg: test.fields.cfg, - server: test.fields.server, - observability: test.fields.observability, - indexer: test.fields.indexer, - } - - got, err := r.Start(test.args.ctx) - if err := checkFunc(test.want, got, err); err != nil { - tt.Errorf("error = %v", err) - } - }) - } -} - -func Test_run_PreStop(t *testing.T) { - type args struct { - ctx context.Context - } - type fields struct { - eg errgroup.Group - cfg *config.Data - server starter.Server - observability observability.Observability - indexer service.Indexer - } - type want struct { - err error - } - type test struct { - name string - args args - fields fields - want want - checkFunc func(want, error) error - beforeFunc func(args) - afterFunc func(args) - } - defaultCheckFunc := func(w want, err error) error { - if !errors.Is(err, w.err) { - return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) - } - return nil - } - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - ctx: nil, - }, - fields: fields { - eg: nil, - cfg: nil, - server: nil, - observability: nil, - indexer: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - ctx: nil, - }, - fields: fields { - eg: nil, - cfg: nil, - server: nil, - observability: nil, - indexer: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - checkFunc := test.checkFunc - if test.checkFunc == nil { - checkFunc = defaultCheckFunc - } - r := &run{ - eg: test.fields.eg, - cfg: test.fields.cfg, - server: test.fields.server, - observability: test.fields.observability, - indexer: test.fields.indexer, - } - - err := r.PreStop(test.args.ctx) - if err := checkFunc(test.want, err); err != nil { - tt.Errorf("error = %v", err) - } - }) - } -} - -func Test_run_Stop(t *testing.T) { - type args struct { - ctx context.Context - } - type fields struct { - eg errgroup.Group - cfg *config.Data - server starter.Server - observability observability.Observability - indexer service.Indexer - } - type want struct { - err error - } - type test struct { - name string - args args - fields fields - want want - checkFunc func(want, error) error - beforeFunc func(args) - afterFunc func(args) - } - defaultCheckFunc := func(w want, err error) error { - if !errors.Is(err, w.err) { - return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) - } - return nil - } - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - ctx: nil, - }, - fields: fields { - eg: nil, - cfg: nil, - server: nil, - observability: nil, - indexer: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - ctx: nil, - }, - fields: fields { - eg: nil, - cfg: nil, - server: nil, - observability: nil, - indexer: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - checkFunc := test.checkFunc - if test.checkFunc == nil { - checkFunc = defaultCheckFunc - } - r := &run{ - eg: test.fields.eg, - cfg: test.fields.cfg, - server: test.fields.server, - observability: test.fields.observability, - indexer: test.fields.indexer, - } - - err := r.Stop(test.args.ctx) - if err := checkFunc(test.want, err); err != nil { - tt.Errorf("error = %v", err) - } - }) - } -} - -func Test_run_PostStop(t *testing.T) { - type args struct { - ctx context.Context - } - type fields struct { - eg errgroup.Group - cfg *config.Data - server starter.Server - observability observability.Observability - indexer service.Indexer - } - type want struct { - err error - } - type test struct { - name string - args args - fields fields - want want - checkFunc func(want, error) error - beforeFunc func(args) - afterFunc func(args) - } - defaultCheckFunc := func(w want, err error) error { - if !errors.Is(err, w.err) { - return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) - } - return nil - } - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - ctx: nil, - }, - fields: fields { - eg: nil, - cfg: nil, - server: nil, - observability: nil, - indexer: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - ctx: nil, - }, - fields: fields { - eg: nil, - cfg: nil, - server: nil, - observability: nil, - indexer: nil, - }, - want: want{}, - checkFunc: defaultCheckFunc, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) - } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - checkFunc := test.checkFunc - if test.checkFunc == nil { - checkFunc = defaultCheckFunc - } - r := &run{ - eg: test.fields.eg, - cfg: test.fields.cfg, - server: test.fields.server, - observability: test.fields.observability, - indexer: test.fields.indexer, - } - - err := r.PostStop(test.args.ctx) - if err := checkFunc(test.want, err); err != nil { - tt.Errorf("error = %v", err) - } - }) - } -} From 9e11d1f230d0816b41086b9c7cac09764ac83f80 Mon Sep 17 00:00:00 2001 From: kevindiu Date: Tue, 22 Nov 2022 10:43:46 +0900 Subject: [PATCH 2/4] regenerate test file for pkg/manager Signed-off-by: kevindiu --- pkg/manager/index/config/config_test.go | 116 ++ .../index/handler/grpc/handler_test.go | 226 +++ pkg/manager/index/handler/grpc/option_test.go | 113 ++ .../index/handler/rest/handler_test.go | 326 +++++ pkg/manager/index/handler/rest/option_test.go | 113 ++ pkg/manager/index/router/option_test.go | 199 +++ pkg/manager/index/router/router_test.go | 113 ++ pkg/manager/index/service/indexer_test.go | 1182 +++++++++++++++ pkg/manager/index/service/indexinfos_test.go | 1296 +++++++++++++++++ pkg/manager/index/service/option_test.go | 802 ++++++++++ pkg/manager/index/usecase/indexer_test.go | 701 +++++++++ 11 files changed, 5187 insertions(+) create mode 100644 pkg/manager/index/config/config_test.go create mode 100644 pkg/manager/index/handler/grpc/handler_test.go create mode 100644 pkg/manager/index/handler/grpc/option_test.go create mode 100644 pkg/manager/index/handler/rest/handler_test.go create mode 100644 pkg/manager/index/handler/rest/option_test.go create mode 100644 pkg/manager/index/router/option_test.go create mode 100644 pkg/manager/index/router/router_test.go create mode 100644 pkg/manager/index/service/indexer_test.go create mode 100644 pkg/manager/index/service/indexinfos_test.go create mode 100644 pkg/manager/index/service/option_test.go create mode 100644 pkg/manager/index/usecase/indexer_test.go diff --git a/pkg/manager/index/config/config_test.go b/pkg/manager/index/config/config_test.go new file mode 100644 index 0000000000..c2e553d3b5 --- /dev/null +++ b/pkg/manager/index/config/config_test.go @@ -0,0 +1,116 @@ +// +// Copyright (C) 2019-2022 vdaas.org vald team +// +// Licensed 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 +// +// https://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 setting stores all server application settings +package config + +import ( + "reflect" + "testing" + + "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/test/goleak" +) + +func TestNewConfig(t *testing.T) { + type args struct { + path string + } + type want struct { + wantCfg *Data + err error + } + type test struct { + name string + args args + want want + checkFunc func(want, *Data, error) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want, gotCfg *Data, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) + } + if !reflect.DeepEqual(gotCfg, w.wantCfg) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", gotCfg, w.wantCfg) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + path: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + path: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + + gotCfg, err := NewConfig(test.args.path) + if err := checkFunc(test.want, gotCfg, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/manager/index/handler/grpc/handler_test.go b/pkg/manager/index/handler/grpc/handler_test.go new file mode 100644 index 0000000000..f85efa27b5 --- /dev/null +++ b/pkg/manager/index/handler/grpc/handler_test.go @@ -0,0 +1,226 @@ +// +// Copyright (C) 2019-2022 vdaas.org vald team +// +// Licensed 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 +// +// https://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 grpc provides grpc server logic +package grpc + +import ( + "context" + "reflect" + "testing" + + "github.com/vdaas/vald/apis/grpc/v1/manager/index" + "github.com/vdaas/vald/apis/grpc/v1/payload" + "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/test/goleak" + "github.com/vdaas/vald/pkg/manager/index/service" +) + +func TestNew(t *testing.T) { + type args struct { + opts []Option + } + type want struct { + want index.IndexServer + } + type test struct { + name string + args args + want want + checkFunc func(want, index.IndexServer) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want, got index.IndexServer) error { + if !reflect.DeepEqual(got, w.want) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + + got := New(test.args.opts...) + if err := checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_server_IndexInfo(t *testing.T) { + type args struct { + ctx context.Context + in1 *payload.Empty + } + type fields struct { + indexer service.Indexer + UnimplementedIndexServer index.UnimplementedIndexServer + } + type want struct { + wantRes *payload.Info_Index_Count + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Info_Index_Count, error) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want, gotRes *payload.Info_Index_Count, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) + } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", gotRes, w.wantRes) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + in1: nil, + }, + fields: fields { + indexer: nil, + UnimplementedIndexServer: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + in1: nil, + }, + fields: fields { + indexer: nil, + UnimplementedIndexServer: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + s := &server{ + indexer: test.fields.indexer, + UnimplementedIndexServer: test.fields.UnimplementedIndexServer, + } + + gotRes, err := s.IndexInfo(test.args.ctx, test.args.in1) + if err := checkFunc(test.want, gotRes, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/manager/index/handler/grpc/option_test.go b/pkg/manager/index/handler/grpc/option_test.go new file mode 100644 index 0000000000..d0efa00d1a --- /dev/null +++ b/pkg/manager/index/handler/grpc/option_test.go @@ -0,0 +1,113 @@ +// +// Copyright (C) 2019-2022 vdaas.org vald team +// +// Licensed 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 +// +// https://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 grpc provides grpc server logic +package grpc + +import ( + "reflect" + "testing" + + "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/test/goleak" + "github.com/vdaas/vald/pkg/manager/index/service" +) + +func TestWithIndexer(t *testing.T) { + type args struct { + i service.Indexer + } + type want struct { + want Option + } + type test struct { + name string + args args + want want + checkFunc func(want, Option) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want, got Option) error { + if !reflect.DeepEqual(got, w.want) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + i: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + i: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + + got := WithIndexer(test.args.i) + if err := checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/manager/index/handler/rest/handler_test.go b/pkg/manager/index/handler/rest/handler_test.go new file mode 100644 index 0000000000..5ff7c5c179 --- /dev/null +++ b/pkg/manager/index/handler/rest/handler_test.go @@ -0,0 +1,326 @@ +// +// Copyright (C) 2019-2022 vdaas.org vald team +// +// Licensed 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 +// +// https://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 rest provides rest api logic +package rest + +import ( + "net/http" + "reflect" + "testing" + + "github.com/vdaas/vald/apis/grpc/v1/manager/index" + "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/test/goleak" +) + +func TestNew(t *testing.T) { + type args struct { + opts []Option + } + type want struct { + want Handler + } + type test struct { + name string + args args + want want + checkFunc func(want, Handler) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want, got Handler) error { + if !reflect.DeepEqual(got, w.want) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + + got := New(test.args.opts...) + if err := checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_Index(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + indexer index.IndexServer + } + type want struct { + want int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want, got int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) + } + if !reflect.DeepEqual(got, w.want) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + indexer: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + indexer: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + h := &handler{ + indexer: test.fields.indexer, + } + + got, err := h.Index(test.args.w, test.args.r) + if err := checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_handler_IndexInfo(t *testing.T) { + type args struct { + w http.ResponseWriter + r *http.Request + } + type fields struct { + indexer index.IndexServer + } + type want struct { + wantCode int + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, int, error) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want, gotCode int, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) + } + if !reflect.DeepEqual(gotCode, w.wantCode) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", gotCode, w.wantCode) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + w: nil, + r: nil, + }, + fields: fields { + indexer: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + w: nil, + r: nil, + }, + fields: fields { + indexer: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + h := &handler{ + indexer: test.fields.indexer, + } + + gotCode, err := h.IndexInfo(test.args.w, test.args.r) + if err := checkFunc(test.want, gotCode, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/manager/index/handler/rest/option_test.go b/pkg/manager/index/handler/rest/option_test.go new file mode 100644 index 0000000000..4cd6a39fd6 --- /dev/null +++ b/pkg/manager/index/handler/rest/option_test.go @@ -0,0 +1,113 @@ +// +// Copyright (C) 2019-2022 vdaas.org vald team +// +// Licensed 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 +// +// https://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 rest provides rest api logic +package rest + +import ( + "reflect" + "testing" + + "github.com/vdaas/vald/apis/grpc/v1/manager/index" + "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/test/goleak" +) + +func TestWithIndexer(t *testing.T) { + type args struct { + i index.IndexServer + } + type want struct { + want Option + } + type test struct { + name string + args args + want want + checkFunc func(want, Option) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want, got Option) error { + if !reflect.DeepEqual(got, w.want) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + i: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + i: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + + got := WithIndexer(test.args.i) + if err := checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/manager/index/router/option_test.go b/pkg/manager/index/router/option_test.go new file mode 100644 index 0000000000..364863d2e1 --- /dev/null +++ b/pkg/manager/index/router/option_test.go @@ -0,0 +1,199 @@ +// +// Copyright (C) 2019-2022 vdaas.org vald team +// +// Licensed 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 +// +// https://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 router provides implementation of Go API for routing http Handler wrapped by rest.Func +package router + +import ( + "reflect" + "testing" + + "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/test/goleak" + "github.com/vdaas/vald/pkg/manager/index/handler/rest" +) + +func TestWithHandler(t *testing.T) { + type args struct { + h rest.Handler + } + type want struct { + want Option + } + type test struct { + name string + args args + want want + checkFunc func(want, Option) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want, got Option) error { + if !reflect.DeepEqual(got, w.want) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + h: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + h: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + + got := WithHandler(test.args.h) + if err := checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func TestWithTimeout(t *testing.T) { + type args struct { + timeout string + } + type want struct { + want Option + } + type test struct { + name string + args args + want want + checkFunc func(want, Option) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want, got Option) error { + if !reflect.DeepEqual(got, w.want) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + timeout: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + timeout: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + + got := WithTimeout(test.args.timeout) + if err := checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/manager/index/router/router_test.go b/pkg/manager/index/router/router_test.go new file mode 100644 index 0000000000..5a078ec665 --- /dev/null +++ b/pkg/manager/index/router/router_test.go @@ -0,0 +1,113 @@ +// +// Copyright (C) 2019-2022 vdaas.org vald team +// +// Licensed 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 +// +// https://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 router provides implementation of Go API for routing http Handler wrapped by rest.Func +package router + +import ( + "net/http" + "reflect" + "testing" + + "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/test/goleak" +) + +func TestNew(t *testing.T) { + type args struct { + opts []Option + } + type want struct { + want http.Handler + } + type test struct { + name string + args args + want want + checkFunc func(want, http.Handler) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want, got http.Handler) error { + if !reflect.DeepEqual(got, w.want) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + + got := New(test.args.opts...) + if err := checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/manager/index/service/indexer_test.go b/pkg/manager/index/service/indexer_test.go new file mode 100644 index 0000000000..8db82c3808 --- /dev/null +++ b/pkg/manager/index/service/indexer_test.go @@ -0,0 +1,1182 @@ +// +// Copyright (C) 2019-2022 vdaas.org vald team +// +// Licensed 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 +// +// https://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 service +package service + +import ( + "context" + "reflect" + "sync" + "sync/atomic" + "testing" + "time" + + "github.com/vdaas/vald/internal/client/v1/client/discoverer" + "github.com/vdaas/vald/internal/errgroup" + "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/test/goleak" +) + +func TestNew(t *testing.T) { + type args struct { + opts []Option + } + type want struct { + wantIdx Indexer + err error + } + type test struct { + name string + args args + want want + checkFunc func(want, Indexer, error) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want, gotIdx Indexer, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) + } + if !reflect.DeepEqual(gotIdx, w.wantIdx) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", gotIdx, w.wantIdx) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + opts: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + + gotIdx, err := New(test.args.opts...) + if err := checkFunc(test.want, gotIdx, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_index_Start(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + client discoverer.Client + eg errgroup.Group + creationPoolSize uint32 + indexDuration time.Duration + indexDurationLimit time.Duration + saveIndexDurationLimit time.Duration + saveIndexWaitDuration time.Duration + saveIndexTargetAddrCh chan string + schMap sync.Map + concurrency int + indexInfos indexInfos + indexing atomic.Value + minUncommitted uint32 + uuidsCount uint32 + uncommittedUUIDsCount uint32 + } + type want struct { + want <-chan error + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, <-chan error, error) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want, got <-chan error, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) + } + if !reflect.DeepEqual(got, w.want) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + }, + fields: fields { + client: nil, + eg: nil, + creationPoolSize: 0, + indexDuration: nil, + indexDurationLimit: nil, + saveIndexDurationLimit: nil, + saveIndexWaitDuration: nil, + saveIndexTargetAddrCh: nil, + schMap: nil, + concurrency: 0, + indexInfos: indexInfos{}, + indexing: nil, + minUncommitted: 0, + uuidsCount: 0, + uncommittedUUIDsCount: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + client: nil, + eg: nil, + creationPoolSize: 0, + indexDuration: nil, + indexDurationLimit: nil, + saveIndexDurationLimit: nil, + saveIndexWaitDuration: nil, + saveIndexTargetAddrCh: nil, + schMap: nil, + concurrency: 0, + indexInfos: indexInfos{}, + indexing: nil, + minUncommitted: 0, + uuidsCount: 0, + uncommittedUUIDsCount: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + idx := &index{ + client: test.fields.client, + eg: test.fields.eg, + creationPoolSize: test.fields.creationPoolSize, + indexDuration: test.fields.indexDuration, + indexDurationLimit: test.fields.indexDurationLimit, + saveIndexDurationLimit: test.fields.saveIndexDurationLimit, + saveIndexWaitDuration: test.fields.saveIndexWaitDuration, + saveIndexTargetAddrCh: test.fields.saveIndexTargetAddrCh, + schMap: test.fields.schMap, + concurrency: test.fields.concurrency, + indexInfos: test.fields.indexInfos, + indexing: test.fields.indexing, + minUncommitted: test.fields.minUncommitted, + uuidsCount: test.fields.uuidsCount, + uncommittedUUIDsCount: test.fields.uncommittedUUIDsCount, + } + + got, err := idx.Start(test.args.ctx) + if err := checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_index_execute(t *testing.T) { + type args struct { + ctx context.Context + enableLowIndexSkip bool + immediateSaving bool + } + type fields struct { + client discoverer.Client + eg errgroup.Group + creationPoolSize uint32 + indexDuration time.Duration + indexDurationLimit time.Duration + saveIndexDurationLimit time.Duration + saveIndexWaitDuration time.Duration + saveIndexTargetAddrCh chan string + schMap sync.Map + concurrency int + indexInfos indexInfos + indexing atomic.Value + minUncommitted uint32 + uuidsCount uint32 + uncommittedUUIDsCount uint32 + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + enableLowIndexSkip: false, + immediateSaving: false, + }, + fields: fields { + client: nil, + eg: nil, + creationPoolSize: 0, + indexDuration: nil, + indexDurationLimit: nil, + saveIndexDurationLimit: nil, + saveIndexWaitDuration: nil, + saveIndexTargetAddrCh: nil, + schMap: nil, + concurrency: 0, + indexInfos: indexInfos{}, + indexing: nil, + minUncommitted: 0, + uuidsCount: 0, + uncommittedUUIDsCount: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + enableLowIndexSkip: false, + immediateSaving: false, + }, + fields: fields { + client: nil, + eg: nil, + creationPoolSize: 0, + indexDuration: nil, + indexDurationLimit: nil, + saveIndexDurationLimit: nil, + saveIndexWaitDuration: nil, + saveIndexTargetAddrCh: nil, + schMap: nil, + concurrency: 0, + indexInfos: indexInfos{}, + indexing: nil, + minUncommitted: 0, + uuidsCount: 0, + uncommittedUUIDsCount: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + idx := &index{ + client: test.fields.client, + eg: test.fields.eg, + creationPoolSize: test.fields.creationPoolSize, + indexDuration: test.fields.indexDuration, + indexDurationLimit: test.fields.indexDurationLimit, + saveIndexDurationLimit: test.fields.saveIndexDurationLimit, + saveIndexWaitDuration: test.fields.saveIndexWaitDuration, + saveIndexTargetAddrCh: test.fields.saveIndexTargetAddrCh, + schMap: test.fields.schMap, + concurrency: test.fields.concurrency, + indexInfos: test.fields.indexInfos, + indexing: test.fields.indexing, + minUncommitted: test.fields.minUncommitted, + uuidsCount: test.fields.uuidsCount, + uncommittedUUIDsCount: test.fields.uncommittedUUIDsCount, + } + + err := idx.execute(test.args.ctx, test.args.enableLowIndexSkip, test.args.immediateSaving) + if err := checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_index_waitForNextSaving(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + client discoverer.Client + eg errgroup.Group + creationPoolSize uint32 + indexDuration time.Duration + indexDurationLimit time.Duration + saveIndexDurationLimit time.Duration + saveIndexWaitDuration time.Duration + saveIndexTargetAddrCh chan string + schMap sync.Map + concurrency int + indexInfos indexInfos + indexing atomic.Value + minUncommitted uint32 + uuidsCount uint32 + uncommittedUUIDsCount uint32 + } + type want struct { + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want) error { + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + }, + fields: fields { + client: nil, + eg: nil, + creationPoolSize: 0, + indexDuration: nil, + indexDurationLimit: nil, + saveIndexDurationLimit: nil, + saveIndexWaitDuration: nil, + saveIndexTargetAddrCh: nil, + schMap: nil, + concurrency: 0, + indexInfos: indexInfos{}, + indexing: nil, + minUncommitted: 0, + uuidsCount: 0, + uncommittedUUIDsCount: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + client: nil, + eg: nil, + creationPoolSize: 0, + indexDuration: nil, + indexDurationLimit: nil, + saveIndexDurationLimit: nil, + saveIndexWaitDuration: nil, + saveIndexTargetAddrCh: nil, + schMap: nil, + concurrency: 0, + indexInfos: indexInfos{}, + indexing: nil, + minUncommitted: 0, + uuidsCount: 0, + uncommittedUUIDsCount: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + idx := &index{ + client: test.fields.client, + eg: test.fields.eg, + creationPoolSize: test.fields.creationPoolSize, + indexDuration: test.fields.indexDuration, + indexDurationLimit: test.fields.indexDurationLimit, + saveIndexDurationLimit: test.fields.saveIndexDurationLimit, + saveIndexWaitDuration: test.fields.saveIndexWaitDuration, + saveIndexTargetAddrCh: test.fields.saveIndexTargetAddrCh, + schMap: test.fields.schMap, + concurrency: test.fields.concurrency, + indexInfos: test.fields.indexInfos, + indexing: test.fields.indexing, + minUncommitted: test.fields.minUncommitted, + uuidsCount: test.fields.uuidsCount, + uncommittedUUIDsCount: test.fields.uncommittedUUIDsCount, + } + + idx.waitForNextSaving(test.args.ctx) + if err := checkFunc(test.want); err != nil { + tt.Errorf("error = %v", err) + } + }) + } +} + +func Test_index_loadInfos(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + client discoverer.Client + eg errgroup.Group + creationPoolSize uint32 + indexDuration time.Duration + indexDurationLimit time.Duration + saveIndexDurationLimit time.Duration + saveIndexWaitDuration time.Duration + saveIndexTargetAddrCh chan string + schMap sync.Map + concurrency int + indexInfos indexInfos + indexing atomic.Value + minUncommitted uint32 + uuidsCount uint32 + uncommittedUUIDsCount uint32 + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + }, + fields: fields { + client: nil, + eg: nil, + creationPoolSize: 0, + indexDuration: nil, + indexDurationLimit: nil, + saveIndexDurationLimit: nil, + saveIndexWaitDuration: nil, + saveIndexTargetAddrCh: nil, + schMap: nil, + concurrency: 0, + indexInfos: indexInfos{}, + indexing: nil, + minUncommitted: 0, + uuidsCount: 0, + uncommittedUUIDsCount: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + client: nil, + eg: nil, + creationPoolSize: 0, + indexDuration: nil, + indexDurationLimit: nil, + saveIndexDurationLimit: nil, + saveIndexWaitDuration: nil, + saveIndexTargetAddrCh: nil, + schMap: nil, + concurrency: 0, + indexInfos: indexInfos{}, + indexing: nil, + minUncommitted: 0, + uuidsCount: 0, + uncommittedUUIDsCount: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + idx := &index{ + client: test.fields.client, + eg: test.fields.eg, + creationPoolSize: test.fields.creationPoolSize, + indexDuration: test.fields.indexDuration, + indexDurationLimit: test.fields.indexDurationLimit, + saveIndexDurationLimit: test.fields.saveIndexDurationLimit, + saveIndexWaitDuration: test.fields.saveIndexWaitDuration, + saveIndexTargetAddrCh: test.fields.saveIndexTargetAddrCh, + schMap: test.fields.schMap, + concurrency: test.fields.concurrency, + indexInfos: test.fields.indexInfos, + indexing: test.fields.indexing, + minUncommitted: test.fields.minUncommitted, + uuidsCount: test.fields.uuidsCount, + uncommittedUUIDsCount: test.fields.uncommittedUUIDsCount, + } + + err := idx.loadInfos(test.args.ctx) + if err := checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_index_IsIndexing(t *testing.T) { + type fields struct { + client discoverer.Client + eg errgroup.Group + creationPoolSize uint32 + indexDuration time.Duration + indexDurationLimit time.Duration + saveIndexDurationLimit time.Duration + saveIndexWaitDuration time.Duration + saveIndexTargetAddrCh chan string + schMap sync.Map + concurrency int + indexInfos indexInfos + indexing atomic.Value + minUncommitted uint32 + uuidsCount uint32 + uncommittedUUIDsCount uint32 + } + type want struct { + want bool + } + type test struct { + name string + fields fields + want want + checkFunc func(want, bool) error + beforeFunc func(*testing.T) + afterFunc func(*testing.T) + } + defaultCheckFunc := func(w want, got bool) error { + if !reflect.DeepEqual(got, w.want) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + fields: fields { + client: nil, + eg: nil, + creationPoolSize: 0, + indexDuration: nil, + indexDurationLimit: nil, + saveIndexDurationLimit: nil, + saveIndexWaitDuration: nil, + saveIndexTargetAddrCh: nil, + schMap: nil, + concurrency: 0, + indexInfos: indexInfos{}, + indexing: nil, + minUncommitted: 0, + uuidsCount: 0, + uncommittedUUIDsCount: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + fields: fields { + client: nil, + eg: nil, + creationPoolSize: 0, + indexDuration: nil, + indexDurationLimit: nil, + saveIndexDurationLimit: nil, + saveIndexWaitDuration: nil, + saveIndexTargetAddrCh: nil, + schMap: nil, + concurrency: 0, + indexInfos: indexInfos{}, + indexing: nil, + minUncommitted: 0, + uuidsCount: 0, + uncommittedUUIDsCount: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt) + } + if test.afterFunc != nil { + defer test.afterFunc(tt) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + idx := &index{ + client: test.fields.client, + eg: test.fields.eg, + creationPoolSize: test.fields.creationPoolSize, + indexDuration: test.fields.indexDuration, + indexDurationLimit: test.fields.indexDurationLimit, + saveIndexDurationLimit: test.fields.saveIndexDurationLimit, + saveIndexWaitDuration: test.fields.saveIndexWaitDuration, + saveIndexTargetAddrCh: test.fields.saveIndexTargetAddrCh, + schMap: test.fields.schMap, + concurrency: test.fields.concurrency, + indexInfos: test.fields.indexInfos, + indexing: test.fields.indexing, + minUncommitted: test.fields.minUncommitted, + uuidsCount: test.fields.uuidsCount, + uncommittedUUIDsCount: test.fields.uncommittedUUIDsCount, + } + + got := idx.IsIndexing() + if err := checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_index_NumberOfUUIDs(t *testing.T) { + type fields struct { + client discoverer.Client + eg errgroup.Group + creationPoolSize uint32 + indexDuration time.Duration + indexDurationLimit time.Duration + saveIndexDurationLimit time.Duration + saveIndexWaitDuration time.Duration + saveIndexTargetAddrCh chan string + schMap sync.Map + concurrency int + indexInfos indexInfos + indexing atomic.Value + minUncommitted uint32 + uuidsCount uint32 + uncommittedUUIDsCount uint32 + } + type want struct { + want uint32 + } + type test struct { + name string + fields fields + want want + checkFunc func(want, uint32) error + beforeFunc func(*testing.T) + afterFunc func(*testing.T) + } + defaultCheckFunc := func(w want, got uint32) error { + if !reflect.DeepEqual(got, w.want) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + fields: fields { + client: nil, + eg: nil, + creationPoolSize: 0, + indexDuration: nil, + indexDurationLimit: nil, + saveIndexDurationLimit: nil, + saveIndexWaitDuration: nil, + saveIndexTargetAddrCh: nil, + schMap: nil, + concurrency: 0, + indexInfos: indexInfos{}, + indexing: nil, + minUncommitted: 0, + uuidsCount: 0, + uncommittedUUIDsCount: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + fields: fields { + client: nil, + eg: nil, + creationPoolSize: 0, + indexDuration: nil, + indexDurationLimit: nil, + saveIndexDurationLimit: nil, + saveIndexWaitDuration: nil, + saveIndexTargetAddrCh: nil, + schMap: nil, + concurrency: 0, + indexInfos: indexInfos{}, + indexing: nil, + minUncommitted: 0, + uuidsCount: 0, + uncommittedUUIDsCount: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt) + } + if test.afterFunc != nil { + defer test.afterFunc(tt) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + idx := &index{ + client: test.fields.client, + eg: test.fields.eg, + creationPoolSize: test.fields.creationPoolSize, + indexDuration: test.fields.indexDuration, + indexDurationLimit: test.fields.indexDurationLimit, + saveIndexDurationLimit: test.fields.saveIndexDurationLimit, + saveIndexWaitDuration: test.fields.saveIndexWaitDuration, + saveIndexTargetAddrCh: test.fields.saveIndexTargetAddrCh, + schMap: test.fields.schMap, + concurrency: test.fields.concurrency, + indexInfos: test.fields.indexInfos, + indexing: test.fields.indexing, + minUncommitted: test.fields.minUncommitted, + uuidsCount: test.fields.uuidsCount, + uncommittedUUIDsCount: test.fields.uncommittedUUIDsCount, + } + + got := idx.NumberOfUUIDs() + if err := checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_index_NumberOfUncommittedUUIDs(t *testing.T) { + type fields struct { + client discoverer.Client + eg errgroup.Group + creationPoolSize uint32 + indexDuration time.Duration + indexDurationLimit time.Duration + saveIndexDurationLimit time.Duration + saveIndexWaitDuration time.Duration + saveIndexTargetAddrCh chan string + schMap sync.Map + concurrency int + indexInfos indexInfos + indexing atomic.Value + minUncommitted uint32 + uuidsCount uint32 + uncommittedUUIDsCount uint32 + } + type want struct { + want uint32 + } + type test struct { + name string + fields fields + want want + checkFunc func(want, uint32) error + beforeFunc func(*testing.T) + afterFunc func(*testing.T) + } + defaultCheckFunc := func(w want, got uint32) error { + if !reflect.DeepEqual(got, w.want) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + fields: fields { + client: nil, + eg: nil, + creationPoolSize: 0, + indexDuration: nil, + indexDurationLimit: nil, + saveIndexDurationLimit: nil, + saveIndexWaitDuration: nil, + saveIndexTargetAddrCh: nil, + schMap: nil, + concurrency: 0, + indexInfos: indexInfos{}, + indexing: nil, + minUncommitted: 0, + uuidsCount: 0, + uncommittedUUIDsCount: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + fields: fields { + client: nil, + eg: nil, + creationPoolSize: 0, + indexDuration: nil, + indexDurationLimit: nil, + saveIndexDurationLimit: nil, + saveIndexWaitDuration: nil, + saveIndexTargetAddrCh: nil, + schMap: nil, + concurrency: 0, + indexInfos: indexInfos{}, + indexing: nil, + minUncommitted: 0, + uuidsCount: 0, + uncommittedUUIDsCount: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt) + } + if test.afterFunc != nil { + defer test.afterFunc(tt) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + idx := &index{ + client: test.fields.client, + eg: test.fields.eg, + creationPoolSize: test.fields.creationPoolSize, + indexDuration: test.fields.indexDuration, + indexDurationLimit: test.fields.indexDurationLimit, + saveIndexDurationLimit: test.fields.saveIndexDurationLimit, + saveIndexWaitDuration: test.fields.saveIndexWaitDuration, + saveIndexTargetAddrCh: test.fields.saveIndexTargetAddrCh, + schMap: test.fields.schMap, + concurrency: test.fields.concurrency, + indexInfos: test.fields.indexInfos, + indexing: test.fields.indexing, + minUncommitted: test.fields.minUncommitted, + uuidsCount: test.fields.uuidsCount, + uncommittedUUIDsCount: test.fields.uncommittedUUIDsCount, + } + + got := idx.NumberOfUncommittedUUIDs() + if err := checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/manager/index/service/indexinfos_test.go b/pkg/manager/index/service/indexinfos_test.go new file mode 100644 index 0000000000..91153189db --- /dev/null +++ b/pkg/manager/index/service/indexinfos_test.go @@ -0,0 +1,1296 @@ +// +// Copyright (C) 2019-2022 vdaas.org vald team +// +// Licensed 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 +// +// https://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 service + +import ( + "reflect" + "sync" + "sync/atomic" + "testing" + "unsafe" + + "github.com/vdaas/vald/apis/grpc/v1/payload" + "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/test/goleak" +) + +func Test_newEntryIndexInfos(t *testing.T) { + type args struct { + i *payload.Info_Index_Count + } + type want struct { + want *entryIndexInfos + } + type test struct { + name string + args args + want want + checkFunc func(want, *entryIndexInfos) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want, got *entryIndexInfos) error { + if !reflect.DeepEqual(got, w.want) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + i: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + i: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + + got := newEntryIndexInfos(test.args.i) + if err := checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_indexInfos_Load(t *testing.T) { + type args struct { + key string + } + type fields struct { + mu sync.Mutex + read atomic.Value + dirty map[string]*entryIndexInfos + misses int + } + type want struct { + wantValue *payload.Info_Index_Count + wantOk bool + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, *payload.Info_Index_Count, bool) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want, gotValue *payload.Info_Index_Count, gotOk bool) error { + if !reflect.DeepEqual(gotValue, w.wantValue) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", gotValue, w.wantValue) + } + if !reflect.DeepEqual(gotOk, w.wantOk) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", gotOk, w.wantOk) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + key: "", + }, + fields: fields { + mu: nil, + read: nil, + dirty: nil, + misses: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + key: "", + }, + fields: fields { + mu: nil, + read: nil, + dirty: nil, + misses: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + m := &indexInfos{ + mu: test.fields.mu, + read: test.fields.read, + dirty: test.fields.dirty, + misses: test.fields.misses, + } + + gotValue, gotOk := m.Load(test.args.key) + if err := checkFunc(test.want, gotValue, gotOk); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_entryIndexInfos_load(t *testing.T) { + type fields struct { + p unsafe.Pointer + } + type want struct { + wantValue *payload.Info_Index_Count + wantOk bool + } + type test struct { + name string + fields fields + want want + checkFunc func(want, *payload.Info_Index_Count, bool) error + beforeFunc func(*testing.T) + afterFunc func(*testing.T) + } + defaultCheckFunc := func(w want, gotValue *payload.Info_Index_Count, gotOk bool) error { + if !reflect.DeepEqual(gotValue, w.wantValue) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", gotValue, w.wantValue) + } + if !reflect.DeepEqual(gotOk, w.wantOk) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", gotOk, w.wantOk) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + fields: fields { + p: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + fields: fields { + p: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt) + } + if test.afterFunc != nil { + defer test.afterFunc(tt) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + e := &entryIndexInfos{ + p: test.fields.p, + } + + gotValue, gotOk := e.load() + if err := checkFunc(test.want, gotValue, gotOk); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_indexInfos_Store(t *testing.T) { + type args struct { + key string + value *payload.Info_Index_Count + } + type fields struct { + mu sync.Mutex + read atomic.Value + dirty map[string]*entryIndexInfos + misses int + } + type want struct { + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want) error { + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + key: "", + value: nil, + }, + fields: fields { + mu: nil, + read: nil, + dirty: nil, + misses: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + key: "", + value: nil, + }, + fields: fields { + mu: nil, + read: nil, + dirty: nil, + misses: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + m := &indexInfos{ + mu: test.fields.mu, + read: test.fields.read, + dirty: test.fields.dirty, + misses: test.fields.misses, + } + + m.Store(test.args.key, test.args.value) + if err := checkFunc(test.want); err != nil { + tt.Errorf("error = %v", err) + } + }) + } +} + +func Test_entryIndexInfos_tryStore(t *testing.T) { + type args struct { + i **payload.Info_Index_Count + } + type fields struct { + p unsafe.Pointer + } + type want struct { + want bool + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, bool) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want, got bool) error { + if !reflect.DeepEqual(got, w.want) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + i: nil, + }, + fields: fields { + p: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + i: nil, + }, + fields: fields { + p: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + e := &entryIndexInfos{ + p: test.fields.p, + } + + got := e.tryStore(test.args.i) + if err := checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_entryIndexInfos_unexpungeLocked(t *testing.T) { + type fields struct { + p unsafe.Pointer + } + type want struct { + wantWasExpunged bool + } + type test struct { + name string + fields fields + want want + checkFunc func(want, bool) error + beforeFunc func(*testing.T) + afterFunc func(*testing.T) + } + defaultCheckFunc := func(w want, gotWasExpunged bool) error { + if !reflect.DeepEqual(gotWasExpunged, w.wantWasExpunged) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", gotWasExpunged, w.wantWasExpunged) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + fields: fields { + p: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + fields: fields { + p: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt) + } + if test.afterFunc != nil { + defer test.afterFunc(tt) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + e := &entryIndexInfos{ + p: test.fields.p, + } + + gotWasExpunged := e.unexpungeLocked() + if err := checkFunc(test.want, gotWasExpunged); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_entryIndexInfos_storeLocked(t *testing.T) { + type args struct { + i **payload.Info_Index_Count + } + type fields struct { + p unsafe.Pointer + } + type want struct { + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want) error { + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + i: nil, + }, + fields: fields { + p: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + i: nil, + }, + fields: fields { + p: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + e := &entryIndexInfos{ + p: test.fields.p, + } + + e.storeLocked(test.args.i) + if err := checkFunc(test.want); err != nil { + tt.Errorf("error = %v", err) + } + }) + } +} + +func Test_indexInfos_Delete(t *testing.T) { + type args struct { + key string + } + type fields struct { + mu sync.Mutex + read atomic.Value + dirty map[string]*entryIndexInfos + misses int + } + type want struct { + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want) error { + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + key: "", + }, + fields: fields { + mu: nil, + read: nil, + dirty: nil, + misses: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + key: "", + }, + fields: fields { + mu: nil, + read: nil, + dirty: nil, + misses: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + m := &indexInfos{ + mu: test.fields.mu, + read: test.fields.read, + dirty: test.fields.dirty, + misses: test.fields.misses, + } + + m.Delete(test.args.key) + if err := checkFunc(test.want); err != nil { + tt.Errorf("error = %v", err) + } + }) + } +} + +func Test_entryIndexInfos_delete(t *testing.T) { + type fields struct { + p unsafe.Pointer + } + type want struct { + wantHadValue bool + } + type test struct { + name string + fields fields + want want + checkFunc func(want, bool) error + beforeFunc func(*testing.T) + afterFunc func(*testing.T) + } + defaultCheckFunc := func(w want, gotHadValue bool) error { + if !reflect.DeepEqual(gotHadValue, w.wantHadValue) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", gotHadValue, w.wantHadValue) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + fields: fields { + p: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + fields: fields { + p: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt) + } + if test.afterFunc != nil { + defer test.afterFunc(tt) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + e := &entryIndexInfos{ + p: test.fields.p, + } + + gotHadValue := e.delete() + if err := checkFunc(test.want, gotHadValue); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_indexInfos_Range(t *testing.T) { + type args struct { + f func(key string, value *payload.Info_Index_Count) bool + } + type fields struct { + mu sync.Mutex + read atomic.Value + dirty map[string]*entryIndexInfos + misses int + } + type want struct { + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want) error { + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + f: nil, + }, + fields: fields { + mu: nil, + read: nil, + dirty: nil, + misses: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + f: nil, + }, + fields: fields { + mu: nil, + read: nil, + dirty: nil, + misses: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + m := &indexInfos{ + mu: test.fields.mu, + read: test.fields.read, + dirty: test.fields.dirty, + misses: test.fields.misses, + } + + m.Range(test.args.f) + if err := checkFunc(test.want); err != nil { + tt.Errorf("error = %v", err) + } + }) + } +} + +func Test_indexInfos_missLocked(t *testing.T) { + type fields struct { + mu sync.Mutex + read atomic.Value + dirty map[string]*entryIndexInfos + misses int + } + type want struct { + } + type test struct { + name string + fields fields + want want + checkFunc func(want) error + beforeFunc func(*testing.T) + afterFunc func(*testing.T) + } + defaultCheckFunc := func(w want) error { + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + fields: fields { + mu: nil, + read: nil, + dirty: nil, + misses: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + fields: fields { + mu: nil, + read: nil, + dirty: nil, + misses: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt) + } + if test.afterFunc != nil { + defer test.afterFunc(tt) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + m := &indexInfos{ + mu: test.fields.mu, + read: test.fields.read, + dirty: test.fields.dirty, + misses: test.fields.misses, + } + + m.missLocked() + if err := checkFunc(test.want); err != nil { + tt.Errorf("error = %v", err) + } + }) + } +} + +func Test_indexInfos_dirtyLocked(t *testing.T) { + type fields struct { + mu sync.Mutex + read atomic.Value + dirty map[string]*entryIndexInfos + misses int + } + type want struct { + } + type test struct { + name string + fields fields + want want + checkFunc func(want) error + beforeFunc func(*testing.T) + afterFunc func(*testing.T) + } + defaultCheckFunc := func(w want) error { + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + fields: fields { + mu: nil, + read: nil, + dirty: nil, + misses: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + fields: fields { + mu: nil, + read: nil, + dirty: nil, + misses: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt) + } + if test.afterFunc != nil { + defer test.afterFunc(tt) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + m := &indexInfos{ + mu: test.fields.mu, + read: test.fields.read, + dirty: test.fields.dirty, + misses: test.fields.misses, + } + + m.dirtyLocked() + if err := checkFunc(test.want); err != nil { + tt.Errorf("error = %v", err) + } + }) + } +} + +func Test_entryIndexInfos_tryExpungeLocked(t *testing.T) { + type fields struct { + p unsafe.Pointer + } + type want struct { + wantIsExpunged bool + } + type test struct { + name string + fields fields + want want + checkFunc func(want, bool) error + beforeFunc func(*testing.T) + afterFunc func(*testing.T) + } + defaultCheckFunc := func(w want, gotIsExpunged bool) error { + if !reflect.DeepEqual(gotIsExpunged, w.wantIsExpunged) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", gotIsExpunged, w.wantIsExpunged) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + fields: fields { + p: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + fields: fields { + p: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt) + } + if test.afterFunc != nil { + defer test.afterFunc(tt) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + e := &entryIndexInfos{ + p: test.fields.p, + } + + gotIsExpunged := e.tryExpungeLocked() + if err := checkFunc(test.want, gotIsExpunged); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/manager/index/service/option_test.go b/pkg/manager/index/service/option_test.go new file mode 100644 index 0000000000..b0a21cb9cb --- /dev/null +++ b/pkg/manager/index/service/option_test.go @@ -0,0 +1,802 @@ +// +// Copyright (C) 2019-2022 vdaas.org vald team +// +// Licensed 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 +// +// https://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 service +package service + +import ( + "reflect" + "testing" + + "github.com/vdaas/vald/internal/client/v1/client/discoverer" + "github.com/vdaas/vald/internal/errgroup" + "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/test/goleak" +) + +func TestWithIndexingConcurrency(t *testing.T) { + type args struct { + c int + } + type want struct { + want Option + } + type test struct { + name string + args args + want want + checkFunc func(want, Option) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want, got Option) error { + if !reflect.DeepEqual(got, w.want) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + c: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + c: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + + got := WithIndexingConcurrency(test.args.c) + if err := checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func TestWithIndexingDuration(t *testing.T) { + type args struct { + dur string + } + type want struct { + want Option + } + type test struct { + name string + args args + want want + checkFunc func(want, Option) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want, got Option) error { + if !reflect.DeepEqual(got, w.want) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + dur: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + dur: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + + got := WithIndexingDuration(test.args.dur) + if err := checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func TestWithIndexingDurationLimit(t *testing.T) { + type args struct { + dur string + } + type want struct { + want Option + } + type test struct { + name string + args args + want want + checkFunc func(want, Option) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want, got Option) error { + if !reflect.DeepEqual(got, w.want) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + dur: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + dur: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + + got := WithIndexingDurationLimit(test.args.dur) + if err := checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func TestWithSaveIndexDurationLimit(t *testing.T) { + type args struct { + dur string + } + type want struct { + want Option + } + type test struct { + name string + args args + want want + checkFunc func(want, Option) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want, got Option) error { + if !reflect.DeepEqual(got, w.want) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + dur: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + dur: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + + got := WithSaveIndexDurationLimit(test.args.dur) + if err := checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func TestWithSaveIndexWaitDuration(t *testing.T) { + type args struct { + dur string + } + type want struct { + want Option + } + type test struct { + name string + args args + want want + checkFunc func(want, Option) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want, got Option) error { + if !reflect.DeepEqual(got, w.want) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + dur: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + dur: "", + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + + got := WithSaveIndexWaitDuration(test.args.dur) + if err := checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func TestWithMinUncommitted(t *testing.T) { + type args struct { + n uint32 + } + type want struct { + want Option + } + type test struct { + name string + args args + want want + checkFunc func(want, Option) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want, got Option) error { + if !reflect.DeepEqual(got, w.want) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + n: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + n: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + + got := WithMinUncommitted(test.args.n) + if err := checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func TestWithCreationPoolSize(t *testing.T) { + type args struct { + size uint32 + } + type want struct { + want Option + } + type test struct { + name string + args args + want want + checkFunc func(want, Option) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want, got Option) error { + if !reflect.DeepEqual(got, w.want) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + size: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + size: 0, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + + got := WithCreationPoolSize(test.args.size) + if err := checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func TestWithDiscoverer(t *testing.T) { + type args struct { + c discoverer.Client + } + type want struct { + want Option + } + type test struct { + name string + args args + want want + checkFunc func(want, Option) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want, got Option) error { + if !reflect.DeepEqual(got, w.want) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + c: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + c: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + + got := WithDiscoverer(test.args.c) + if err := checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func TestWithErrGroup(t *testing.T) { + type args struct { + eg errgroup.Group + } + type want struct { + want Option + } + type test struct { + name string + args args + want want + checkFunc func(want, Option) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want, got Option) error { + if !reflect.DeepEqual(got, w.want) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + eg: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + eg: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + + got := WithErrGroup(test.args.eg) + if err := checkFunc(test.want, got); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} diff --git a/pkg/manager/index/usecase/indexer_test.go b/pkg/manager/index/usecase/indexer_test.go new file mode 100644 index 0000000000..122fdab9bc --- /dev/null +++ b/pkg/manager/index/usecase/indexer_test.go @@ -0,0 +1,701 @@ +// +// Copyright (C) 2019-2022 vdaas.org vald team +// +// Licensed 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 +// +// https://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 usecase + +import ( + "context" + "reflect" + "testing" + + "github.com/vdaas/vald/internal/errgroup" + "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/observability" + "github.com/vdaas/vald/internal/runner" + "github.com/vdaas/vald/internal/servers/starter" + "github.com/vdaas/vald/internal/test/goleak" + "github.com/vdaas/vald/pkg/manager/index/config" + "github.com/vdaas/vald/pkg/manager/index/service" +) + +func TestNew(t *testing.T) { + type args struct { + cfg *config.Data + } + type want struct { + wantR runner.Runner + err error + } + type test struct { + name string + args args + want want + checkFunc func(want, runner.Runner, error) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want, gotR runner.Runner, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) + } + if !reflect.DeepEqual(gotR, w.wantR) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", gotR, w.wantR) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + cfg: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + cfg: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + + gotR, err := New(test.args.cfg) + if err := checkFunc(test.want, gotR, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_run_PreStart(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + eg errgroup.Group + cfg *config.Data + server starter.Server + observability observability.Observability + indexer service.Indexer + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + indexer: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + indexer: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + r := &run{ + eg: test.fields.eg, + cfg: test.fields.cfg, + server: test.fields.server, + observability: test.fields.observability, + indexer: test.fields.indexer, + } + + err := r.PreStart(test.args.ctx) + if err := checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_run_Start(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + eg errgroup.Group + cfg *config.Data + server starter.Server + observability observability.Observability + indexer service.Indexer + } + type want struct { + want <-chan error + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, <-chan error, error) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want, got <-chan error, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) + } + if !reflect.DeepEqual(got, w.want) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + indexer: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + indexer: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + r := &run{ + eg: test.fields.eg, + cfg: test.fields.cfg, + server: test.fields.server, + observability: test.fields.observability, + indexer: test.fields.indexer, + } + + got, err := r.Start(test.args.ctx) + if err := checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_run_PreStop(t *testing.T) { + type args struct { + in0 context.Context + } + type fields struct { + eg errgroup.Group + cfg *config.Data + server starter.Server + observability observability.Observability + indexer service.Indexer + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + in0: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + indexer: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + in0: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + indexer: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + r := &run{ + eg: test.fields.eg, + cfg: test.fields.cfg, + server: test.fields.server, + observability: test.fields.observability, + indexer: test.fields.indexer, + } + + err := r.PreStop(test.args.in0) + if err := checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_run_Stop(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + eg errgroup.Group + cfg *config.Data + server starter.Server + observability observability.Observability + indexer service.Indexer + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + indexer: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + indexer: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + r := &run{ + eg: test.fields.eg, + cfg: test.fields.cfg, + server: test.fields.server, + observability: test.fields.observability, + indexer: test.fields.indexer, + } + + err := r.Stop(test.args.ctx) + if err := checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_run_PostStop(t *testing.T) { + type args struct { + in0 context.Context + } + type fields struct { + eg errgroup.Group + cfg *config.Data + server starter.Server + observability observability.Observability + indexer service.Indexer + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + in0: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + indexer: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + in0: nil, + }, + fields: fields { + eg: nil, + cfg: nil, + server: nil, + observability: nil, + indexer: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, + } + }(), + */ + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc != nil { + test.beforeFunc(tt, test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + r := &run{ + eg: test.fields.eg, + cfg: test.fields.cfg, + server: test.fields.server, + observability: test.fields.observability, + indexer: test.fields.indexer, + } + + err := r.PostStop(test.args.in0) + if err := checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} From 08454eaf042bc12c08bf9600a9630e145139a79e Mon Sep 17 00:00:00 2001 From: kevindiu Date: Tue, 22 Nov 2022 11:27:16 +0900 Subject: [PATCH 3/4] fix deepsource Signed-off-by: kevindiu --- pkg/manager/index/config/config_test.go | 1 - .../index/handler/grpc/handler_test.go | 2 - pkg/manager/index/handler/grpc/option_test.go | 1 - .../index/handler/rest/handler_test.go | 3 -- pkg/manager/index/handler/rest/option_test.go | 1 - pkg/manager/index/router/option_test.go | 2 - pkg/manager/index/router/router_test.go | 1 - pkg/manager/index/service/indexer_test.go | 38 ++++++++----------- pkg/manager/index/service/indexinfos_test.go | 38 +++---------------- pkg/manager/index/service/option_test.go | 9 ----- pkg/manager/index/usecase/indexer_test.go | 6 --- 11 files changed, 21 insertions(+), 81 deletions(-) diff --git a/pkg/manager/index/config/config_test.go b/pkg/manager/index/config/config_test.go index c2e553d3b5..96b7fe013b 100644 --- a/pkg/manager/index/config/config_test.go +++ b/pkg/manager/index/config/config_test.go @@ -110,7 +110,6 @@ func TestNewConfig(t *testing.T) { if err := checkFunc(test.want, gotCfg, err); err != nil { tt.Errorf("error = %v", err) } - }) } } diff --git a/pkg/manager/index/handler/grpc/handler_test.go b/pkg/manager/index/handler/grpc/handler_test.go index f85efa27b5..ff68fe79a0 100644 --- a/pkg/manager/index/handler/grpc/handler_test.go +++ b/pkg/manager/index/handler/grpc/handler_test.go @@ -110,7 +110,6 @@ func TestNew(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -220,7 +219,6 @@ func Test_server_IndexInfo(t *testing.T) { if err := checkFunc(test.want, gotRes, err); err != nil { tt.Errorf("error = %v", err) } - }) } } diff --git a/pkg/manager/index/handler/grpc/option_test.go b/pkg/manager/index/handler/grpc/option_test.go index d0efa00d1a..798c3b7c9c 100644 --- a/pkg/manager/index/handler/grpc/option_test.go +++ b/pkg/manager/index/handler/grpc/option_test.go @@ -107,7 +107,6 @@ func TestWithIndexer(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } - }) } } diff --git a/pkg/manager/index/handler/rest/handler_test.go b/pkg/manager/index/handler/rest/handler_test.go index 5ff7c5c179..b92536727f 100644 --- a/pkg/manager/index/handler/rest/handler_test.go +++ b/pkg/manager/index/handler/rest/handler_test.go @@ -108,7 +108,6 @@ func TestNew(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -214,7 +213,6 @@ func Test_handler_Index(t *testing.T) { if err := checkFunc(test.want, got, err); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -320,7 +318,6 @@ func Test_handler_IndexInfo(t *testing.T) { if err := checkFunc(test.want, gotCode, err); err != nil { tt.Errorf("error = %v", err) } - }) } } diff --git a/pkg/manager/index/handler/rest/option_test.go b/pkg/manager/index/handler/rest/option_test.go index 4cd6a39fd6..f850c7f5db 100644 --- a/pkg/manager/index/handler/rest/option_test.go +++ b/pkg/manager/index/handler/rest/option_test.go @@ -107,7 +107,6 @@ func TestWithIndexer(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } - }) } } diff --git a/pkg/manager/index/router/option_test.go b/pkg/manager/index/router/option_test.go index 364863d2e1..5f5ace0704 100644 --- a/pkg/manager/index/router/option_test.go +++ b/pkg/manager/index/router/option_test.go @@ -107,7 +107,6 @@ func TestWithHandler(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -193,7 +192,6 @@ func TestWithTimeout(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } - }) } } diff --git a/pkg/manager/index/router/router_test.go b/pkg/manager/index/router/router_test.go index 5a078ec665..04ef78a10b 100644 --- a/pkg/manager/index/router/router_test.go +++ b/pkg/manager/index/router/router_test.go @@ -107,7 +107,6 @@ func TestNew(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } - }) } } diff --git a/pkg/manager/index/service/indexer_test.go b/pkg/manager/index/service/indexer_test.go index 8db82c3808..fa9a4b753a 100644 --- a/pkg/manager/index/service/indexer_test.go +++ b/pkg/manager/index/service/indexer_test.go @@ -116,7 +116,6 @@ func TestNew(t *testing.T) { if err := checkFunc(test.want, gotIdx, err); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -136,7 +135,7 @@ func Test_index_Start(t *testing.T) { saveIndexTargetAddrCh chan string schMap sync.Map concurrency int - indexInfos indexInfos + indexInfos func() indexInfos indexing atomic.Value minUncommitted uint32 uuidsCount uint32 @@ -264,7 +263,7 @@ func Test_index_Start(t *testing.T) { saveIndexTargetAddrCh: test.fields.saveIndexTargetAddrCh, schMap: test.fields.schMap, concurrency: test.fields.concurrency, - indexInfos: test.fields.indexInfos, + indexInfos: test.fields.indexInfos(), indexing: test.fields.indexing, minUncommitted: test.fields.minUncommitted, uuidsCount: test.fields.uuidsCount, @@ -275,7 +274,6 @@ func Test_index_Start(t *testing.T) { if err := checkFunc(test.want, got, err); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -297,7 +295,7 @@ func Test_index_execute(t *testing.T) { saveIndexTargetAddrCh chan string schMap sync.Map concurrency int - indexInfos indexInfos + indexInfos func() indexInfos indexing atomic.Value minUncommitted uint32 uuidsCount uint32 @@ -425,7 +423,7 @@ func Test_index_execute(t *testing.T) { saveIndexTargetAddrCh: test.fields.saveIndexTargetAddrCh, schMap: test.fields.schMap, concurrency: test.fields.concurrency, - indexInfos: test.fields.indexInfos, + indexInfos: test.fields.indexInfos(), indexing: test.fields.indexing, minUncommitted: test.fields.minUncommitted, uuidsCount: test.fields.uuidsCount, @@ -436,7 +434,6 @@ func Test_index_execute(t *testing.T) { if err := checkFunc(test.want, err); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -456,14 +453,13 @@ func Test_index_waitForNextSaving(t *testing.T) { saveIndexTargetAddrCh chan string schMap sync.Map concurrency int - indexInfos indexInfos + indexInfos func() indexInfos indexing atomic.Value minUncommitted uint32 uuidsCount uint32 uncommittedUUIDsCount uint32 } - type want struct { - } + type want struct{} type test struct { name string args args @@ -576,7 +572,7 @@ func Test_index_waitForNextSaving(t *testing.T) { saveIndexTargetAddrCh: test.fields.saveIndexTargetAddrCh, schMap: test.fields.schMap, concurrency: test.fields.concurrency, - indexInfos: test.fields.indexInfos, + indexInfos: test.fields.indexInfos(), indexing: test.fields.indexing, minUncommitted: test.fields.minUncommitted, uuidsCount: test.fields.uuidsCount, @@ -606,7 +602,7 @@ func Test_index_loadInfos(t *testing.T) { saveIndexTargetAddrCh chan string schMap sync.Map concurrency int - indexInfos indexInfos + indexInfos func() indexInfos indexing atomic.Value minUncommitted uint32 uuidsCount uint32 @@ -730,7 +726,7 @@ func Test_index_loadInfos(t *testing.T) { saveIndexTargetAddrCh: test.fields.saveIndexTargetAddrCh, schMap: test.fields.schMap, concurrency: test.fields.concurrency, - indexInfos: test.fields.indexInfos, + indexInfos: test.fields.indexInfos(), indexing: test.fields.indexing, minUncommitted: test.fields.minUncommitted, uuidsCount: test.fields.uuidsCount, @@ -741,7 +737,6 @@ func Test_index_loadInfos(t *testing.T) { if err := checkFunc(test.want, err); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -758,7 +753,7 @@ func Test_index_IsIndexing(t *testing.T) { saveIndexTargetAddrCh chan string schMap sync.Map concurrency int - indexInfos indexInfos + indexInfos func() indexInfos indexing atomic.Value minUncommitted uint32 uuidsCount uint32 @@ -875,7 +870,7 @@ func Test_index_IsIndexing(t *testing.T) { saveIndexTargetAddrCh: test.fields.saveIndexTargetAddrCh, schMap: test.fields.schMap, concurrency: test.fields.concurrency, - indexInfos: test.fields.indexInfos, + indexInfos: test.fields.indexInfos(), indexing: test.fields.indexing, minUncommitted: test.fields.minUncommitted, uuidsCount: test.fields.uuidsCount, @@ -886,7 +881,6 @@ func Test_index_IsIndexing(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -903,7 +897,7 @@ func Test_index_NumberOfUUIDs(t *testing.T) { saveIndexTargetAddrCh chan string schMap sync.Map concurrency int - indexInfos indexInfos + indexInfos func() indexInfos indexing atomic.Value minUncommitted uint32 uuidsCount uint32 @@ -1020,7 +1014,7 @@ func Test_index_NumberOfUUIDs(t *testing.T) { saveIndexTargetAddrCh: test.fields.saveIndexTargetAddrCh, schMap: test.fields.schMap, concurrency: test.fields.concurrency, - indexInfos: test.fields.indexInfos, + indexInfos: test.fields.indexInfos(), indexing: test.fields.indexing, minUncommitted: test.fields.minUncommitted, uuidsCount: test.fields.uuidsCount, @@ -1031,7 +1025,6 @@ func Test_index_NumberOfUUIDs(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -1048,7 +1041,7 @@ func Test_index_NumberOfUncommittedUUIDs(t *testing.T) { saveIndexTargetAddrCh chan string schMap sync.Map concurrency int - indexInfos indexInfos + indexInfos func() indexInfos indexing atomic.Value minUncommitted uint32 uuidsCount uint32 @@ -1165,7 +1158,7 @@ func Test_index_NumberOfUncommittedUUIDs(t *testing.T) { saveIndexTargetAddrCh: test.fields.saveIndexTargetAddrCh, schMap: test.fields.schMap, concurrency: test.fields.concurrency, - indexInfos: test.fields.indexInfos, + indexInfos: test.fields.indexInfos(), indexing: test.fields.indexing, minUncommitted: test.fields.minUncommitted, uuidsCount: test.fields.uuidsCount, @@ -1176,7 +1169,6 @@ func Test_index_NumberOfUncommittedUUIDs(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } - }) } } diff --git a/pkg/manager/index/service/indexinfos_test.go b/pkg/manager/index/service/indexinfos_test.go index 91153189db..3ec7cfcc3a 100644 --- a/pkg/manager/index/service/indexinfos_test.go +++ b/pkg/manager/index/service/indexinfos_test.go @@ -18,7 +18,6 @@ package service import ( "reflect" - "sync" "sync/atomic" "testing" "unsafe" @@ -109,7 +108,6 @@ func Test_newEntryIndexInfos(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -119,7 +117,6 @@ func Test_indexInfos_Load(t *testing.T) { key string } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryIndexInfos misses int @@ -214,7 +211,6 @@ func Test_indexInfos_Load(t *testing.T) { checkFunc = defaultCheckFunc } m := &indexInfos{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -224,7 +220,6 @@ func Test_indexInfos_Load(t *testing.T) { if err := checkFunc(test.want, gotValue, gotOk); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -317,7 +312,6 @@ func Test_entryIndexInfos_load(t *testing.T) { if err := checkFunc(test.want, gotValue, gotOk); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -328,13 +322,11 @@ func Test_indexInfos_Store(t *testing.T) { value *payload.Info_Index_Count } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryIndexInfos misses int } - type want struct { - } + type want struct{} type test struct { name string args args @@ -417,7 +409,6 @@ func Test_indexInfos_Store(t *testing.T) { checkFunc = defaultCheckFunc } m := &indexInfos{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -525,7 +516,6 @@ func Test_entryIndexInfos_tryStore(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -614,7 +604,6 @@ func Test_entryIndexInfos_unexpungeLocked(t *testing.T) { if err := checkFunc(test.want, gotWasExpunged); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -626,8 +615,7 @@ func Test_entryIndexInfos_storeLocked(t *testing.T) { type fields struct { p unsafe.Pointer } - type want struct { - } + type want struct{} type test struct { name string args args @@ -718,13 +706,11 @@ func Test_indexInfos_Delete(t *testing.T) { key string } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryIndexInfos misses int } - type want struct { - } + type want struct{} type test struct { name string args args @@ -805,7 +791,6 @@ func Test_indexInfos_Delete(t *testing.T) { checkFunc = defaultCheckFunc } m := &indexInfos{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -903,7 +888,6 @@ func Test_entryIndexInfos_delete(t *testing.T) { if err := checkFunc(test.want, gotHadValue); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -913,13 +897,11 @@ func Test_indexInfos_Range(t *testing.T) { f func(key string, value *payload.Info_Index_Count) bool } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryIndexInfos misses int } - type want struct { - } + type want struct{} type test struct { name string args args @@ -1000,7 +982,6 @@ func Test_indexInfos_Range(t *testing.T) { checkFunc = defaultCheckFunc } m := &indexInfos{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -1016,13 +997,11 @@ func Test_indexInfos_Range(t *testing.T) { func Test_indexInfos_missLocked(t *testing.T) { type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryIndexInfos misses int } - type want struct { - } + type want struct{} type test struct { name string fields fields @@ -1096,7 +1075,6 @@ func Test_indexInfos_missLocked(t *testing.T) { checkFunc = defaultCheckFunc } m := &indexInfos{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -1112,13 +1090,11 @@ func Test_indexInfos_missLocked(t *testing.T) { func Test_indexInfos_dirtyLocked(t *testing.T) { type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryIndexInfos misses int } - type want struct { - } + type want struct{} type test struct { name string fields fields @@ -1192,7 +1168,6 @@ func Test_indexInfos_dirtyLocked(t *testing.T) { checkFunc = defaultCheckFunc } m := &indexInfos{ - mu: test.fields.mu, read: test.fields.read, dirty: test.fields.dirty, misses: test.fields.misses, @@ -1290,7 +1265,6 @@ func Test_entryIndexInfos_tryExpungeLocked(t *testing.T) { if err := checkFunc(test.want, gotIsExpunged); err != nil { tt.Errorf("error = %v", err) } - }) } } diff --git a/pkg/manager/index/service/option_test.go b/pkg/manager/index/service/option_test.go index b0a21cb9cb..61cb913b0e 100644 --- a/pkg/manager/index/service/option_test.go +++ b/pkg/manager/index/service/option_test.go @@ -108,7 +108,6 @@ func TestWithIndexingConcurrency(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -194,7 +193,6 @@ func TestWithIndexingDuration(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -280,7 +278,6 @@ func TestWithIndexingDurationLimit(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -366,7 +363,6 @@ func TestWithSaveIndexDurationLimit(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -452,7 +448,6 @@ func TestWithSaveIndexWaitDuration(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -538,7 +533,6 @@ func TestWithMinUncommitted(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -624,7 +618,6 @@ func TestWithCreationPoolSize(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -710,7 +703,6 @@ func TestWithDiscoverer(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -796,7 +788,6 @@ func TestWithErrGroup(t *testing.T) { if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } - }) } } diff --git a/pkg/manager/index/usecase/indexer_test.go b/pkg/manager/index/usecase/indexer_test.go index 122fdab9bc..c0f5cf97b0 100644 --- a/pkg/manager/index/usecase/indexer_test.go +++ b/pkg/manager/index/usecase/indexer_test.go @@ -116,7 +116,6 @@ func TestNew(t *testing.T) { if err := checkFunc(test.want, gotR, err); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -231,7 +230,6 @@ func Test_run_PreStart(t *testing.T) { if err := checkFunc(test.want, err); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -350,7 +348,6 @@ func Test_run_Start(t *testing.T) { if err := checkFunc(test.want, got, err); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -465,7 +462,6 @@ func Test_run_PreStop(t *testing.T) { if err := checkFunc(test.want, err); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -580,7 +576,6 @@ func Test_run_Stop(t *testing.T) { if err := checkFunc(test.want, err); err != nil { tt.Errorf("error = %v", err) } - }) } } @@ -695,7 +690,6 @@ func Test_run_PostStop(t *testing.T) { if err := checkFunc(test.want, err); err != nil { tt.Errorf("error = %v", err) } - }) } } From fb9c6cbaee9011ca64e834086bf1f4946abcaa07 Mon Sep 17 00:00:00 2001 From: kevindiu Date: Tue, 22 Nov 2022 15:57:31 +0900 Subject: [PATCH 4/4] fix comment Signed-off-by: kevindiu --- pkg/manager/index/service/indexer_test.go | 225 +++++++++++-------- pkg/manager/index/service/indexinfos_test.go | 12 - 2 files changed, 126 insertions(+), 111 deletions(-) diff --git a/pkg/manager/index/service/indexer_test.go b/pkg/manager/index/service/indexer_test.go index fa9a4b753a..8dff1ace93 100644 --- a/pkg/manager/index/service/indexer_test.go +++ b/pkg/manager/index/service/indexer_test.go @@ -20,7 +20,6 @@ package service import ( "context" "reflect" - "sync" "sync/atomic" "testing" "time" @@ -133,13 +132,16 @@ func Test_index_Start(t *testing.T) { saveIndexDurationLimit time.Duration saveIndexWaitDuration time.Duration saveIndexTargetAddrCh chan string - schMap sync.Map concurrency int - indexInfos func() indexInfos - indexing atomic.Value - minUncommitted uint32 - uuidsCount uint32 - uncommittedUUIDsCount uint32 + indexInfos struct { + read atomic.Value + dirty map[string]*entryIndexInfos + misses int + } + indexing atomic.Value + minUncommitted uint32 + uuidsCount uint32 + uncommittedUUIDsCount uint32 } type want struct { want <-chan error @@ -180,7 +182,6 @@ func Test_index_Start(t *testing.T) { saveIndexDurationLimit: nil, saveIndexWaitDuration: nil, saveIndexTargetAddrCh: nil, - schMap: nil, concurrency: 0, indexInfos: indexInfos{}, indexing: nil, @@ -216,7 +217,6 @@ func Test_index_Start(t *testing.T) { saveIndexDurationLimit: nil, saveIndexWaitDuration: nil, saveIndexTargetAddrCh: nil, - schMap: nil, concurrency: 0, indexInfos: indexInfos{}, indexing: nil, @@ -261,13 +261,16 @@ func Test_index_Start(t *testing.T) { saveIndexDurationLimit: test.fields.saveIndexDurationLimit, saveIndexWaitDuration: test.fields.saveIndexWaitDuration, saveIndexTargetAddrCh: test.fields.saveIndexTargetAddrCh, - schMap: test.fields.schMap, concurrency: test.fields.concurrency, - indexInfos: test.fields.indexInfos(), - indexing: test.fields.indexing, - minUncommitted: test.fields.minUncommitted, - uuidsCount: test.fields.uuidsCount, - uncommittedUUIDsCount: test.fields.uncommittedUUIDsCount, + indexInfos: indexInfos{ + read: test.fields.indexInfos.read, + dirty: test.fields.indexInfos.dirty, + misses: test.fields.indexInfos.misses, + }, + indexing: test.fields.indexing, + minUncommitted: test.fields.minUncommitted, + uuidsCount: test.fields.uuidsCount, + uncommittedUUIDsCount: test.fields.uncommittedUUIDsCount, } got, err := idx.Start(test.args.ctx) @@ -293,13 +296,16 @@ func Test_index_execute(t *testing.T) { saveIndexDurationLimit time.Duration saveIndexWaitDuration time.Duration saveIndexTargetAddrCh chan string - schMap sync.Map concurrency int - indexInfos func() indexInfos - indexing atomic.Value - minUncommitted uint32 - uuidsCount uint32 - uncommittedUUIDsCount uint32 + indexInfos struct { + read atomic.Value + dirty map[string]*entryIndexInfos + misses int + } + indexing atomic.Value + minUncommitted uint32 + uuidsCount uint32 + uncommittedUUIDsCount uint32 } type want struct { err error @@ -338,7 +344,6 @@ func Test_index_execute(t *testing.T) { saveIndexDurationLimit: nil, saveIndexWaitDuration: nil, saveIndexTargetAddrCh: nil, - schMap: nil, concurrency: 0, indexInfos: indexInfos{}, indexing: nil, @@ -376,7 +381,6 @@ func Test_index_execute(t *testing.T) { saveIndexDurationLimit: nil, saveIndexWaitDuration: nil, saveIndexTargetAddrCh: nil, - schMap: nil, concurrency: 0, indexInfos: indexInfos{}, indexing: nil, @@ -421,13 +425,16 @@ func Test_index_execute(t *testing.T) { saveIndexDurationLimit: test.fields.saveIndexDurationLimit, saveIndexWaitDuration: test.fields.saveIndexWaitDuration, saveIndexTargetAddrCh: test.fields.saveIndexTargetAddrCh, - schMap: test.fields.schMap, concurrency: test.fields.concurrency, - indexInfos: test.fields.indexInfos(), - indexing: test.fields.indexing, - minUncommitted: test.fields.minUncommitted, - uuidsCount: test.fields.uuidsCount, - uncommittedUUIDsCount: test.fields.uncommittedUUIDsCount, + indexInfos: indexInfos{ + read: test.fields.indexInfos.read, + dirty: test.fields.indexInfos.dirty, + misses: test.fields.indexInfos.misses, + }, + indexing: test.fields.indexing, + minUncommitted: test.fields.minUncommitted, + uuidsCount: test.fields.uuidsCount, + uncommittedUUIDsCount: test.fields.uncommittedUUIDsCount, } err := idx.execute(test.args.ctx, test.args.enableLowIndexSkip, test.args.immediateSaving) @@ -451,13 +458,16 @@ func Test_index_waitForNextSaving(t *testing.T) { saveIndexDurationLimit time.Duration saveIndexWaitDuration time.Duration saveIndexTargetAddrCh chan string - schMap sync.Map concurrency int - indexInfos func() indexInfos - indexing atomic.Value - minUncommitted uint32 - uuidsCount uint32 - uncommittedUUIDsCount uint32 + indexInfos struct { + read atomic.Value + dirty map[string]*entryIndexInfos + misses int + } + indexing atomic.Value + minUncommitted uint32 + uuidsCount uint32 + uncommittedUUIDsCount uint32 } type want struct{} type test struct { @@ -489,7 +499,6 @@ func Test_index_waitForNextSaving(t *testing.T) { saveIndexDurationLimit: nil, saveIndexWaitDuration: nil, saveIndexTargetAddrCh: nil, - schMap: nil, concurrency: 0, indexInfos: indexInfos{}, indexing: nil, @@ -525,7 +534,6 @@ func Test_index_waitForNextSaving(t *testing.T) { saveIndexDurationLimit: nil, saveIndexWaitDuration: nil, saveIndexTargetAddrCh: nil, - schMap: nil, concurrency: 0, indexInfos: indexInfos{}, indexing: nil, @@ -570,13 +578,16 @@ func Test_index_waitForNextSaving(t *testing.T) { saveIndexDurationLimit: test.fields.saveIndexDurationLimit, saveIndexWaitDuration: test.fields.saveIndexWaitDuration, saveIndexTargetAddrCh: test.fields.saveIndexTargetAddrCh, - schMap: test.fields.schMap, concurrency: test.fields.concurrency, - indexInfos: test.fields.indexInfos(), - indexing: test.fields.indexing, - minUncommitted: test.fields.minUncommitted, - uuidsCount: test.fields.uuidsCount, - uncommittedUUIDsCount: test.fields.uncommittedUUIDsCount, + indexInfos: indexInfos{ + read: test.fields.indexInfos.read, + dirty: test.fields.indexInfos.dirty, + misses: test.fields.indexInfos.misses, + }, + indexing: test.fields.indexing, + minUncommitted: test.fields.minUncommitted, + uuidsCount: test.fields.uuidsCount, + uncommittedUUIDsCount: test.fields.uncommittedUUIDsCount, } idx.waitForNextSaving(test.args.ctx) @@ -600,13 +611,16 @@ func Test_index_loadInfos(t *testing.T) { saveIndexDurationLimit time.Duration saveIndexWaitDuration time.Duration saveIndexTargetAddrCh chan string - schMap sync.Map concurrency int - indexInfos func() indexInfos - indexing atomic.Value - minUncommitted uint32 - uuidsCount uint32 - uncommittedUUIDsCount uint32 + indexInfos struct { + read atomic.Value + dirty map[string]*entryIndexInfos + misses int + } + indexing atomic.Value + minUncommitted uint32 + uuidsCount uint32 + uncommittedUUIDsCount uint32 } type want struct { err error @@ -643,7 +657,6 @@ func Test_index_loadInfos(t *testing.T) { saveIndexDurationLimit: nil, saveIndexWaitDuration: nil, saveIndexTargetAddrCh: nil, - schMap: nil, concurrency: 0, indexInfos: indexInfos{}, indexing: nil, @@ -679,7 +692,6 @@ func Test_index_loadInfos(t *testing.T) { saveIndexDurationLimit: nil, saveIndexWaitDuration: nil, saveIndexTargetAddrCh: nil, - schMap: nil, concurrency: 0, indexInfos: indexInfos{}, indexing: nil, @@ -724,13 +736,16 @@ func Test_index_loadInfos(t *testing.T) { saveIndexDurationLimit: test.fields.saveIndexDurationLimit, saveIndexWaitDuration: test.fields.saveIndexWaitDuration, saveIndexTargetAddrCh: test.fields.saveIndexTargetAddrCh, - schMap: test.fields.schMap, concurrency: test.fields.concurrency, - indexInfos: test.fields.indexInfos(), - indexing: test.fields.indexing, - minUncommitted: test.fields.minUncommitted, - uuidsCount: test.fields.uuidsCount, - uncommittedUUIDsCount: test.fields.uncommittedUUIDsCount, + indexInfos: indexInfos{ + read: test.fields.indexInfos.read, + dirty: test.fields.indexInfos.dirty, + misses: test.fields.indexInfos.misses, + }, + indexing: test.fields.indexing, + minUncommitted: test.fields.minUncommitted, + uuidsCount: test.fields.uuidsCount, + uncommittedUUIDsCount: test.fields.uncommittedUUIDsCount, } err := idx.loadInfos(test.args.ctx) @@ -751,13 +766,16 @@ func Test_index_IsIndexing(t *testing.T) { saveIndexDurationLimit time.Duration saveIndexWaitDuration time.Duration saveIndexTargetAddrCh chan string - schMap sync.Map concurrency int - indexInfos func() indexInfos - indexing atomic.Value - minUncommitted uint32 - uuidsCount uint32 - uncommittedUUIDsCount uint32 + indexInfos struct { + read atomic.Value + dirty map[string]*entryIndexInfos + misses int + } + indexing atomic.Value + minUncommitted uint32 + uuidsCount uint32 + uncommittedUUIDsCount uint32 } type want struct { want bool @@ -790,7 +808,6 @@ func Test_index_IsIndexing(t *testing.T) { saveIndexDurationLimit: nil, saveIndexWaitDuration: nil, saveIndexTargetAddrCh: nil, - schMap: nil, concurrency: 0, indexInfos: indexInfos{}, indexing: nil, @@ -823,7 +840,6 @@ func Test_index_IsIndexing(t *testing.T) { saveIndexDurationLimit: nil, saveIndexWaitDuration: nil, saveIndexTargetAddrCh: nil, - schMap: nil, concurrency: 0, indexInfos: indexInfos{}, indexing: nil, @@ -868,13 +884,16 @@ func Test_index_IsIndexing(t *testing.T) { saveIndexDurationLimit: test.fields.saveIndexDurationLimit, saveIndexWaitDuration: test.fields.saveIndexWaitDuration, saveIndexTargetAddrCh: test.fields.saveIndexTargetAddrCh, - schMap: test.fields.schMap, concurrency: test.fields.concurrency, - indexInfos: test.fields.indexInfos(), - indexing: test.fields.indexing, - minUncommitted: test.fields.minUncommitted, - uuidsCount: test.fields.uuidsCount, - uncommittedUUIDsCount: test.fields.uncommittedUUIDsCount, + indexInfos: indexInfos{ + read: test.fields.indexInfos.read, + dirty: test.fields.indexInfos.dirty, + misses: test.fields.indexInfos.misses, + }, + indexing: test.fields.indexing, + minUncommitted: test.fields.minUncommitted, + uuidsCount: test.fields.uuidsCount, + uncommittedUUIDsCount: test.fields.uncommittedUUIDsCount, } got := idx.IsIndexing() @@ -895,13 +914,16 @@ func Test_index_NumberOfUUIDs(t *testing.T) { saveIndexDurationLimit time.Duration saveIndexWaitDuration time.Duration saveIndexTargetAddrCh chan string - schMap sync.Map concurrency int - indexInfos func() indexInfos - indexing atomic.Value - minUncommitted uint32 - uuidsCount uint32 - uncommittedUUIDsCount uint32 + indexInfos struct { + read atomic.Value + dirty map[string]*entryIndexInfos + misses int + } + indexing atomic.Value + minUncommitted uint32 + uuidsCount uint32 + uncommittedUUIDsCount uint32 } type want struct { want uint32 @@ -934,7 +956,6 @@ func Test_index_NumberOfUUIDs(t *testing.T) { saveIndexDurationLimit: nil, saveIndexWaitDuration: nil, saveIndexTargetAddrCh: nil, - schMap: nil, concurrency: 0, indexInfos: indexInfos{}, indexing: nil, @@ -967,7 +988,6 @@ func Test_index_NumberOfUUIDs(t *testing.T) { saveIndexDurationLimit: nil, saveIndexWaitDuration: nil, saveIndexTargetAddrCh: nil, - schMap: nil, concurrency: 0, indexInfos: indexInfos{}, indexing: nil, @@ -1012,13 +1032,16 @@ func Test_index_NumberOfUUIDs(t *testing.T) { saveIndexDurationLimit: test.fields.saveIndexDurationLimit, saveIndexWaitDuration: test.fields.saveIndexWaitDuration, saveIndexTargetAddrCh: test.fields.saveIndexTargetAddrCh, - schMap: test.fields.schMap, concurrency: test.fields.concurrency, - indexInfos: test.fields.indexInfos(), - indexing: test.fields.indexing, - minUncommitted: test.fields.minUncommitted, - uuidsCount: test.fields.uuidsCount, - uncommittedUUIDsCount: test.fields.uncommittedUUIDsCount, + indexInfos: indexInfos{ + read: test.fields.indexInfos.read, + dirty: test.fields.indexInfos.dirty, + misses: test.fields.indexInfos.misses, + }, + indexing: test.fields.indexing, + minUncommitted: test.fields.minUncommitted, + uuidsCount: test.fields.uuidsCount, + uncommittedUUIDsCount: test.fields.uncommittedUUIDsCount, } got := idx.NumberOfUUIDs() @@ -1039,13 +1062,16 @@ func Test_index_NumberOfUncommittedUUIDs(t *testing.T) { saveIndexDurationLimit time.Duration saveIndexWaitDuration time.Duration saveIndexTargetAddrCh chan string - schMap sync.Map concurrency int - indexInfos func() indexInfos - indexing atomic.Value - minUncommitted uint32 - uuidsCount uint32 - uncommittedUUIDsCount uint32 + indexInfos struct { + read atomic.Value + dirty map[string]*entryIndexInfos + misses int + } + indexing atomic.Value + minUncommitted uint32 + uuidsCount uint32 + uncommittedUUIDsCount uint32 } type want struct { want uint32 @@ -1078,7 +1104,6 @@ func Test_index_NumberOfUncommittedUUIDs(t *testing.T) { saveIndexDurationLimit: nil, saveIndexWaitDuration: nil, saveIndexTargetAddrCh: nil, - schMap: nil, concurrency: 0, indexInfos: indexInfos{}, indexing: nil, @@ -1111,7 +1136,6 @@ func Test_index_NumberOfUncommittedUUIDs(t *testing.T) { saveIndexDurationLimit: nil, saveIndexWaitDuration: nil, saveIndexTargetAddrCh: nil, - schMap: nil, concurrency: 0, indexInfos: indexInfos{}, indexing: nil, @@ -1156,13 +1180,16 @@ func Test_index_NumberOfUncommittedUUIDs(t *testing.T) { saveIndexDurationLimit: test.fields.saveIndexDurationLimit, saveIndexWaitDuration: test.fields.saveIndexWaitDuration, saveIndexTargetAddrCh: test.fields.saveIndexTargetAddrCh, - schMap: test.fields.schMap, concurrency: test.fields.concurrency, - indexInfos: test.fields.indexInfos(), - indexing: test.fields.indexing, - minUncommitted: test.fields.minUncommitted, - uuidsCount: test.fields.uuidsCount, - uncommittedUUIDsCount: test.fields.uncommittedUUIDsCount, + indexInfos: indexInfos{ + read: test.fields.indexInfos.read, + dirty: test.fields.indexInfos.dirty, + misses: test.fields.indexInfos.misses, + }, + indexing: test.fields.indexing, + minUncommitted: test.fields.minUncommitted, + uuidsCount: test.fields.uuidsCount, + uncommittedUUIDsCount: test.fields.uncommittedUUIDsCount, } got := idx.NumberOfUncommittedUUIDs() diff --git a/pkg/manager/index/service/indexinfos_test.go b/pkg/manager/index/service/indexinfos_test.go index 3ec7cfcc3a..02f235f626 100644 --- a/pkg/manager/index/service/indexinfos_test.go +++ b/pkg/manager/index/service/indexinfos_test.go @@ -152,7 +152,6 @@ func Test_indexInfos_Load(t *testing.T) { key: "", }, fields: fields { - mu: nil, read: nil, dirty: nil, misses: 0, @@ -177,7 +176,6 @@ func Test_indexInfos_Load(t *testing.T) { key: "", }, fields: fields { - mu: nil, read: nil, dirty: nil, misses: 0, @@ -349,7 +347,6 @@ func Test_indexInfos_Store(t *testing.T) { value: nil, }, fields: fields { - mu: nil, read: nil, dirty: nil, misses: 0, @@ -375,7 +372,6 @@ func Test_indexInfos_Store(t *testing.T) { value: nil, }, fields: fields { - mu: nil, read: nil, dirty: nil, misses: 0, @@ -732,7 +728,6 @@ func Test_indexInfos_Delete(t *testing.T) { key: "", }, fields: fields { - mu: nil, read: nil, dirty: nil, misses: 0, @@ -757,7 +752,6 @@ func Test_indexInfos_Delete(t *testing.T) { key: "", }, fields: fields { - mu: nil, read: nil, dirty: nil, misses: 0, @@ -923,7 +917,6 @@ func Test_indexInfos_Range(t *testing.T) { f: nil, }, fields: fields { - mu: nil, read: nil, dirty: nil, misses: 0, @@ -948,7 +941,6 @@ func Test_indexInfos_Range(t *testing.T) { f: nil, }, fields: fields { - mu: nil, read: nil, dirty: nil, misses: 0, @@ -1019,7 +1011,6 @@ func Test_indexInfos_missLocked(t *testing.T) { { name: "test_case_1", fields: fields { - mu: nil, read: nil, dirty: nil, misses: 0, @@ -1041,7 +1032,6 @@ func Test_indexInfos_missLocked(t *testing.T) { return test { name: "test_case_2", fields: fields { - mu: nil, read: nil, dirty: nil, misses: 0, @@ -1112,7 +1102,6 @@ func Test_indexInfos_dirtyLocked(t *testing.T) { { name: "test_case_1", fields: fields { - mu: nil, read: nil, dirty: nil, misses: 0, @@ -1134,7 +1123,6 @@ func Test_indexInfos_dirtyLocked(t *testing.T) { return test { name: "test_case_2", fields: fields { - mu: nil, read: nil, dirty: nil, misses: 0,