diff --git a/pkg/manager/index/config/config_test.go b/pkg/manager/index/config/config_test.go index dec3921e4a..96b7fe013b 100644 --- a/pkg/manager/index/config/config_test.go +++ b/pkg/manager/index/config/config_test.go @@ -38,8 +38,8 @@ func TestNewConfig(t *testing.T) { args args want want checkFunc func(want, *Data, error) error - beforeFunc func(args) - afterFunc func(args) + 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) { @@ -60,6 +60,12 @@ func TestNewConfig(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -73,6 +79,12 @@ func TestNewConfig(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -84,10 +96,10 @@ func TestNewConfig(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { diff --git a/pkg/manager/index/handler/grpc/handler_test.go b/pkg/manager/index/handler/grpc/handler_test.go index acaf71ec0b..ff68fe79a0 100644 --- a/pkg/manager/index/handler/grpc/handler_test.go +++ b/pkg/manager/index/handler/grpc/handler_test.go @@ -41,8 +41,8 @@ func TestNew(t *testing.T) { args args want want checkFunc func(want, index.IndexServer) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got index.IndexServer) error { if !reflect.DeepEqual(got, w.want) { @@ -60,6 +60,12 @@ func TestNew(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -73,6 +79,12 @@ func TestNew(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -84,10 +96,10 @@ func TestNew(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -108,7 +120,8 @@ func Test_server_IndexInfo(t *testing.T) { in1 *payload.Empty } type fields struct { - indexer service.Indexer + indexer service.Indexer + UnimplementedIndexServer index.UnimplementedIndexServer } type want struct { wantRes *payload.Info_Index_Count @@ -120,8 +133,8 @@ func Test_server_IndexInfo(t *testing.T) { fields fields want want checkFunc func(want, *payload.Info_Index_Count, error) error - beforeFunc func(args) - afterFunc func(args) + 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) { @@ -143,9 +156,16 @@ func Test_server_IndexInfo(t *testing.T) { }, 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() + }, }, */ @@ -160,9 +180,16 @@ func Test_server_IndexInfo(t *testing.T) { }, 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() + }, } }(), */ @@ -174,17 +201,18 @@ func Test_server_IndexInfo(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } s := &server{ - indexer: test.fields.indexer, + indexer: test.fields.indexer, + UnimplementedIndexServer: test.fields.UnimplementedIndexServer, } gotRes, err := s.IndexInfo(test.args.ctx, test.args.in1) diff --git a/pkg/manager/index/handler/grpc/option_test.go b/pkg/manager/index/handler/grpc/option_test.go index 0f341097e8..798c3b7c9c 100644 --- a/pkg/manager/index/handler/grpc/option_test.go +++ b/pkg/manager/index/handler/grpc/option_test.go @@ -18,57 +18,35 @@ 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) { - // 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 + want Option } 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) + 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 } - - // 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 /* @@ -77,8 +55,13 @@ func TestWithIndexer(t *testing.T) { args: args { i: nil, }, - want: want { - obj: new(T), + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() }, }, */ @@ -91,8 +74,13 @@ func TestWithIndexer(t *testing.T) { args: args { i: nil, }, - want: want { - obj: new(T), + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() }, } }(), @@ -105,37 +93,20 @@ func TestWithIndexer(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc } - // 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) - } - */ + 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 index 819a246df0..b92536727f 100644 --- a/pkg/manager/index/handler/rest/handler_test.go +++ b/pkg/manager/index/handler/rest/handler_test.go @@ -39,8 +39,8 @@ func TestNew(t *testing.T) { args args want want checkFunc func(want, Handler) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got Handler) error { if !reflect.DeepEqual(got, w.want) { @@ -58,6 +58,12 @@ func TestNew(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -71,6 +77,12 @@ func TestNew(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -82,10 +94,10 @@ func TestNew(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -118,8 +130,8 @@ func Test_handler_Index(t *testing.T) { fields fields want want checkFunc func(want, int, error) error - beforeFunc func(args) - afterFunc func(args) + 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) { @@ -144,6 +156,12 @@ func Test_handler_Index(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -161,6 +179,12 @@ func Test_handler_Index(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -172,10 +196,10 @@ func Test_handler_Index(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -211,8 +235,8 @@ func Test_handler_IndexInfo(t *testing.T) { fields fields want want checkFunc func(want, int, error) error - beforeFunc func(args) - afterFunc func(args) + 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) { @@ -237,6 +261,12 @@ func Test_handler_IndexInfo(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -254,6 +284,12 @@ func Test_handler_IndexInfo(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -265,10 +301,10 @@ func Test_handler_IndexInfo(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { diff --git a/pkg/manager/index/handler/rest/option_test.go b/pkg/manager/index/handler/rest/option_test.go index 90f09f5983..f850c7f5db 100644 --- a/pkg/manager/index/handler/rest/option_test.go +++ b/pkg/manager/index/handler/rest/option_test.go @@ -18,57 +18,35 @@ 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) { - // 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 + want Option } 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) + 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 } - - // 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 /* @@ -77,8 +55,13 @@ func TestWithIndexer(t *testing.T) { args: args { i: nil, }, - want: want { - obj: new(T), + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() }, }, */ @@ -91,8 +74,13 @@ func TestWithIndexer(t *testing.T) { args: args { i: nil, }, - want: want { - obj: new(T), + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() }, } }(), @@ -105,37 +93,20 @@ func TestWithIndexer(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc } - // 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) - } - */ + 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 index 52d72d5b85..5f5ace0704 100644 --- a/pkg/manager/index/router/option_test.go +++ b/pkg/manager/index/router/option_test.go @@ -18,57 +18,35 @@ 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) { - // 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 + want Option } 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) + 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 } - - // 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 /* @@ -77,8 +55,13 @@ func TestWithHandler(t *testing.T) { args: args { h: nil, }, - want: want { - obj: new(T), + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() }, }, */ @@ -91,8 +74,13 @@ func TestWithHandler(t *testing.T) { args: args { h: nil, }, - want: want { - obj: new(T), + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() }, } }(), @@ -105,86 +93,45 @@ func TestWithHandler(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc } - // 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) - } - */ + got := WithHandler(test.args.h) + if err := checkFunc(test.want, got); 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 + want Option } 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) + 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 } - - // 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 /* @@ -193,8 +140,13 @@ func TestWithTimeout(t *testing.T) { args: args { timeout: "", }, - want: want { - obj: new(T), + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() }, }, */ @@ -207,8 +159,13 @@ func TestWithTimeout(t *testing.T) { args: args { timeout: "", }, - want: want { - obj: new(T), + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() }, } }(), @@ -221,37 +178,20 @@ func TestWithTimeout(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc } - // 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) - } - */ + 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 index b274161d1d..04ef78a10b 100644 --- a/pkg/manager/index/router/router_test.go +++ b/pkg/manager/index/router/router_test.go @@ -38,8 +38,8 @@ func TestNew(t *testing.T) { args args want want checkFunc func(want, http.Handler) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got http.Handler) error { if !reflect.DeepEqual(got, w.want) { @@ -57,6 +57,12 @@ func TestNew(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -70,6 +76,12 @@ func TestNew(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -81,10 +93,10 @@ func TestNew(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { diff --git a/pkg/manager/index/service/indexer_test.go b/pkg/manager/index/service/indexer_test.go index 86be1968c6..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" @@ -44,8 +43,8 @@ func TestNew(t *testing.T) { args args want want checkFunc func(want, Indexer, error) error - beforeFunc func(args) - afterFunc func(args) + 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) { @@ -66,6 +65,12 @@ func TestNew(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -79,6 +84,12 @@ func TestNew(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -90,10 +101,10 @@ func TestNew(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -121,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 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 @@ -139,8 +153,8 @@ func Test_index_Start(t *testing.T) { fields fields want want checkFunc func(want, <-chan error, error) error - beforeFunc func(args) - afterFunc func(args) + 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) { @@ -168,7 +182,6 @@ func Test_index_Start(t *testing.T) { saveIndexDurationLimit: nil, saveIndexWaitDuration: nil, saveIndexTargetAddrCh: nil, - schMap: sync.Map{}, concurrency: 0, indexInfos: indexInfos{}, indexing: nil, @@ -178,6 +191,12 @@ func Test_index_Start(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -198,7 +217,6 @@ func Test_index_Start(t *testing.T) { saveIndexDurationLimit: nil, saveIndexWaitDuration: nil, saveIndexTargetAddrCh: nil, - schMap: sync.Map{}, concurrency: 0, indexInfos: indexInfos{}, indexing: nil, @@ -208,6 +226,12 @@ func Test_index_Start(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -219,10 +243,10 @@ func Test_index_Start(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -237,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) @@ -269,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 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 @@ -286,8 +316,8 @@ func Test_index_execute(t *testing.T) { fields fields want want checkFunc func(want, error) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, err error) error { if !errors.Is(err, w.err) { @@ -314,7 +344,6 @@ func Test_index_execute(t *testing.T) { saveIndexDurationLimit: nil, saveIndexWaitDuration: nil, saveIndexTargetAddrCh: nil, - schMap: sync.Map{}, concurrency: 0, indexInfos: indexInfos{}, indexing: nil, @@ -324,6 +353,12 @@ func Test_index_execute(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -346,7 +381,6 @@ func Test_index_execute(t *testing.T) { saveIndexDurationLimit: nil, saveIndexWaitDuration: nil, saveIndexTargetAddrCh: nil, - schMap: sync.Map{}, concurrency: 0, indexInfos: indexInfos{}, indexing: nil, @@ -356,6 +390,12 @@ func Test_index_execute(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -367,10 +407,10 @@ func Test_index_execute(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -385,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) @@ -415,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 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 { @@ -430,8 +476,8 @@ func Test_index_waitForNextSaving(t *testing.T) { fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -453,7 +499,6 @@ func Test_index_waitForNextSaving(t *testing.T) { saveIndexDurationLimit: nil, saveIndexWaitDuration: nil, saveIndexTargetAddrCh: nil, - schMap: sync.Map{}, concurrency: 0, indexInfos: indexInfos{}, indexing: nil, @@ -463,6 +508,12 @@ func Test_index_waitForNextSaving(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -483,7 +534,6 @@ func Test_index_waitForNextSaving(t *testing.T) { saveIndexDurationLimit: nil, saveIndexWaitDuration: nil, saveIndexTargetAddrCh: nil, - schMap: sync.Map{}, concurrency: 0, indexInfos: indexInfos{}, indexing: nil, @@ -493,6 +543,12 @@ func Test_index_waitForNextSaving(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -504,10 +560,10 @@ func Test_index_waitForNextSaving(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -522,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) @@ -552,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 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 @@ -569,8 +631,8 @@ func Test_index_loadInfos(t *testing.T) { fields fields want want checkFunc func(want, error) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, err error) error { if !errors.Is(err, w.err) { @@ -595,7 +657,6 @@ func Test_index_loadInfos(t *testing.T) { saveIndexDurationLimit: nil, saveIndexWaitDuration: nil, saveIndexTargetAddrCh: nil, - schMap: sync.Map{}, concurrency: 0, indexInfos: indexInfos{}, indexing: nil, @@ -605,6 +666,12 @@ func Test_index_loadInfos(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -625,7 +692,6 @@ func Test_index_loadInfos(t *testing.T) { saveIndexDurationLimit: nil, saveIndexWaitDuration: nil, saveIndexTargetAddrCh: nil, - schMap: sync.Map{}, concurrency: 0, indexInfos: indexInfos{}, indexing: nil, @@ -635,6 +701,12 @@ func Test_index_loadInfos(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -646,10 +718,10 @@ func Test_index_loadInfos(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -664,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) @@ -691,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 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 @@ -707,8 +785,8 @@ func Test_index_IsIndexing(t *testing.T) { fields fields want want checkFunc func(want, bool) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, got bool) error { if !reflect.DeepEqual(got, w.want) { @@ -730,7 +808,6 @@ func Test_index_IsIndexing(t *testing.T) { saveIndexDurationLimit: nil, saveIndexWaitDuration: nil, saveIndexTargetAddrCh: nil, - schMap: sync.Map{}, concurrency: 0, indexInfos: indexInfos{}, indexing: nil, @@ -740,6 +817,12 @@ func Test_index_IsIndexing(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -757,7 +840,6 @@ func Test_index_IsIndexing(t *testing.T) { saveIndexDurationLimit: nil, saveIndexWaitDuration: nil, saveIndexTargetAddrCh: nil, - schMap: sync.Map{}, concurrency: 0, indexInfos: indexInfos{}, indexing: nil, @@ -767,6 +849,12 @@ func Test_index_IsIndexing(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -778,10 +866,10 @@ func Test_index_IsIndexing(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -796,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() @@ -823,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 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 @@ -839,8 +933,8 @@ func Test_index_NumberOfUUIDs(t *testing.T) { fields fields want want checkFunc func(want, uint32) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, got uint32) error { if !reflect.DeepEqual(got, w.want) { @@ -862,7 +956,6 @@ func Test_index_NumberOfUUIDs(t *testing.T) { saveIndexDurationLimit: nil, saveIndexWaitDuration: nil, saveIndexTargetAddrCh: nil, - schMap: sync.Map{}, concurrency: 0, indexInfos: indexInfos{}, indexing: nil, @@ -872,6 +965,12 @@ func Test_index_NumberOfUUIDs(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -889,7 +988,6 @@ func Test_index_NumberOfUUIDs(t *testing.T) { saveIndexDurationLimit: nil, saveIndexWaitDuration: nil, saveIndexTargetAddrCh: nil, - schMap: sync.Map{}, concurrency: 0, indexInfos: indexInfos{}, indexing: nil, @@ -899,6 +997,12 @@ func Test_index_NumberOfUUIDs(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -910,10 +1014,10 @@ func Test_index_NumberOfUUIDs(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -928,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() @@ -955,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 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 @@ -971,8 +1081,8 @@ func Test_index_NumberOfUncommittedUUIDs(t *testing.T) { fields fields want want checkFunc func(want, uint32) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, got uint32) error { if !reflect.DeepEqual(got, w.want) { @@ -994,7 +1104,6 @@ func Test_index_NumberOfUncommittedUUIDs(t *testing.T) { saveIndexDurationLimit: nil, saveIndexWaitDuration: nil, saveIndexTargetAddrCh: nil, - schMap: sync.Map{}, concurrency: 0, indexInfos: indexInfos{}, indexing: nil, @@ -1004,6 +1113,12 @@ func Test_index_NumberOfUncommittedUUIDs(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -1021,7 +1136,6 @@ func Test_index_NumberOfUncommittedUUIDs(t *testing.T) { saveIndexDurationLimit: nil, saveIndexWaitDuration: nil, saveIndexTargetAddrCh: nil, - schMap: sync.Map{}, concurrency: 0, indexInfos: indexInfos{}, indexing: nil, @@ -1031,6 +1145,12 @@ func Test_index_NumberOfUncommittedUUIDs(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -1042,10 +1162,10 @@ func Test_index_NumberOfUncommittedUUIDs(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -1060,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 200acd6e07..02f235f626 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" @@ -40,8 +39,8 @@ func Test_newEntryIndexInfos(t *testing.T) { args args want want checkFunc func(want, *entryIndexInfos) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got *entryIndexInfos) error { if !reflect.DeepEqual(got, w.want) { @@ -59,6 +58,12 @@ func Test_newEntryIndexInfos(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -72,6 +77,12 @@ func Test_newEntryIndexInfos(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -83,10 +94,10 @@ func Test_newEntryIndexInfos(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -106,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 @@ -121,8 +131,8 @@ func Test_indexInfos_Load(t *testing.T) { fields fields want want checkFunc func(want, *payload.Info_Index_Count, bool) error - beforeFunc func(args) - afterFunc func(args) + 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) { @@ -142,13 +152,18 @@ func Test_indexInfos_Load(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, 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() + }, }, */ @@ -161,13 +176,18 @@ func Test_indexInfos_Load(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, 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() + }, } }(), */ @@ -179,17 +199,16 @@ func Test_indexInfos_Load(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + 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, @@ -216,8 +235,8 @@ func Test_entryIndexInfos_load(t *testing.T) { fields fields want want checkFunc func(want, *payload.Info_Index_Count, bool) error - beforeFunc func() - afterFunc func() + 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) { @@ -238,6 +257,12 @@ func Test_entryIndexInfos_load(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -251,6 +276,12 @@ func Test_entryIndexInfos_load(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -262,10 +293,10 @@ func Test_entryIndexInfos_load(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -289,7 +320,6 @@ 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 @@ -301,8 +331,8 @@ func Test_indexInfos_Store(t *testing.T) { fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -317,13 +347,18 @@ func Test_indexInfos_Store(t *testing.T) { value: nil, }, fields: fields { - mu: sync.Mutex{}, 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() + }, }, */ @@ -337,13 +372,18 @@ func Test_indexInfos_Store(t *testing.T) { value: nil, }, fields: fields { - mu: sync.Mutex{}, 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() + }, } }(), */ @@ -355,17 +395,16 @@ func Test_indexInfos_Store(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + 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, @@ -395,8 +434,8 @@ func Test_entryIndexInfos_tryStore(t *testing.T) { fields fields want want checkFunc func(want, bool) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got bool) error { if !reflect.DeepEqual(got, w.want) { @@ -417,6 +456,12 @@ func Test_entryIndexInfos_tryStore(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -433,6 +478,12 @@ func Test_entryIndexInfos_tryStore(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -444,10 +495,10 @@ func Test_entryIndexInfos_tryStore(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -477,8 +528,8 @@ func Test_entryIndexInfos_unexpungeLocked(t *testing.T) { fields fields want want checkFunc func(want, bool) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, gotWasExpunged bool) error { if !reflect.DeepEqual(gotWasExpunged, w.wantWasExpunged) { @@ -496,6 +547,12 @@ func Test_entryIndexInfos_unexpungeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -509,6 +566,12 @@ func Test_entryIndexInfos_unexpungeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -520,10 +583,10 @@ func Test_entryIndexInfos_unexpungeLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -555,8 +618,8 @@ func Test_entryIndexInfos_storeLocked(t *testing.T) { fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -574,6 +637,12 @@ func Test_entryIndexInfos_storeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -590,6 +659,12 @@ func Test_entryIndexInfos_storeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -601,10 +676,10 @@ func Test_entryIndexInfos_storeLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -627,7 +702,6 @@ func Test_indexInfos_Delete(t *testing.T) { key string } type fields struct { - mu sync.Mutex read atomic.Value dirty map[string]*entryIndexInfos misses int @@ -639,8 +713,8 @@ func Test_indexInfos_Delete(t *testing.T) { fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -654,13 +728,18 @@ func Test_indexInfos_Delete(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, 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() + }, }, */ @@ -673,13 +752,18 @@ func Test_indexInfos_Delete(t *testing.T) { key: "", }, fields: fields { - mu: sync.Mutex{}, 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() + }, } }(), */ @@ -691,17 +775,16 @@ func Test_indexInfos_Delete(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + 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, @@ -727,8 +810,8 @@ func Test_entryIndexInfos_delete(t *testing.T) { fields fields want want checkFunc func(want, bool) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, gotHadValue bool) error { if !reflect.DeepEqual(gotHadValue, w.wantHadValue) { @@ -746,6 +829,12 @@ func Test_entryIndexInfos_delete(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -759,6 +848,12 @@ func Test_entryIndexInfos_delete(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -770,10 +865,10 @@ func Test_entryIndexInfos_delete(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -796,7 +891,6 @@ 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 @@ -808,8 +902,8 @@ func Test_indexInfos_Range(t *testing.T) { fields fields want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -823,13 +917,18 @@ func Test_indexInfos_Range(t *testing.T) { f: nil, }, fields: fields { - mu: sync.Mutex{}, 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() + }, }, */ @@ -842,13 +941,18 @@ func Test_indexInfos_Range(t *testing.T) { f: nil, }, fields: fields { - mu: sync.Mutex{}, 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() + }, } }(), */ @@ -860,17 +964,16 @@ func Test_indexInfos_Range(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + 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, @@ -886,7 +989,6 @@ 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 @@ -897,8 +999,8 @@ func Test_indexInfos_missLocked(t *testing.T) { fields fields want want checkFunc func(want) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want) error { return nil @@ -909,13 +1011,18 @@ func Test_indexInfos_missLocked(t *testing.T) { { name: "test_case_1", fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -925,13 +1032,18 @@ func Test_indexInfos_missLocked(t *testing.T) { return test { name: "test_case_2", fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -943,17 +1055,16 @@ func Test_indexInfos_missLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + 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, @@ -969,7 +1080,6 @@ 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 @@ -980,8 +1090,8 @@ func Test_indexInfos_dirtyLocked(t *testing.T) { fields fields want want checkFunc func(want) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want) error { return nil @@ -992,13 +1102,18 @@ func Test_indexInfos_dirtyLocked(t *testing.T) { { name: "test_case_1", fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -1008,13 +1123,18 @@ func Test_indexInfos_dirtyLocked(t *testing.T) { return test { name: "test_case_2", fields: fields { - mu: sync.Mutex{}, read: nil, dirty: nil, misses: 0, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -1026,17 +1146,16 @@ func Test_indexInfos_dirtyLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + 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, @@ -1062,8 +1181,8 @@ func Test_entryIndexInfos_tryExpungeLocked(t *testing.T) { fields fields want want checkFunc func(want, bool) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, gotIsExpunged bool) error { if !reflect.DeepEqual(gotIsExpunged, w.wantIsExpunged) { @@ -1081,6 +1200,12 @@ func Test_entryIndexInfos_tryExpungeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, }, */ @@ -1094,6 +1219,12 @@ func Test_entryIndexInfos_tryExpungeLocked(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T,) { + t.Helper() + }, + afterFunc: func(t *testing.T,) { + t.Helper() + }, } }(), */ @@ -1105,10 +1236,10 @@ func Test_entryIndexInfos_tryExpungeLocked(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { diff --git a/pkg/manager/index/service/option_test.go b/pkg/manager/index/service/option_test.go index 91f0d88656..61cb913b0e 100644 --- a/pkg/manager/index/service/option_test.go +++ b/pkg/manager/index/service/option_test.go @@ -18,58 +18,36 @@ 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) { - // 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 + want Option } 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) + 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 } - - // 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 /* @@ -78,8 +56,13 @@ func TestWithIndexingConcurrency(t *testing.T) { args: args { c: 0, }, - want: want { - obj: new(T), + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() }, }, */ @@ -92,8 +75,13 @@ func TestWithIndexingConcurrency(t *testing.T) { args: args { c: 0, }, - want: want { - obj: new(T), + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() }, } }(), @@ -106,86 +94,45 @@ func TestWithIndexingConcurrency(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc } - // 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) - } - */ + got := WithIndexingConcurrency(test.args.c) + if err := checkFunc(test.want, got); 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 + want Option } 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) + 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 } - - // 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 /* @@ -194,8 +141,13 @@ func TestWithIndexingDuration(t *testing.T) { args: args { dur: "", }, - want: want { - obj: new(T), + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() }, }, */ @@ -208,8 +160,13 @@ func TestWithIndexingDuration(t *testing.T) { args: args { dur: "", }, - want: want { - obj: new(T), + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() }, } }(), @@ -222,86 +179,45 @@ func TestWithIndexingDuration(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc } - // 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) - } - */ + got := WithIndexingDuration(test.args.dur) + if err := checkFunc(test.want, got); 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 + want Option } 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) + 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 } - - // 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 /* @@ -310,8 +226,13 @@ func TestWithIndexingDurationLimit(t *testing.T) { args: args { dur: "", }, - want: want { - obj: new(T), + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() }, }, */ @@ -324,8 +245,13 @@ func TestWithIndexingDurationLimit(t *testing.T) { args: args { dur: "", }, - want: want { - obj: new(T), + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() }, } }(), @@ -338,86 +264,45 @@ func TestWithIndexingDurationLimit(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc } - // 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) - } - */ + got := WithIndexingDurationLimit(test.args.dur) + if err := checkFunc(test.want, got); 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 + want Option } 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) + 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 } - - // 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 /* @@ -426,8 +311,13 @@ func TestWithSaveIndexDurationLimit(t *testing.T) { args: args { dur: "", }, - want: want { - obj: new(T), + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() }, }, */ @@ -440,8 +330,13 @@ func TestWithSaveIndexDurationLimit(t *testing.T) { args: args { dur: "", }, - want: want { - obj: new(T), + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() }, } }(), @@ -454,86 +349,45 @@ func TestWithSaveIndexDurationLimit(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc } - // 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) - } - */ + got := WithSaveIndexDurationLimit(test.args.dur) + if err := checkFunc(test.want, got); 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 + want Option } 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) + 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 } - - // 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 /* @@ -542,8 +396,13 @@ func TestWithSaveIndexWaitDuration(t *testing.T) { args: args { dur: "", }, - want: want { - obj: new(T), + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() }, }, */ @@ -556,8 +415,13 @@ func TestWithSaveIndexWaitDuration(t *testing.T) { args: args { dur: "", }, - want: want { - obj: new(T), + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() }, } }(), @@ -570,86 +434,45 @@ func TestWithSaveIndexWaitDuration(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc } - // 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) - } - */ + got := WithSaveIndexWaitDuration(test.args.dur) + if err := checkFunc(test.want, got); 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 + want Option } 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) + 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 } - - // 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 /* @@ -658,8 +481,13 @@ func TestWithMinUncommitted(t *testing.T) { args: args { n: 0, }, - want: want { - obj: new(T), + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() }, }, */ @@ -672,8 +500,13 @@ func TestWithMinUncommitted(t *testing.T) { args: args { n: 0, }, - want: want { - obj: new(T), + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() }, } }(), @@ -686,86 +519,45 @@ func TestWithMinUncommitted(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc } - // 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) - } - */ + got := WithMinUncommitted(test.args.n) + if err := checkFunc(test.want, got); 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 + want Option } 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) + 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 } - - // 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 /* @@ -774,8 +566,13 @@ func TestWithCreationPoolSize(t *testing.T) { args: args { size: 0, }, - want: want { - obj: new(T), + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() }, }, */ @@ -788,8 +585,13 @@ func TestWithCreationPoolSize(t *testing.T) { args: args { size: 0, }, - want: want { - obj: new(T), + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() }, } }(), @@ -802,86 +604,45 @@ func TestWithCreationPoolSize(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc } - // 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) - } - */ + got := WithCreationPoolSize(test.args.size) + if err := checkFunc(test.want, got); 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 + want Option } 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) + 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 } - - // 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 /* @@ -890,8 +651,13 @@ func TestWithDiscoverer(t *testing.T) { args: args { c: nil, }, - want: want { - obj: new(T), + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() }, }, */ @@ -904,8 +670,13 @@ func TestWithDiscoverer(t *testing.T) { args: args { c: nil, }, - want: want { - obj: new(T), + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() }, } }(), @@ -918,86 +689,45 @@ func TestWithDiscoverer(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc } - // 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) - } - */ + got := WithDiscoverer(test.args.c) + if err := checkFunc(test.want, got); 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 + want Option } 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) + 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 } - - // 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 /* @@ -1006,8 +736,13 @@ func TestWithErrGroup(t *testing.T) { args: args { eg: nil, }, - want: want { - obj: new(T), + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() }, }, */ @@ -1020,8 +755,13 @@ func TestWithErrGroup(t *testing.T) { args: args { eg: nil, }, - want: want { - obj: new(T), + want: want{}, + checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() }, } }(), @@ -1034,37 +774,20 @@ func TestWithErrGroup(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc } - // 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) - } - */ + 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 index 9037fe1b2b..c0f5cf97b0 100644 --- a/pkg/manager/index/usecase/indexer_test.go +++ b/pkg/manager/index/usecase/indexer_test.go @@ -44,8 +44,8 @@ func TestNew(t *testing.T) { args args want want checkFunc func(want, runner.Runner, error) error - beforeFunc func(args) - afterFunc func(args) + 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) { @@ -66,6 +66,12 @@ func TestNew(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -79,6 +85,12 @@ func TestNew(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -90,10 +102,10 @@ func TestNew(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -128,8 +140,8 @@ func Test_run_PreStart(t *testing.T) { fields fields want want checkFunc func(want, error) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, err error) error { if !errors.Is(err, w.err) { @@ -154,6 +166,12 @@ func Test_run_PreStart(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -174,6 +192,12 @@ func Test_run_PreStart(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -185,10 +209,10 @@ func Test_run_PreStart(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -231,8 +255,8 @@ func Test_run_Start(t *testing.T) { fields fields want want checkFunc func(want, <-chan error, error) error - beforeFunc func(args) - afterFunc func(args) + 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) { @@ -260,6 +284,12 @@ func Test_run_Start(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -280,6 +310,12 @@ func Test_run_Start(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -291,10 +327,10 @@ func Test_run_Start(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -318,7 +354,7 @@ func Test_run_Start(t *testing.T) { func Test_run_PreStop(t *testing.T) { type args struct { - ctx context.Context + in0 context.Context } type fields struct { eg errgroup.Group @@ -336,8 +372,8 @@ func Test_run_PreStop(t *testing.T) { fields fields want want checkFunc func(want, error) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, err error) error { if !errors.Is(err, w.err) { @@ -351,7 +387,7 @@ func Test_run_PreStop(t *testing.T) { { name: "test_case_1", args: args { - ctx: nil, + in0: nil, }, fields: fields { eg: nil, @@ -362,6 +398,12 @@ func Test_run_PreStop(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -371,7 +413,7 @@ func Test_run_PreStop(t *testing.T) { return test { name: "test_case_2", args: args { - ctx: nil, + in0: nil, }, fields: fields { eg: nil, @@ -382,6 +424,12 @@ func Test_run_PreStop(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -393,10 +441,10 @@ func Test_run_PreStop(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -410,7 +458,7 @@ func Test_run_PreStop(t *testing.T) { indexer: test.fields.indexer, } - err := r.PreStop(test.args.ctx) + err := r.PreStop(test.args.in0) if err := checkFunc(test.want, err); err != nil { tt.Errorf("error = %v", err) } @@ -438,8 +486,8 @@ func Test_run_Stop(t *testing.T) { fields fields want want checkFunc func(want, error) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, err error) error { if !errors.Is(err, w.err) { @@ -464,6 +512,12 @@ func Test_run_Stop(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -484,6 +538,12 @@ func Test_run_Stop(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -495,10 +555,10 @@ func Test_run_Stop(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -522,7 +582,7 @@ func Test_run_Stop(t *testing.T) { func Test_run_PostStop(t *testing.T) { type args struct { - ctx context.Context + in0 context.Context } type fields struct { eg errgroup.Group @@ -540,8 +600,8 @@ func Test_run_PostStop(t *testing.T) { fields fields want want checkFunc func(want, error) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, err error) error { if !errors.Is(err, w.err) { @@ -555,7 +615,7 @@ func Test_run_PostStop(t *testing.T) { { name: "test_case_1", args: args { - ctx: nil, + in0: nil, }, fields: fields { eg: nil, @@ -566,6 +626,12 @@ func Test_run_PostStop(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -575,7 +641,7 @@ func Test_run_PostStop(t *testing.T) { return test { name: "test_case_2", args: args { - ctx: nil, + in0: nil, }, fields: fields { eg: nil, @@ -586,6 +652,12 @@ func Test_run_PostStop(t *testing.T) { }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -597,10 +669,10 @@ func Test_run_PostStop(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -614,7 +686,7 @@ func Test_run_PostStop(t *testing.T) { indexer: test.fields.indexer, } - err := r.PostStop(test.args.ctx) + err := r.PostStop(test.args.in0) if err := checkFunc(test.want, err); err != nil { tt.Errorf("error = %v", err) }