diff --git a/internal/cache/gache/gache_test.go b/internal/cache/gache/gache_test.go index 4ace926497..556ec96592 100644 --- a/internal/cache/gache/gache_test.go +++ b/internal/cache/gache/gache_test.go @@ -211,7 +211,7 @@ func Test_cache_Get(t *testing.T) { fields fields want want checkFunc func(want, interface{}, bool) error - beforeFunc func(args, *cache) + beforeFunc func(*testing.T, args, *cache) afterFunc func(args) } defaultCheckFunc := func(w want, got interface{}, got1 bool) error { @@ -255,7 +255,8 @@ func Test_cache_Get(t *testing.T) { want: "vald", want1: true, }, - beforeFunc: func(args args, c *cache) { + beforeFunc: func(t *testing.T, args args, c *cache) { + t.Helper() c.Set(args.key, "vald") }, }, @@ -272,7 +273,7 @@ func Test_cache_Get(t *testing.T) { expiredHook: test.fields.expiredHook, } if test.beforeFunc != nil { - test.beforeFunc(test.args, c) + test.beforeFunc(tt, test.args, c) } if test.afterFunc != nil { defer test.afterFunc(test.args) @@ -395,7 +396,7 @@ func Test_cache_Delete(t *testing.T) { fields fields want want checkFunc func(want, *cache) error - beforeFunc func(args, *cache) + beforeFunc func(*testing.T, args, *cache) afterFunc func(args) } defaultCheckFunc := func(w want, c *cache) error { @@ -442,7 +443,8 @@ func Test_cache_Delete(t *testing.T) { want: nil, want1: false, }, - beforeFunc: func(args args, c *cache) { + beforeFunc: func(t *testing.T, args args, c *cache) { + t.Helper() c.Set(args.key, "vald") }, }, @@ -459,7 +461,7 @@ func Test_cache_Delete(t *testing.T) { expiredHook: test.fields.expiredHook, } if test.beforeFunc != nil { - test.beforeFunc(test.args, c) + test.beforeFunc(tt, test.args, c) } if test.afterFunc != nil { defer test.afterFunc(test.args) @@ -497,7 +499,7 @@ func Test_cache_GetAndDelete(t *testing.T) { fields fields want want checkFunc func(want, interface{}, bool) error - beforeFunc func(args, *cache) + beforeFunc func(*testing.T, args, *cache) afterFunc func(args) } defaultCheckFunc := func(w want, got interface{}, got1 bool) error { @@ -541,7 +543,8 @@ func Test_cache_GetAndDelete(t *testing.T) { want: "vald", want1: true, }, - beforeFunc: func(args args, c *cache) { + beforeFunc: func(t *testing.T, args args, c *cache) { + t.Helper() c.Set(args.key, "vald") }, }, @@ -558,7 +561,7 @@ func Test_cache_GetAndDelete(t *testing.T) { expiredHook: test.fields.expiredHook, } if test.beforeFunc != nil { - test.beforeFunc(test.args, c) + test.beforeFunc(tt, test.args, c) } if test.afterFunc != nil { defer test.afterFunc(test.args) diff --git a/internal/config/config_test.go b/internal/config/config_test.go index b57cf0b62b..135b276394 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -54,7 +54,7 @@ func TestGlobalConfig_Bind(t *testing.T) { fields fields want want checkFunc func(want, *GlobalConfig) error - beforeFunc func() + beforeFunc func(*testing.T) afterFunc func() } defaultCheckFunc := func(w want, got *GlobalConfig) error { @@ -231,7 +231,8 @@ func TestGlobalConfig_Bind(t *testing.T) { }, }, }, - beforeFunc: func() { + beforeFunc: func(t *testing.T) { + t.Helper() for key, val := range env { t.Setenv(key, val) } @@ -245,7 +246,7 @@ func TestGlobalConfig_Bind(t *testing.T) { t.Run(test.name, func(tt *testing.T) { defer goleak.VerifyNone(tt, goleakIgnoreOptions...) if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { defer test.afterFunc() diff --git a/internal/config/log_test.go b/internal/config/log_test.go index eb9e739264..9c78ad3ae9 100644 --- a/internal/config/log_test.go +++ b/internal/config/log_test.go @@ -38,7 +38,7 @@ func TestLogging_Bind(t *testing.T) { fields fields want want checkFunc func(want, *Logging) error - beforeFunc func() + beforeFunc func(*testing.T) afterFunc func() } defaultCheckFunc := func(w want, got *Logging) error { @@ -70,7 +70,8 @@ func TestLogging_Bind(t *testing.T) { Level: "_LOGGING_BIND_LEVEL_", Format: "_LOGGING_BIND_FORMAT_", }, - beforeFunc: func() { + beforeFunc: func(t *testing.T) { + t.Helper() t.Setenv("LOGGING_BIND_LOGGER", "glg") t.Setenv("LOGGING_BIND_LEVEL", "info") t.Setenv("LOGGING_BIND_FORMAT", "json") @@ -95,7 +96,7 @@ func TestLogging_Bind(t *testing.T) { test := tc t.Run(test.name, func(tt *testing.T) { if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { defer test.afterFunc() diff --git a/internal/config/mysql_test.go b/internal/config/mysql_test.go index 7a284e62b3..7ca2ea9b5a 100644 --- a/internal/config/mysql_test.go +++ b/internal/config/mysql_test.go @@ -56,7 +56,7 @@ func TestMySQL_Bind(t *testing.T) { fields fields want want checkFunc func(want, *MySQL) error - beforeFunc func() + beforeFunc func(*testing.T) afterFunc func() } defaultCheckFunc := func(w want, got *MySQL) error { @@ -190,7 +190,8 @@ func TestMySQL_Bind(t *testing.T) { Net: new(Net), }, }, - beforeFunc: func() { + beforeFunc: func(t *testing.T) { + t.Helper() t.Setenv("MYSQL_BIND_DB", "db") t.Setenv("MYSQL_BIND_HOST", "host") t.Setenv("MYSQL_BIND_USER", "user") @@ -209,7 +210,7 @@ func TestMySQL_Bind(t *testing.T) { test := tc t.Run(test.name, func(tt *testing.T) { if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { defer test.afterFunc() diff --git a/internal/config/ngt_test.go b/internal/config/ngt_test.go index aea6f2509c..b941c73d41 100644 --- a/internal/config/ngt_test.go +++ b/internal/config/ngt_test.go @@ -50,7 +50,7 @@ func TestNGT_Bind(t *testing.T) { fields fields want want checkFunc func(want, *NGT) error - beforeFunc func() + beforeFunc func(*testing.T) afterFunc func() } defaultCheckFunc := func(w want, got *NGT) error { @@ -118,7 +118,8 @@ func TestNGT_Bind(t *testing.T) { VQueue: new(VQueue), KVSDB: new(KVSDB), }, - beforeFunc: func() { + beforeFunc: func(t *testing.T) { + t.Helper() t.Setenv("NGT_BIND_INDEX_PATH", "config/ngt") t.Setenv("NGT_BIND_DISTANCE_TYPE", "l2") t.Setenv("NGT_BIND_OBJECT_TYPE", "float") @@ -162,7 +163,7 @@ func TestNGT_Bind(t *testing.T) { test := tc t.Run(test.name, func(tt *testing.T) { if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { defer test.afterFunc() diff --git a/internal/config/tls_test.go b/internal/config/tls_test.go index 94303d4b41..2abc47fded 100644 --- a/internal/config/tls_test.go +++ b/internal/config/tls_test.go @@ -40,7 +40,7 @@ func TestTLS_Bind(t *testing.T) { fields fields want want checkFunc func(want, *TLS) error - beforeFunc func() + beforeFunc func(*testing.T) afterFunc func() } defaultCheckFunc := func(w want, got *TLS) error { @@ -75,7 +75,8 @@ func TestTLS_Bind(t *testing.T) { Key: "_TLS_BIND_KEY_", CA: "_TLS_BIND_CA_", }, - beforeFunc: func() { + beforeFunc: func(t *testing.T) { + t.Helper() t.Setenv("TLS_BIND_CERT", "tls_cert") t.Setenv("TLS_BIND_KEY", "tls_key") t.Setenv("TLS_BIND_CA", "tls_ca") @@ -101,7 +102,7 @@ func TestTLS_Bind(t *testing.T) { test := tc t.Run(test.name, func(tt *testing.T) { if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } if test.afterFunc != nil { defer test.afterFunc() diff --git a/internal/db/nosql/cassandra/option_test.go b/internal/db/nosql/cassandra/option_test.go index f644d537d8..22640895a5 100644 --- a/internal/db/nosql/cassandra/option_test.go +++ b/internal/db/nosql/cassandra/option_test.go @@ -66,7 +66,7 @@ func TestWithHosts(t *testing.T) { args args want want checkFunc func(want, *T, error) error - beforeFunc func(*T) + beforeFunc func(*testing.T, *T) afterFunc func(args) } defaultCheckFunc := func(w want, obj *T, err error) error { @@ -112,7 +112,8 @@ func TestWithHosts(t *testing.T) { args: args{ hosts: []string{"hosts1"}, }, - beforeFunc: func(obj *T) { + beforeFunc: func(t *testing.T, obj *T) { + t.Helper() _ = WithHosts("vald.vdaas.org")(obj) }, want: want{ @@ -138,7 +139,7 @@ func TestWithHosts(t *testing.T) { got := WithHosts(test.args.hosts...) obj := new(T) if test.beforeFunc != nil { - test.beforeFunc(obj) + test.beforeFunc(tt, obj) } if err := checkFunc(test.want, obj, got(obj)); err != nil { tt.Errorf("error = %v", err) diff --git a/internal/db/rdb/mysql/mysql_test.go b/internal/db/rdb/mysql/mysql_test.go index aabdad9ab6..ad373fae7d 100644 --- a/internal/db/rdb/mysql/mysql_test.go +++ b/internal/db/rdb/mysql/mysql_test.go @@ -53,7 +53,7 @@ func TestNew(t *testing.T) { want want checkFunc func(want, MySQL, error) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got MySQL, err error) error { if !errors.Is(err, w.err) { @@ -122,7 +122,7 @@ func TestNew(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -174,7 +174,7 @@ func Test_mySQLClient_Open(t *testing.T) { want want checkFunc func(want, error) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, err error) error { if !errors.Is(err, w.err) { @@ -234,7 +234,8 @@ func Test_mySQLClient_Open(t *testing.T) { }, }, }, - afterFunc: func(args) { + afterFunc: func(t *testing.T, _ args) { + t.Helper() cancel() }, want: want{}, @@ -294,7 +295,8 @@ func Test_mySQLClient_Open(t *testing.T) { }, }, }, - afterFunc: func(args) { + afterFunc: func(t *testing.T, _ args) { + t.Helper() cancel() }, want: want{}, @@ -333,7 +335,8 @@ func Test_mySQLClient_Open(t *testing.T) { }, }, }, - afterFunc: func(args) { + afterFunc: func(t *testing.T, _ args) { + t.Helper() cancel() }, want: want{ @@ -393,7 +396,8 @@ func Test_mySQLClient_Open(t *testing.T) { }, }, }, - afterFunc: func(args) { + afterFunc: func(t *testing.T, _ args) { + t.Helper() cancel() }, want: want{ @@ -411,7 +415,7 @@ func Test_mySQLClient_Open(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -467,7 +471,7 @@ func Test_mySQLClient_Ping(t *testing.T) { want want checkFunc func(want, error) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, err error) error { if !errors.Is(err, w.err) { @@ -502,7 +506,8 @@ func Test_mySQLClient_Ping(t *testing.T) { }, }, want: want{}, - afterFunc: func(args) { + afterFunc: func(t *testing.T, _ args) { + t.Helper() cancel() }, } @@ -521,7 +526,8 @@ func Test_mySQLClient_Ping(t *testing.T) { want: want{ err: errors.ErrMySQLSessionNil, }, - afterFunc: func(args) { + afterFunc: func(t *testing.T, _ args) { + t.Helper() cancel() }, } @@ -546,7 +552,8 @@ func Test_mySQLClient_Ping(t *testing.T) { want: want{ err: errors.Wrap(errors.Wrap(errors.ErrMySQLConnectionPingFailed, err.Error()), context.DeadlineExceeded.Error()), }, - afterFunc: func(args) { + afterFunc: func(t *testing.T, _ args) { + t.Helper() cancel() }, } @@ -570,7 +577,8 @@ func Test_mySQLClient_Ping(t *testing.T) { want: want{ err: errors.ErrMySQLConnectionPingFailed, }, - afterFunc: func(args) { + afterFunc: func(t *testing.T, _ args) { + t.Helper() cancel() }, } @@ -585,7 +593,7 @@ func Test_mySQLClient_Ping(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -623,7 +631,7 @@ func Test_mySQLClient_Close(t *testing.T) { want want checkFunc func(want, error, *mySQLClient) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, err error, m *mySQLClient) error { if !errors.Is(err, w.err) { @@ -692,7 +700,7 @@ func Test_mySQLClient_Close(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -732,7 +740,7 @@ func Test_mySQLClient_GetVector(t *testing.T) { want want checkFunc func(want, Vector, error) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got Vector, err error) error { if !errors.Is(err, w.err) { @@ -1000,7 +1008,7 @@ func Test_mySQLClient_GetVector(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -1041,7 +1049,7 @@ func Test_mySQLClient_GetIPs(t *testing.T) { want want checkFunc func(want, []string, error) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got []string, err error) error { if !errors.Is(err, w.err) { @@ -1323,7 +1331,7 @@ func Test_mySQLClient_GetIPs(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -1356,7 +1364,7 @@ func Test_validateVector(t *testing.T) { want want checkFunc func(want, error) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, err error) error { if !errors.Is(err, w.err) { @@ -1398,7 +1406,7 @@ func Test_validateVector(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -1433,7 +1441,7 @@ func Test_mySQLClient_SetVector(t *testing.T) { want want checkFunc func(want, error) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, err error) error { if !errors.Is(err, w.err) { @@ -2075,7 +2083,7 @@ func Test_mySQLClient_SetVector(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -2115,7 +2123,7 @@ func Test_mySQLClient_SetVectors(t *testing.T) { want want checkFunc func(want, error) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, err error) error { if !errors.Is(err, w.err) { @@ -2773,7 +2781,7 @@ func Test_mySQLClient_SetVectors(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -2813,7 +2821,7 @@ func Test_mySQLClient_DeleteVector(t *testing.T) { want want checkFunc func(want, error) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, err error) error { if !errors.Is(err, w.err) { @@ -3352,7 +3360,7 @@ func Test_mySQLClient_DeleteVector(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -3392,7 +3400,7 @@ func Test_mySQLClient_DeleteVectors(t *testing.T) { want want checkFunc func(want, error) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, err error) error { if !errors.Is(err, w.err) { @@ -3542,7 +3550,7 @@ func Test_mySQLClient_DeleteVectors(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -3583,7 +3591,7 @@ func Test_mySQLClient_SetIPs(t *testing.T) { want want checkFunc func(want, error) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, err error) error { if !errors.Is(err, w.err) { @@ -3936,7 +3944,7 @@ func Test_mySQLClient_SetIPs(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -3976,7 +3984,7 @@ func Test_mySQLClient_RemoveIPs(t *testing.T) { want want checkFunc func(want, error) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, err error) error { if !errors.Is(err, w.err) { @@ -4156,7 +4164,7 @@ func Test_mySQLClient_RemoveIPs(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -4213,7 +4221,7 @@ func Test_mySQLClient_errorLog(t *testing.T) { want want checkFunc func(want) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want) error { return nil @@ -4303,7 +4311,7 @@ func Test_mySQLClient_errorLog(t *testing.T) { test.beforeFunc(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/internal/db/storage/blob/s3/reader/option_test.go b/internal/db/storage/blob/s3/reader/option_test.go index ababd21b9b..fc29b90e32 100644 --- a/internal/db/storage/blob/s3/reader/option_test.go +++ b/internal/db/storage/blob/s3/reader/option_test.go @@ -398,7 +398,7 @@ func TestWithBackoffOpts(t *testing.T) { args args want want checkFunc func(want, *T) error - beforeFunc func(args, *T) + beforeFunc func(*testing.T, args, *T) afterFunc func(args, *T) } defaultCheckFunc := func(w want, got *T) error { @@ -450,7 +450,8 @@ func TestWithBackoffOpts(t *testing.T) { backoffOpts: append(defaultOptions, opts...), }, }, - beforeFunc: func(args args, r *T) { + beforeFunc: func(t *testing.T, args args, r *T) { + t.Helper() r.backoffOpts = args.defaultOptions }, } @@ -471,7 +472,7 @@ func TestWithBackoffOpts(t *testing.T) { defer goleak.VerifyNone(tt, goleakIgnoreOptions...) obj := new(T) if test.beforeFunc != nil { - test.beforeFunc(test.args, obj) + test.beforeFunc(tt, test.args, obj) } if test.afterFunc != nil { defer test.afterFunc(test.args, obj) diff --git a/internal/db/storage/blob/s3/reader/reader_test.go b/internal/db/storage/blob/s3/reader/reader_test.go index 1838b8a68c..14bfa0d1ef 100644 --- a/internal/db/storage/blob/s3/reader/reader_test.go +++ b/internal/db/storage/blob/s3/reader/reader_test.go @@ -152,8 +152,8 @@ func Test_reader_Open(t *testing.T) { fields fields want want checkFunc func(want, error) error - beforeFunc func(args) - afterFunc func(args, *testing.T) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) hookFunc func(*reader) } defaultCheckFunc := func(w want, err error) error { @@ -180,10 +180,11 @@ func Test_reader_Open(t *testing.T) { want: want{ err: nil, }, - beforeFunc: func(args) { + beforeFunc: func(t *testing.T, _ args) { + t.Helper() cancel() }, - afterFunc: func(_ args, t *testing.T) { + afterFunc: func(t *testing.T, _ args) { t.Helper() if err := eg.Wait(); err != nil { t.Errorf("want: %v, but got: %v", nil, err) @@ -219,7 +220,7 @@ func Test_reader_Open(t *testing.T) { want: want{ err: nil, }, - afterFunc: func(_ args, t *testing.T) { + afterFunc: func(t *testing.T, _ args) { t.Helper() if err := eg.Wait(); !errors.Is(err, wantErr) { @@ -253,7 +254,7 @@ func Test_reader_Open(t *testing.T) { want: want{ err: nil, }, - afterFunc: func(_ args, t *testing.T) { + afterFunc: func(t *testing.T, _ args) { t.Helper() if err := eg.Wait(); !errors.Is(err, wantErr) { @@ -302,7 +303,7 @@ func Test_reader_Open(t *testing.T) { want: want{ err: nil, }, - afterFunc: func(_ args, t *testing.T) { + afterFunc: func(t *testing.T, _ args) { t.Helper() if err := eg.Wait(); !errors.Is(err, wantErr) { @@ -355,7 +356,7 @@ func Test_reader_Open(t *testing.T) { want: want{ err: nil, }, - afterFunc: func(_ args, t *testing.T) { + afterFunc: func(t *testing.T, _ args) { t.Helper() if err := eg.Wait(); !errors.Is(err, wantErr) { @@ -437,7 +438,7 @@ func Test_reader_Open(t *testing.T) { } }() }, - afterFunc: func(_ args, t *testing.T) { + afterFunc: func(t *testing.T, _ args) { t.Helper() if err := eg.Wait(); err != nil { @@ -455,10 +456,10 @@ func Test_reader_Open(t *testing.T) { t.Run(test.name, func(tt *testing.T) { defer goleak.VerifyNone(tt, goleakIgnoreOptions...) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args, t) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { diff --git a/internal/errgroup/group_test.go b/internal/errgroup/group_test.go index 7f553d01ce..e0e450ad2d 100644 --- a/internal/errgroup/group_test.go +++ b/internal/errgroup/group_test.go @@ -51,7 +51,7 @@ func TestNew(t *testing.T) { want want checkFunc func(want, Group, context.Context) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got Group, got1 context.Context) error { if got, want := got.(*group), w.want.(*group); !reflect.DeepEqual(got.emap, want.emap) && @@ -97,7 +97,7 @@ func TestNew(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -125,7 +125,7 @@ func TestInit(t *testing.T) { want want checkFunc func(want, context.Context) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotEgctx context.Context) error { if !reflect.DeepEqual(gotEgctx, w.wantEgctx) { @@ -152,7 +152,8 @@ func TestInit(t *testing.T) { want: want{ wantEgctx: egctx, }, - afterFunc: func(a args) { + afterFunc: func(t *testing.T, a args) { + t.Helper() cancel() defaultBeforeFunc(a) }, @@ -169,7 +170,7 @@ func TestInit(t *testing.T) { test.beforeFunc(test.args) if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -192,8 +193,8 @@ func TestGet(t *testing.T) { name string want want checkFunc func(want, Group) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, got Group) error { if got, want := got.(*group), w.want.(*group); !reflect.DeepEqual(got.egctx, want.egctx) { @@ -204,10 +205,12 @@ func TestGet(t *testing.T) { initFunc := func() { instance, once = nil, sync.Once{} } - defaultBeforeFunc := func() { + defaultBeforeFunc := func(t *testing.T) { + t.Helper() initFunc() } - defaultAfterFunc := func() { + defaultAfterFunc := func(t *testing.T) { + t.Helper() initFunc() } @@ -236,7 +239,8 @@ func TestGet(t *testing.T) { want: want{ want: g, }, - beforeFunc: func() { + beforeFunc: func(t *testing.T) { + t.Helper() instance = g }, } @@ -249,12 +253,12 @@ func TestGet(t *testing.T) { if test.beforeFunc == nil { test.beforeFunc = defaultBeforeFunc } - test.beforeFunc() + test.beforeFunc(tt) if test.afterFunc == nil { test.afterFunc = defaultAfterFunc } - defer test.afterFunc() + defer test.afterFunc(tt) checkFunc := test.checkFunc if test.checkFunc == nil { @@ -277,8 +281,8 @@ func TestGo(t *testing.T) { name string args args checkFunc func(Group) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(Group) error { return nil @@ -295,7 +299,8 @@ func TestGo(t *testing.T) { return nil }, }, - beforeFunc: func(args) { + beforeFunc: func(t *testing.T, _ args) { + t.Helper() g := new(group) g.enableLimitation.Store(false) instance = g @@ -318,10 +323,10 @@ func TestGo(t *testing.T) { test := tc t.Run(test.name, func(tt *testing.T) { 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 { @@ -354,7 +359,7 @@ func Test_group_Limitation(t *testing.T) { want want checkFunc func(want, Group) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, g Group) error { got, want := g.(*group), w.want.(*group) @@ -410,7 +415,7 @@ func Test_group_Limitation(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -445,8 +450,8 @@ func Test_group_Go(t *testing.T) { args args fields fields checkFunc func(Group) error - beforeFunc func(args, Group) - afterFunc func(args) + beforeFunc func(*testing.T, args, Group) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(g Group) error { return nil @@ -475,7 +480,8 @@ func Test_group_Go(t *testing.T) { return }(), }, - beforeFunc: func(_ args, g Group) { + beforeFunc: func(t *testing.T, _ args, g Group) { + t.Helper() for i := 0; i < limit; i++ { g.Go(func() error { time.Sleep(3 * time.Second) @@ -521,7 +527,8 @@ func Test_group_Go(t *testing.T) { }(), emap: make(map[string]struct{}), }, - beforeFunc: func(a args, g Group) { + beforeFunc: func(t *testing.T, a args, g Group) { + t.Helper() g.Go(func() error { return errors.New("err-1") }) @@ -554,7 +561,7 @@ func Test_group_Go(t *testing.T) { test := tc t.Run(test.name, func(tt *testing.T) { if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -570,7 +577,7 @@ func Test_group_Go(t *testing.T) { } if test.beforeFunc != nil { - test.beforeFunc(test.args, g) + test.beforeFunc(tt, test.args, g) } g.Go(test.args.f) @@ -649,8 +656,8 @@ func TestWait(t *testing.T) { name string want want checkFunc func(want, error) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, err error) error { if !errors.Is(err, w.err) { @@ -661,10 +668,12 @@ func TestWait(t *testing.T) { tests := []test{ { name: "returns nil when Wait returns nil", - beforeFunc: func() { + beforeFunc: func(t *testing.T) { + t.Helper() instance, _ = New(context.Background()) }, - afterFunc: func() { + afterFunc: func(t *testing.T) { + t.Helper() instance = nil }, }, @@ -675,10 +684,10 @@ func TestWait(t *testing.T) { t.Run(test.name, func(tt *testing.T) { tt.Parallel() 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 { @@ -707,7 +716,7 @@ func Test_group_Wait(t *testing.T) { fields fields want want checkFunc func(want, error) error - beforeFunc func(Group) + beforeFunc func(*testing.T, Group) afterFunc func() } defaultCheckFunc := func(w want, err error) error { @@ -727,7 +736,8 @@ func Test_group_Wait(t *testing.T) { return }(), }, - beforeFunc: func(g Group) { + beforeFunc: func(t *testing.T, g Group) { + t.Helper() g.Go(func() error { atomic.StoreInt32(&num, int32(runtime.NumGoroutine())) time.Sleep(time.Second) @@ -778,7 +788,7 @@ func Test_group_Wait(t *testing.T) { } if test.beforeFunc != nil { - test.beforeFunc(g) + test.beforeFunc(tt, g) } err := g.Wait() diff --git a/internal/file/watch/watch_test.go b/internal/file/watch/watch_test.go index ac4b8474a2..ec5b8e4fef 100644 --- a/internal/file/watch/watch_test.go +++ b/internal/file/watch/watch_test.go @@ -737,6 +737,7 @@ func Test_watch_Add(t *testing.T) { }, }, afterFunc: func(t *testing.T, args args, w Watcher) { + t.Helper() _ = w.Remove("./watch_test.go") defaultAfterFunc(t, args, w) }, diff --git a/internal/info/info_test.go b/internal/info/info_test.go index 30c5993e66..094648fa99 100644 --- a/internal/info/info_test.go +++ b/internal/info/info_test.go @@ -50,8 +50,8 @@ func TestString(t *testing.T) { name string want want checkFunc func(want, string) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, got string) error { if got != w.want { @@ -62,13 +62,15 @@ func TestString(t *testing.T) { tests := []test{ { name: "return correct string with no stack trace initialized", - beforeFunc: func() { + beforeFunc: func(t *testing.T) { + t.Helper() infoProvider, _ = New(WithServerName(""), WithRuntimeCaller(func(skip int) (pc uintptr, file string, line int, ok bool) { return uintptr(0), "", 0, false })) }, - afterFunc: func() { + afterFunc: func(t *testing.T) { + t.Helper() once = sync.Once{} infoProvider = nil }, @@ -79,14 +81,16 @@ func TestString(t *testing.T) { { name: "return correct string with no information initialized", - beforeFunc: func() { + beforeFunc: func(t *testing.T) { + t.Helper() infoProvider = &info{ rtCaller: func(skip int) (pc uintptr, file string, line int, ok bool) { return uintptr(0), "", 0, false }, } }, - afterFunc: func() { + afterFunc: func(t *testing.T) { + t.Helper() once = sync.Once{} infoProvider = nil }, @@ -100,10 +104,10 @@ func TestString(t *testing.T) { test := tc t.Run(test.name, func(tt *testing.T) { if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } if test.beforeFunc != nil { - test.beforeFunc() + test.beforeFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -126,8 +130,8 @@ func TestGet(t *testing.T) { name string want want checkFunc func(want, Detail) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, got Detail) error { if !reflect.DeepEqual(got, w.want) { @@ -138,12 +142,14 @@ func TestGet(t *testing.T) { tests := []test{ { name: "return detail with initialized runtime information", - beforeFunc: func() { + beforeFunc: func(t *testing.T) { + t.Helper() infoProvider, _ = New(WithServerName(""), WithRuntimeCaller(func(skip int) (pc uintptr, file string, line int, ok bool) { return uintptr(0), "", 0, false })) }, - afterFunc: func() { + afterFunc: func(t *testing.T) { + t.Helper() once = sync.Once{} infoProvider = nil }, @@ -170,10 +176,10 @@ func TestGet(t *testing.T) { test := tc t.Run(test.name, func(tt *testing.T) { 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 { @@ -200,8 +206,8 @@ func TestInit(t *testing.T) { args args want want checkFunc func(want, Info) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got Info) error { opts := []comparator.Option{ @@ -263,7 +269,8 @@ func TestInit(t *testing.T) { }(), }, }, - beforeFunc: func(args) { + beforeFunc: func(t *testing.T, _ args) { + t.Helper() GitCommit = "gitcommit" Version = "" BuildTime = "1s" @@ -271,7 +278,8 @@ func TestInit(t *testing.T) { NGTVersion = "v1.11.6" BuildCPUInfoFlags = "\t\tavx512f avx512dq\t" }, - afterFunc: func(args) { + afterFunc: func(t *testing.T, _ args) { + t.Helper() once = sync.Once{} infoProvider = nil @@ -315,7 +323,8 @@ func TestInit(t *testing.T) { }(), }, }, - beforeFunc: func(args) { + beforeFunc: func(t *testing.T, _ args) { + t.Helper() GitCommit = "gitcommit" Version = "" BuildTime = "1s" @@ -323,7 +332,8 @@ func TestInit(t *testing.T) { NGTVersion = "v1.11.6" BuildCPUInfoFlags = "\t\tavx512f avx512dq\t" }, - afterFunc: func(args) { + afterFunc: func(t *testing.T, _ args) { + t.Helper() once = sync.Once{} infoProvider = nil @@ -341,10 +351,10 @@ func TestInit(t *testing.T) { test := tc t.Run(test.name, func(tt *testing.T) { 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 { @@ -373,7 +383,7 @@ func TestNew(t *testing.T) { want want checkFunc func(want, Info, error) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got Info, err error) error { if !errors.Is(err, w.err) { @@ -557,7 +567,7 @@ func TestNew(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -587,7 +597,7 @@ func Test_info_String(t *testing.T) { want want checkFunc func(want, string) error beforeFunc func() - afterFunc func() + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, got string) error { if !reflect.DeepEqual(got, w.want) { @@ -660,7 +670,7 @@ func Test_info_String(t *testing.T) { test.beforeFunc() } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -703,7 +713,7 @@ func TestDetail_String(t *testing.T) { want want checkFunc func(want, string) error beforeFunc func() - afterFunc func() + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, got string) error { if !reflect.DeepEqual(got, w.want) { @@ -767,7 +777,7 @@ func TestDetail_String(t *testing.T) { test.beforeFunc() } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -810,7 +820,7 @@ func Test_info_Get(t *testing.T) { want want checkFunc func(want, Detail) error beforeFunc func() - afterFunc func() + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, got Detail) error { if !reflect.DeepEqual(got, w.want) { @@ -1130,7 +1140,7 @@ func Test_info_Get(t *testing.T) { test.beforeFunc() } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -1165,7 +1175,7 @@ func Test_info_prepare(t *testing.T) { want want checkFunc func(info, want) error beforeFunc func() - afterFunc func() + afterFunc func(*testing.T) } // skipcq: VET-V0008 defaultCheckFunc := func(got info, w want) error { @@ -1480,7 +1490,7 @@ func Test_info_prepare(t *testing.T) { test.beforeFunc() } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -1515,7 +1525,7 @@ func TestStackTrace_String(t *testing.T) { want want checkFunc func(want, string) error beforeFunc func() - afterFunc func() + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, got string) error { if !reflect.DeepEqual(got, w.want) { @@ -1546,7 +1556,7 @@ func TestStackTrace_String(t *testing.T) { test.beforeFunc() } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -1583,7 +1593,7 @@ func Test_info_getDetail(t *testing.T) { want want checkFunc func(want, Detail) error beforeFunc func() - afterFunc func() + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, got Detail) error { if !reflect.DeepEqual(got, w.want) { @@ -1636,7 +1646,7 @@ func Test_info_getDetail(t *testing.T) { test.beforeFunc() } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } checkFunc := test.checkFunc if test.checkFunc == nil { diff --git a/internal/log/log_test.go b/internal/log/log_test.go index c8727f0eee..0d4ccb222e 100644 --- a/internal/log/log_test.go +++ b/internal/log/log_test.go @@ -47,8 +47,8 @@ func TestInit(t *testing.T) { args args want want checkFunc func(want, logger.Logger) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got logger.Logger) error { if !reflect.DeepEqual(got, l) { @@ -65,7 +65,8 @@ func TestInit(t *testing.T) { glg.WithLevel(level.DEBUG.String()), ), }, - beforeFunc: func(args) { + beforeFunc: func(t *testing.T, _ args) { + t.Helper() once = sync.Once{} }, } @@ -84,7 +85,8 @@ func TestInit(t *testing.T) { glg.WithLevel(level.FATAL.String()), ), }, - beforeFunc: func(args) { + beforeFunc: func(t *testing.T, _ args) { + t.Helper() once = sync.Once{} }, } @@ -96,10 +98,10 @@ func TestInit(t *testing.T) { t.Run(test.name, func(tt *testing.T) { defer goleak.VerifyNone(tt, goleakIgnoreOptions...) 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 { @@ -126,8 +128,8 @@ func Test_getLogger(t *testing.T) { args args want want checkFunc func(want, logger.Logger) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got logger.Logger) error { if !reflect.DeepEqual(got, w.want) { @@ -210,10 +212,10 @@ func Test_getLogger(t *testing.T) { t.Run(test.name, func(tt *testing.T) { defer goleak.VerifyNone(tt, goleakIgnoreOptions...) 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 { @@ -240,8 +242,8 @@ func TestBold(t *testing.T) { args args want want checkFunc func(want, string) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got string) error { if !reflect.DeepEqual(got, w.want) { @@ -266,10 +268,10 @@ func TestBold(t *testing.T) { t.Run(test.name, func(tt *testing.T) { defer goleak.VerifyNone(tt, goleakIgnoreOptions...) 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 { @@ -296,8 +298,8 @@ func TestDebug(t *testing.T) { args args want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } tests := []test{ func() test { @@ -321,10 +323,12 @@ func TestDebug(t *testing.T) { vals: w.vals, }, want: w, - beforeFunc: func(args) { + beforeFunc: func(t *testing.T, _ args) { + t.Helper() l = ml }, - afterFunc: func(args) { + afterFunc: func(t *testing.T, _ args) { + t.Helper() l = nil }, checkFunc: func(w want) error { @@ -342,10 +346,10 @@ func TestDebug(t *testing.T) { t.Run(test.name, func(tt *testing.T) { defer goleak.VerifyNone(tt, goleakIgnoreOptions...) 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) } Debug(test.args.vals...) @@ -370,8 +374,8 @@ func TestDebugf(t *testing.T) { args args want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } tests := []test{ func() test { @@ -400,10 +404,12 @@ func TestDebugf(t *testing.T) { vals: w.vals, }, want: w, - beforeFunc: func(args) { + beforeFunc: func(t *testing.T, _ args) { + t.Helper() l = ml }, - afterFunc: func(args) { + afterFunc: func(t *testing.T, _ args) { + t.Helper() l = nil }, checkFunc: func(w want) error { @@ -424,10 +430,10 @@ func TestDebugf(t *testing.T) { t.Run(test.name, func(tt *testing.T) { defer goleak.VerifyNone(tt, goleakIgnoreOptions...) 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) } Debugf(test.args.format, test.args.vals...) @@ -450,8 +456,8 @@ func TestInfo(t *testing.T) { args args want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } tests := []test{ func() test { @@ -475,10 +481,12 @@ func TestInfo(t *testing.T) { vals: w.vals, }, want: w, - beforeFunc: func(args) { + beforeFunc: func(t *testing.T, _ args) { + t.Helper() l = ml }, - afterFunc: func(args) { + afterFunc: func(t *testing.T, _ args) { + t.Helper() l = nil }, checkFunc: func(want) error { @@ -496,10 +504,10 @@ func TestInfo(t *testing.T) { t.Run(test.name, func(tt *testing.T) { defer goleak.VerifyNone(tt, goleakIgnoreOptions...) 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) } Info(test.args.vals...) @@ -524,8 +532,8 @@ func TestInfof(t *testing.T) { args args want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } tests := []test{ func() test { @@ -554,10 +562,12 @@ func TestInfof(t *testing.T) { vals: w.vals, }, want: w, - beforeFunc: func(args) { + beforeFunc: func(t *testing.T, _ args) { + t.Helper() l = ml }, - afterFunc: func(args) { + afterFunc: func(t *testing.T, _ args) { + t.Helper() l = nil }, checkFunc: func(w want) error { @@ -578,10 +588,10 @@ func TestInfof(t *testing.T) { t.Run(test.name, func(tt *testing.T) { defer goleak.VerifyNone(tt, goleakIgnoreOptions...) 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) } Infof(test.args.format, test.args.vals...) @@ -604,8 +614,8 @@ func TestWarn(t *testing.T) { args args want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } tests := []test{ func() test { @@ -629,10 +639,12 @@ func TestWarn(t *testing.T) { vals: w.vals, }, want: w, - beforeFunc: func(args) { + beforeFunc: func(t *testing.T, _ args) { + t.Helper() l = ml }, - afterFunc: func(args) { + afterFunc: func(t *testing.T, _ args) { + t.Helper() l = nil }, checkFunc: func(want) error { @@ -650,10 +662,10 @@ func TestWarn(t *testing.T) { t.Run(test.name, func(tt *testing.T) { defer goleak.VerifyNone(tt, goleakIgnoreOptions...) 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) } Warn(test.args.vals...) @@ -678,8 +690,8 @@ func TestWarnf(t *testing.T) { args args want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } tests := []test{ func() test { @@ -708,10 +720,12 @@ func TestWarnf(t *testing.T) { vals: w.vals, }, want: w, - beforeFunc: func(args) { + beforeFunc: func(t *testing.T, _ args) { + t.Helper() l = ml }, - afterFunc: func(args) { + afterFunc: func(t *testing.T, _ args) { + t.Helper() l = nil }, checkFunc: func(w want) error { @@ -732,10 +746,10 @@ func TestWarnf(t *testing.T) { t.Run(test.name, func(tt *testing.T) { defer goleak.VerifyNone(tt, goleakIgnoreOptions...) 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) } Warnf(test.args.format, test.args.vals...) @@ -758,8 +772,8 @@ func TestError(t *testing.T) { args args want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } tests := []test{ func() test { @@ -783,10 +797,12 @@ func TestError(t *testing.T) { vals: w.vals, }, want: w, - beforeFunc: func(args) { + beforeFunc: func(t *testing.T, _ args) { + t.Helper() l = ml }, - afterFunc: func(args) { + afterFunc: func(t *testing.T, _ args) { + t.Helper() l = nil }, checkFunc: func(w want) error { @@ -804,10 +820,10 @@ func TestError(t *testing.T) { t.Run(test.name, func(tt *testing.T) { defer goleak.VerifyNone(tt, goleakIgnoreOptions...) 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) } Error(test.args.vals...) @@ -832,8 +848,8 @@ func TestErrorf(t *testing.T) { args args want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } tests := []test{ func() test { @@ -862,10 +878,12 @@ func TestErrorf(t *testing.T) { vals: w.vals, }, want: w, - beforeFunc: func(args) { + beforeFunc: func(t *testing.T, _ args) { + t.Helper() l = ml }, - afterFunc: func(args) { + afterFunc: func(t *testing.T, _ args) { + t.Helper() l = nil }, checkFunc: func(w want) error { @@ -886,10 +904,10 @@ func TestErrorf(t *testing.T) { t.Run(test.name, func(tt *testing.T) { defer goleak.VerifyNone(tt, goleakIgnoreOptions...) 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) } Errorf(test.args.format, test.args.vals...) @@ -912,8 +930,8 @@ func TestFatal(t *testing.T) { args args want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } tests := []test{ func() test { @@ -937,10 +955,12 @@ func TestFatal(t *testing.T) { vals: w.vals, }, want: w, - beforeFunc: func(args) { + beforeFunc: func(t *testing.T, _ args) { + t.Helper() l = ml }, - afterFunc: func(args) { + afterFunc: func(t *testing.T, _ args) { + t.Helper() l = nil }, checkFunc: func(w want) error { @@ -958,10 +978,10 @@ func TestFatal(t *testing.T) { t.Run(test.name, func(tt *testing.T) { defer goleak.VerifyNone(tt, goleakIgnoreOptions...) 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) } Fatal(test.args.vals...) @@ -986,8 +1006,8 @@ func TestFatalf(t *testing.T) { args args want want checkFunc func(want) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } tests := []test{ func() test { @@ -1016,10 +1036,12 @@ func TestFatalf(t *testing.T) { vals: w.vals, }, want: w, - beforeFunc: func(args) { + beforeFunc: func(t *testing.T, _ args) { + t.Helper() l = ml }, - afterFunc: func(args) { + afterFunc: func(t *testing.T, _ args) { + t.Helper() l = nil }, checkFunc: func(w want) error { @@ -1040,10 +1062,10 @@ func TestFatalf(t *testing.T) { t.Run(test.name, func(tt *testing.T) { defer goleak.VerifyNone(tt, goleakIgnoreOptions...) 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) } Fatalf(test.args.format, test.args.vals...) @@ -1066,8 +1088,8 @@ func TestDebugd(t *testing.T) { args args 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 @@ -1108,10 +1130,10 @@ func TestDebugd(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 { @@ -1138,8 +1160,8 @@ func TestInfod(t *testing.T) { args args 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 @@ -1180,10 +1202,10 @@ func TestInfod(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 { @@ -1210,8 +1232,8 @@ func TestWarnd(t *testing.T) { args args 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 @@ -1252,10 +1274,10 @@ func TestWarnd(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 { @@ -1282,8 +1304,8 @@ func TestErrord(t *testing.T) { args args 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 @@ -1324,10 +1346,10 @@ func TestErrord(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 { @@ -1354,8 +1376,8 @@ func TestFatald(t *testing.T) { args args 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 @@ -1396,10 +1418,10 @@ func TestFatald(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/internal/log/retry/retry_test.go b/internal/log/retry/retry_test.go index e1d6413663..29e991bcaf 100644 --- a/internal/log/retry/retry_test.go +++ b/internal/log/retry/retry_test.go @@ -117,7 +117,7 @@ func Test_retry_Out(t *testing.T) { fields fields checkFunc func() error beforeFunc func(args) - afterFunc func(args, *testing.T) + afterFunc func(*testing.T, args) } defaultCheckFunc := func() error { return nil @@ -191,7 +191,7 @@ func Test_retry_Out(t *testing.T) { return nil }, - afterFunc: func(args args, t *testing.T) { + afterFunc: func(t *testing.T, args args) { t.Helper() if e := recover(); e == nil { t.Error("panic dose not occur") @@ -209,7 +209,7 @@ func Test_retry_Out(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args, tt) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -244,7 +244,7 @@ func Test_retry_Outf(t *testing.T) { fields fields checkFunc func() error beforeFunc func(args) - afterFunc func(args, *testing.T) + afterFunc func(*testing.T, args) } defaultCheckFunc := func() error { return nil @@ -340,7 +340,7 @@ func Test_retry_Outf(t *testing.T) { return nil }, - afterFunc: func(args args, t *testing.T) { + afterFunc: func(t *testing.T, args args) { t.Helper() if e := recover(); e == nil { t.Error("panic dose not occur") @@ -358,7 +358,7 @@ func Test_retry_Outf(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args, tt) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { diff --git a/internal/net/control/control_test.go b/internal/net/control/control_test.go index 32bea56e6e..4544103b66 100644 --- a/internal/net/control/control_test.go +++ b/internal/net/control/control_test.go @@ -47,7 +47,7 @@ func TestNew(t *testing.T) { want want checkFunc func(want, SocketController) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got SocketController) error { if !reflect.DeepEqual(got, w.want) { @@ -91,7 +91,7 @@ func TestNew(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -120,7 +120,7 @@ func Test_boolint(t *testing.T) { want want checkFunc func(want, int) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got int) error { if !reflect.DeepEqual(got, w.want) { @@ -157,7 +157,7 @@ func Test_boolint(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -186,7 +186,7 @@ func Test_isTCP(t *testing.T) { want want checkFunc func(want, bool) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got bool) error { if !reflect.DeepEqual(got, w.want) { @@ -241,7 +241,7 @@ func Test_isTCP(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -361,7 +361,7 @@ func Test_control_controlFunc(t *testing.T) { want want checkFunc func(want, error) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, err error) error { if !errors.Is(err, w.err) { @@ -400,7 +400,8 @@ func Test_control_controlFunc(t *testing.T) { keepAlive: 10, }, want: want{}, - afterFunc: func(a args) { + afterFunc: func(t *testing.T, a args) { + t.Helper() f.Close() }, } @@ -435,7 +436,8 @@ func Test_control_controlFunc(t *testing.T) { keepAlive: 10, }, want: want{}, - afterFunc: func(a args) { + afterFunc: func(t *testing.T, a args) { + t.Helper() f.Close() }, } @@ -470,7 +472,8 @@ func Test_control_controlFunc(t *testing.T) { keepAlive: 10, }, want: want{}, - afterFunc: func(a args) { + afterFunc: func(t *testing.T, a args) { + t.Helper() f.Close() }, } @@ -485,7 +488,7 @@ func Test_control_controlFunc(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } if test.checkFunc == nil { test.checkFunc = defaultCheckFunc diff --git a/internal/net/dialer_test.go b/internal/net/dialer_test.go index b4bb98362d..b73e3a716b 100644 --- a/internal/net/dialer_test.go +++ b/internal/net/dialer_test.go @@ -593,7 +593,7 @@ func Test_dialer_StartDialerCache(t *testing.T) { opts []DialerOption want want checkFunc func(*dialer) error - beforeFunc func(*dialer) + beforeFunc func(*testing.T, *dialer) afterFunc func(args) } defaultCheckFunc := func(d *dialer) error { @@ -615,7 +615,8 @@ func Test_dialer_StartDialerCache(t *testing.T) { WithDialerTimeout("1m"), WithDialerKeepalive("1m"), }, - beforeFunc: func(d *dialer) { + beforeFunc: func(t *testing.T, d *dialer) { + t.Helper() d.dnsCache.Set(addr, &dialerCache{ ips: ips, }) @@ -709,7 +710,7 @@ func Test_dialer_StartDialerCache(t *testing.T) { tt.Errorf("NewDialer return value Dialer is not *dialer: %v", der) } if test.beforeFunc != nil { - test.beforeFunc(d) + test.beforeFunc(tt, d) } d.StartDialerCache(ctx) @@ -852,7 +853,8 @@ func Test_dialer_cachedDialer(t *testing.T) { } return nil }, - afterFunc: func(*testing.T) { + afterFunc: func(t *testing.T) { + t.Helper() srv.Close() }, } @@ -962,6 +964,7 @@ func Test_dialer_cachedDialer(t *testing.T) { return nil }, afterFunc: func(t *testing.T) { + t.Helper() srv.Close() }, } @@ -998,6 +1001,7 @@ func Test_dialer_cachedDialer(t *testing.T) { WithTLS(tls), }, beforeFunc: func(t *testing.T) { + t.Helper() // set the hostname 'invalid_ip' to the host name of the cache with the test server ip address c.Set(addr, &dialerCache{ ips: []string{ @@ -1019,6 +1023,7 @@ func Test_dialer_cachedDialer(t *testing.T) { return nil }, afterFunc: func(t *testing.T) { + t.Helper() srv.Close() }, } @@ -1039,7 +1044,8 @@ func Test_dialer_cachedDialer(t *testing.T) { opts: []DialerOption{ WithDNSCache(c), }, - beforeFunc: func(*testing.T) { + beforeFunc: func(t *testing.T) { + t.Helper() c.Set(addr, &dialerCache{ ips: []string{ addr, @@ -1076,7 +1082,8 @@ func Test_dialer_cachedDialer(t *testing.T) { opts: []DialerOption{ WithDNSCache(c), }, - beforeFunc: func(*testing.T) { + beforeFunc: func(t *testing.T) { + t.Helper() c.Set(addr, &dialerCache{ ips: []string{ "invalid_ip", @@ -1131,6 +1138,7 @@ func Test_dialer_cachedDialer(t *testing.T) { WithEnableDNSCache(), }, beforeFunc: func(t *testing.T) { + t.Helper() c.Set(addrs[0], &dialerCache{ ips: hosts, }) @@ -1194,6 +1202,7 @@ func Test_dialer_cachedDialer(t *testing.T) { return nil }, afterFunc: func(t *testing.T) { + t.Helper() for _, s := range srvs { s.Close() } @@ -1227,6 +1236,7 @@ func Test_dialer_cachedDialer(t *testing.T) { WithDialerTimeout("10s"), }, beforeFunc: func(t *testing.T) { + t.Helper() c.Set(addr, &dialerCache{ cnt: math.MaxUint32, ips: []string{host, host}, @@ -1248,6 +1258,7 @@ func Test_dialer_cachedDialer(t *testing.T) { return nil }, afterFunc: func(t *testing.T) { + t.Helper() srv.Close() }, } @@ -1650,7 +1661,8 @@ func Test_dialer_tlsHandshake(t *testing.T) { } return nil }, - afterFunc: func(*testing.T) { + afterFunc: func(t *testing.T) { + t.Helper() srv.Close() conn.Close() cancel() @@ -1702,7 +1714,8 @@ func Test_dialer_tlsHandshake(t *testing.T) { want: want{ err: context.DeadlineExceeded, }, - afterFunc: func(*testing.T) { + afterFunc: func(t *testing.T) { + t.Helper() srv.Close() conn.Close() cancel() @@ -1747,7 +1760,8 @@ func Test_dialer_tlsHandshake(t *testing.T) { return c }()), }, - beforeFunc: func(*testing.T) { + beforeFunc: func(t *testing.T) { + t.Helper() // close the server before the test srv.Close() }, @@ -1757,7 +1771,8 @@ func Test_dialer_tlsHandshake(t *testing.T) { } return nil }, - afterFunc: func(t1 *testing.T) { + afterFunc: func(t *testing.T) { + t.Helper() conn.Close() cancel() }, diff --git a/internal/net/grpc/logger/logger_test.go b/internal/net/grpc/logger/logger_test.go index eb5508ddfa..e37dd7047f 100644 --- a/internal/net/grpc/logger/logger_test.go +++ b/internal/net/grpc/logger/logger_test.go @@ -35,7 +35,7 @@ func TestInit(t *testing.T) { name string checkFunc func() error beforeFunc func(*testing.T) - afterFunc func() + afterFunc func(*testing.T) } defaultCheckFunc := func() error { return nil @@ -49,13 +49,15 @@ func TestInit(t *testing.T) { } return nil }, - afterFunc: func() { + afterFunc: func(t *testing.T) { + t.Helper() once = sync.Once{} }, }, { name: "set logger success with verbosity level is set", beforeFunc: func(t *testing.T) { + t.Helper() t.Setenv("GRPC_GO_LOG_VERBOSITY_LEVEL", "2") }, checkFunc: func() error { @@ -70,7 +72,8 @@ func TestInit(t *testing.T) { } return nil }, - afterFunc: func() { + afterFunc: func(t *testing.T) { + t.Helper() once = sync.Once{} }, }, @@ -83,7 +86,7 @@ func TestInit(t *testing.T) { test.beforeFunc(tt) } if test.afterFunc != nil { - defer test.afterFunc() + defer test.afterFunc(tt) } if test.checkFunc == nil { test.checkFunc = defaultCheckFunc @@ -111,7 +114,7 @@ func Test_logger_Info(t *testing.T) { fields fields checkFunc func() error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func() error { return nil @@ -136,7 +139,7 @@ func Test_logger_Info(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } if test.checkFunc == nil { test.checkFunc = defaultCheckFunc @@ -167,7 +170,7 @@ func Test_logger_Infoln(t *testing.T) { fields fields checkFunc func() error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func() error { return nil @@ -192,7 +195,7 @@ func Test_logger_Infoln(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } if test.checkFunc == nil { test.checkFunc = defaultCheckFunc @@ -224,7 +227,7 @@ func Test_logger_Infof(t *testing.T) { fields fields checkFunc func() error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func() error { return nil @@ -249,7 +252,7 @@ func Test_logger_Infof(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } if test.checkFunc == nil { test.checkFunc = defaultCheckFunc @@ -280,7 +283,7 @@ func Test_logger_Warning(t *testing.T) { fields fields checkFunc func() error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func() error { return nil @@ -305,7 +308,7 @@ func Test_logger_Warning(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } if test.checkFunc == nil { test.checkFunc = defaultCheckFunc @@ -336,7 +339,7 @@ func Test_logger_Warningln(t *testing.T) { fields fields checkFunc func() error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func() error { return nil @@ -361,7 +364,7 @@ func Test_logger_Warningln(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } if test.checkFunc == nil { test.checkFunc = defaultCheckFunc @@ -393,7 +396,7 @@ func Test_logger_Warningf(t *testing.T) { fields fields checkFunc func() error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func() error { return nil @@ -418,7 +421,7 @@ func Test_logger_Warningf(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } if test.checkFunc == nil { test.checkFunc = defaultCheckFunc @@ -449,7 +452,7 @@ func Test_logger_Error(t *testing.T) { fields fields checkFunc func() error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func() error { return nil @@ -474,7 +477,7 @@ func Test_logger_Error(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } if test.checkFunc == nil { test.checkFunc = defaultCheckFunc @@ -505,7 +508,7 @@ func Test_logger_Errorln(t *testing.T) { fields fields checkFunc func() error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func() error { return nil @@ -530,7 +533,7 @@ func Test_logger_Errorln(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } if test.checkFunc == nil { test.checkFunc = defaultCheckFunc @@ -562,7 +565,7 @@ func Test_logger_Errorf(t *testing.T) { fields fields checkFunc func() error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func() error { return nil @@ -587,7 +590,7 @@ func Test_logger_Errorf(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } if test.checkFunc == nil { test.checkFunc = defaultCheckFunc @@ -627,7 +630,7 @@ func Test_logger_Fatal(t *testing.T) { fields fields checkFunc func() error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func() error { return nil @@ -641,7 +644,8 @@ func Test_logger_Fatal(t *testing.T) { fields: fields{ v: 0, }, - afterFunc: func(a args) { + afterFunc: func(t *testing.T, _ args) { + t.Helper() _ = recover() }, }, @@ -655,7 +659,7 @@ func Test_logger_Fatal(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } if test.checkFunc == nil { test.checkFunc = defaultCheckFunc @@ -695,7 +699,7 @@ func Test_logger_Fatalln(t *testing.T) { fields fields checkFunc func() error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func() error { return nil @@ -720,7 +724,7 @@ func Test_logger_Fatalln(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } if test.checkFunc == nil { test.checkFunc = defaultCheckFunc @@ -761,7 +765,7 @@ func Test_logger_Fatalf(t *testing.T) { fields fields checkFunc func() error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func() error { return nil @@ -775,7 +779,8 @@ func Test_logger_Fatalf(t *testing.T) { fields: fields{ v: 0, }, - afterFunc: func(a args) { + afterFunc: func(t *testing.T, _ args) { + t.Helper() _ = recover() }, }, @@ -789,7 +794,7 @@ func Test_logger_Fatalf(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } if test.checkFunc == nil { test.checkFunc = defaultCheckFunc @@ -824,7 +829,7 @@ func Test_logger_V(t *testing.T) { want want checkFunc func(want, bool) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got bool) error { if !reflect.DeepEqual(got, w.want) { @@ -879,7 +884,7 @@ func Test_logger_V(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } if test.checkFunc == nil { test.checkFunc = defaultCheckFunc diff --git a/internal/net/http/json/json_test.go b/internal/net/http/json/json_test.go index 0e3028e6ba..487681a75f 100644 --- a/internal/net/http/json/json_test.go +++ b/internal/net/http/json/json_test.go @@ -412,7 +412,7 @@ func TestDecodeResponse(t *testing.T) { want want checkFunc func(want, error) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, err error) error { if !errors.Is(err, w.err) { @@ -532,7 +532,7 @@ func TestDecodeResponse(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -563,7 +563,7 @@ func TestEncodeRequest(t *testing.T) { want want checkFunc func(want, error) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, err error) error { if w.err != nil && err != nil && !strings.HasPrefix(err.Error(), w.err.Error()) { @@ -645,7 +645,7 @@ func TestEncodeRequest(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -678,7 +678,7 @@ func TestRequest(t *testing.T) { want want checkFunc func(want, error) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, err error) error { if !errors.Is(err, w.err) { @@ -768,7 +768,8 @@ func TestRequest(t *testing.T) { } return nil }, - afterFunc: func(args) { + afterFunc: func(t *testing.T, _ args) { + t.Helper() srv.Close() }, } @@ -783,7 +784,7 @@ func TestRequest(t *testing.T) { test.beforeFunc(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/internal/net/net_test.go b/internal/net/net_test.go index 0d79b77185..ef5d08e680 100644 --- a/internal/net/net_test.go +++ b/internal/net/net_test.go @@ -149,8 +149,8 @@ func TestDialContext(t *testing.T) { want want srv *httptest.Server checkFunc func(want, Conn, error) error - beforeFunc func(*test) - afterFunc func(*test) + beforeFunc func(*testing.T, *test) + afterFunc func(*testing.T, *test) } defaultCheckFunc := func(w want, gotConn Conn, err error) error { if !errors.Is(err, w.err) { @@ -167,14 +167,15 @@ func TestDialContext(t *testing.T) { args: args{ network: TCP.String(), }, - beforeFunc: func(t *test) { + beforeFunc: func(t *testing.T, test *test) { + t.Helper() srvContent := "test" - t.srv = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + test.srv = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(200) fmt.Fprint(w, srvContent) })) - t.args.addr = t.srv.URL[len("http://"):] + test.args.addr = test.srv.URL[len("http://"):] }, checkFunc: func(w want, gotConn Conn, err error) error { if !errors.Is(err, w.err) { @@ -193,10 +194,11 @@ func TestDialContext(t *testing.T) { return nil }, - afterFunc: func(t *test) { - t.srv.Client().CloseIdleConnections() - t.srv.CloseClientConnections() - t.srv.Close() + afterFunc: func(t *testing.T, test *test) { + t.Helper() + test.srv.Client().CloseIdleConnections() + test.srv.CloseClientConnections() + test.srv.Close() }, }, } @@ -208,7 +210,7 @@ func TestDialContext(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() if test.beforeFunc != nil { - test.beforeFunc(test) + test.beforeFunc(tt, test) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -221,7 +223,7 @@ func TestDialContext(t *testing.T) { } if test.afterFunc != nil { - test.afterFunc(test) + test.afterFunc(tt, test) } }) } @@ -588,6 +590,7 @@ func TestScanPorts(t *testing.T) { host: "localhost", }, beforeFunc: func(t *testing.T, test *test) { + t.Helper() srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(200) })) @@ -617,6 +620,7 @@ func TestScanPorts(t *testing.T) { host: "localhost", }, beforeFunc: func(t *testing.T, test *test) { + t.Helper() srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(200) })) @@ -646,6 +650,7 @@ func TestScanPorts(t *testing.T) { host: "localhost", }, beforeFunc: func(t *testing.T, test *test) { + t.Helper() srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(200) })) @@ -675,6 +680,7 @@ func TestScanPorts(t *testing.T) { host: "localhost", }, beforeFunc: func(t *testing.T, test *test) { + t.Helper() srvNum := 20 srvs := make([]*httptest.Server, 0, srvNum) diff --git a/internal/params/params_test.go b/internal/params/params_test.go index 276bd20932..c4b868a4c1 100644 --- a/internal/params/params_test.go +++ b/internal/params/params_test.go @@ -173,8 +173,8 @@ func Test_parser_Parse(t *testing.T) { fields fields want want checkFunc func(want, Data, bool, error) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, got Data, got1 bool, err error) error { if !errors.Is(err, w.err) { @@ -215,12 +215,16 @@ func Test_parser_Parse(t *testing.T) { description: "show version", }, }, - beforeFunc: func() { + beforeFunc: func(t *testing.T) { + t.Helper() os.Args = []string{ "test", "--path=./params.go", "--version=false", } }, - afterFunc: func() { os.Args = nil }, + afterFunc: func(t *testing.T) { + t.Helper() + os.Args = nil + }, want: want{ want: &data{ configFilePath: "./params.go", @@ -231,12 +235,16 @@ func Test_parser_Parse(t *testing.T) { { name: "returns (nil, true, nil) When parse fails but the help option is set", - beforeFunc: func() { + beforeFunc: func(t *testing.T) { + t.Helper() os.Args = []string{ "test", "--help", } }, - afterFunc: func() { os.Args = nil }, + afterFunc: func(t *testing.T) { + t.Helper() + os.Args = nil + }, want: want{ want1: true, }, @@ -244,12 +252,16 @@ func Test_parser_Parse(t *testing.T) { { name: "returns (nil, true, nil) When parse fails but the help option is not set", - beforeFunc: func() { + beforeFunc: func(t *testing.T) { + t.Helper() os.Args = []string{ "test", "--name", } }, - afterFunc: func() { os.Args = nil }, + afterFunc: func(t *testing.T) { + t.Helper() + os.Args = nil + }, want: want{ want1: false, err: errors.ErrArgumentParseFailed(errors.New("flag provided but not defined: -name")), @@ -270,12 +282,16 @@ func Test_parser_Parse(t *testing.T) { description: "sets file path", }, }, - beforeFunc: func() { + beforeFunc: func(t *testing.T) { + t.Helper() os.Args = []string{ "test", "--path=config.yml", } }, - afterFunc: func() { os.Args = nil }, + afterFunc: func(t *testing.T) { + t.Helper() + os.Args = nil + }, want: want{ want1: true, err: &os.PathError{ @@ -292,10 +308,10 @@ func Test_parser_Parse(t *testing.T) { t.Run(test.name, func(tt *testing.T) { defer goleak.VerifyNone(tt) 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 { @@ -326,8 +342,8 @@ func Test_data_ConfigFilePath(t *testing.T) { fields fields want want checkFunc func(want, string) error - beforeFunc func() - afterFunc func() + beforeFunc func(*testing.T) + afterFunc func(*testing.T) } defaultCheckFunc := func(w want, got string) error { if !reflect.DeepEqual(got, w.want) { @@ -352,10 +368,10 @@ func Test_data_ConfigFilePath(t *testing.T) { t.Run(test.name, func(tt *testing.T) { defer goleak.VerifyNone(tt) 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 { @@ -385,8 +401,8 @@ func Test_data_ShowVersion(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) { @@ -411,10 +427,10 @@ func Test_data_ShowVersion(t *testing.T) { t.Run(test.name, func(tt *testing.T) { defer goleak.VerifyNone(tt) 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/internal/rand/rand_test.go b/internal/rand/rand_test.go index ab6c57738e..1e23332de1 100644 --- a/internal/rand/rand_test.go +++ b/internal/rand/rand_test.go @@ -32,22 +32,24 @@ func clearPool() { func TestUint32(t *testing.T) { type test struct { name string - beforeFunc func() + beforeFunc func(*testing.T) } tests := []test{ { name: "returns random number when pooled rand instance is nil", - beforeFunc: func() { + beforeFunc: func(t *testing.T) { + t.Helper() clearPool() }, }, } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if tt.beforeFunc != nil { - tt.beforeFunc() + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + if test.beforeFunc != nil { + test.beforeFunc(tt) } _ = Uint32() @@ -61,29 +63,31 @@ func TestUint32(t *testing.T) { func TestLimitedUint32(t *testing.T) { type test struct { name string - beforeFunc func() + beforeFunc func(*testing.T) max uint64 } tests := []test{ { name: "returns random number less than max", - beforeFunc: func() { + beforeFunc: func(t *testing.T) { + t.Helper() clearPool() }, max: 100, }, } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if tt.beforeFunc != nil { - tt.beforeFunc() + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + if test.beforeFunc != nil { + test.beforeFunc(tt) } - got := LimitedUint32(tt.max) - if got > uint32(tt.max) { - t.Errorf("more than %v. got: %v", tt.max, got) + got := LimitedUint32(test.max) + if got > uint32(test.max) { + t.Errorf("more than %v. got: %v", test.max, got) } }) } diff --git a/internal/runner/runner_race_test.go b/internal/runner/runner_race_test.go index 7c9b1312da..ddf1c788c8 100644 --- a/internal/runner/runner_race_test.go +++ b/internal/runner/runner_race_test.go @@ -40,8 +40,9 @@ func TestDo_for_race(t *testing.T) { args args want want checkFunc func(want, error) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + + afterFunc func(args) } defaultCheckFunc := func(w want, err error) error { if !errors.Is(err, w.err) { @@ -60,7 +61,8 @@ func TestDo_for_race(t *testing.T) { args: args{ ctx: context.Background(), }, - beforeFunc: func(args) { + beforeFunc: func(t *testing.T, _ args) { + t.Helper() os.Args = []string{ "test", "-version", } @@ -75,7 +77,8 @@ func TestDo_for_race(t *testing.T) { args: args{ ctx: context.Background(), }, - beforeFunc: func(args) { + beforeFunc: func(t *testing.T, _ args) { + t.Helper() os.Args = []string{ "test", "-team=set", } @@ -95,7 +98,8 @@ func TestDo_for_race(t *testing.T) { }), }, }, - beforeFunc: func(args) { + beforeFunc: func(t *testing.T, _ args) { + t.Helper() os.Args = []string{ "test", "-c=./runner.go", } @@ -123,7 +127,8 @@ func TestDo_for_race(t *testing.T) { }), }, }, - beforeFunc: func(args) { + beforeFunc: func(t *testing.T, _ args) { + t.Helper() os.Args = []string{ "test", "-c=./runner.go", } @@ -154,7 +159,8 @@ func TestDo_for_race(t *testing.T) { }), }, }, - beforeFunc: func(args) { + beforeFunc: func(t *testing.T, _ args) { + t.Helper() os.Args = []string{ "test", "-c=./runner.go", } @@ -201,7 +207,8 @@ func TestDo_for_race(t *testing.T) { }), }, }, - beforeFunc: func(args) { + beforeFunc: func(t *testing.T, _ args) { + t.Helper() os.Args = []string{ "test", "-c=./runner.go", } @@ -221,7 +228,7 @@ func TestDo_for_race(t *testing.T) { t.Run(test.name, func(tt *testing.T) { defer goleak.VerifyNone(tt, goleakIgnoreOptions...) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc == nil { test.afterFunc = defaultAfterFunc diff --git a/internal/runner/runner_test.go b/internal/runner/runner_test.go index 3aec9facff..046c2e83d7 100644 --- a/internal/runner/runner_test.go +++ b/internal/runner/runner_test.go @@ -48,8 +48,9 @@ func TestRun(t *testing.T) { args args want want checkFunc func(want, error) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + + afterFunc func(args) } defaultCheckFunc := func(w want, err error) error { if !errors.Is(err, w.err) { @@ -84,7 +85,8 @@ func TestRun(t *testing.T) { } }(), }, - beforeFunc: func(args) { + beforeFunc: func(t *testing.T, _ args) { + t.Helper() cancel() }, want: want{ @@ -120,7 +122,8 @@ func TestRun(t *testing.T) { } }(), }, - beforeFunc: func(args) { + beforeFunc: func(t *testing.T, _ args) { + t.Helper() go func() { time.Sleep(2 * time.Second) cancel() @@ -187,7 +190,8 @@ func TestRun(t *testing.T) { } }(), }, - beforeFunc: func(args) { + beforeFunc: func(t *testing.T, _ args) { + t.Helper() go func() { time.Sleep(2 * time.Second) cancel() @@ -264,7 +268,7 @@ func TestRun(t *testing.T) { t.Run(test.name, func(tt *testing.T) { defer goleak.VerifyNone(tt, goleakIgnoreOptions...) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { defer test.afterFunc(test.args) @@ -295,8 +299,9 @@ func TestDo(t *testing.T) { args args want want checkFunc func(want, error) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + + afterFunc func(args) } defaultCheckFunc := func(w want, err error) error { if !errors.Is(err, w.err) { @@ -340,7 +345,7 @@ func TestDo(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) diff --git a/internal/servers/server/server_test.go b/internal/servers/server/server_test.go index e1d40674ab..7ccee36ee1 100644 --- a/internal/servers/server/server_test.go +++ b/internal/servers/server/server_test.go @@ -62,11 +62,12 @@ func TestServerMode_String(t *testing.T) { }, } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got := tt.m.String() - if tt.want != got { - t.Errorf("String is wrong. want: %v, got: %v", tt.want, got) + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + got := test.m.String() + if test.want != got { + t.Errorf("String is wrong. want: %v, got: %v", test.want, got) } }) } @@ -392,7 +393,7 @@ func Test_server_ListenAndServe(t *testing.T) { name string args args field field - afterFunc func() + afterFunc func(*testing.T) want error } @@ -447,7 +448,8 @@ func Test_server_ListenAndServe(t *testing.T) { }, running: false, }, - afterFunc: func() { + afterFunc: func(t *testing.T) { + t.Helper() srv.Shutdown(ctx) cancel() eg.Wait() @@ -476,7 +478,8 @@ func Test_server_ListenAndServe(t *testing.T) { }, running: false, }, - afterFunc: func() { + afterFunc: func(t *testing.T) { + t.Helper() cancel() eg.Wait() }, @@ -486,23 +489,24 @@ func Test_server_ListenAndServe(t *testing.T) { } log.Init(log.WithLoggerType(logger.NOP.String())) - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { defer func() { - if tt.afterFunc != nil { - defer tt.afterFunc() + if test.afterFunc != nil { + defer test.afterFunc(tt) } }() s := &server{ - mode: tt.field.mode, - eg: tt.field.eg, + mode: test.field.mode, + eg: test.field.eg, http: struct { srv *http.Server h http.Handler starter func(net.Listener) error }{ - starter: tt.field.httpSrvStarter, + starter: test.field.httpSrvStarter, }, grpc: struct { srv *grpc.Server @@ -510,17 +514,17 @@ func Test_server_ListenAndServe(t *testing.T) { opts []grpc.ServerOption regs []func(*grpc.Server) }{ - srv: tt.field.grpcSrv, + srv: test.field.grpcSrv, }, - lc: tt.field.lc, - pwt: tt.field.pwt, - sddur: tt.field.sddur, - running: tt.field.running, - preStartFunc: tt.field.preStartFunc, + lc: test.field.lc, + pwt: test.field.pwt, + sddur: test.field.sddur, + running: test.field.running, + preStartFunc: test.field.preStartFunc, } - got := s.ListenAndServe(tt.args.ctx, tt.args.errCh) - if !errors.Is(got, tt.want) { + got := s.ListenAndServe(test.args.ctx, test.args.errCh) + if !errors.Is(got, test.want) { t.Errorf("ListenAndServe returns error: %v", got) } }) @@ -547,7 +551,7 @@ func Test_server_Shutdown(t *testing.T) { name string args args field field - afterFunc func() + afterFunc func(*testing.T) checkFunc func(s *server, got, want error) error want error } @@ -599,7 +603,8 @@ func Test_server_Shutdown(t *testing.T) { return nil }, }, - afterFunc: func() { + afterFunc: func(t *testing.T) { + t.Helper() testSrv.Close() cancel() eg.Wait() @@ -629,7 +634,8 @@ func Test_server_Shutdown(t *testing.T) { return nil }, }, - afterFunc: func() { + afterFunc: func(t *testing.T) { + t.Helper() cancel() eg.Wait() }, @@ -639,26 +645,27 @@ func Test_server_Shutdown(t *testing.T) { } log.Init(log.WithLoggerType(logger.NOP.String())) - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { defer func() { - if tt.afterFunc != nil { - defer tt.afterFunc() + if test.afterFunc != nil { + defer test.afterFunc(tt) } }() - if tt.checkFunc == nil { - tt.checkFunc = defaultCheckFunc + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc } s := &server{ - mode: tt.field.mode, - eg: tt.field.eg, + mode: test.field.mode, + eg: test.field.eg, http: struct { srv *http.Server h http.Handler starter func(net.Listener) error }{ - srv: tt.field.httpSrv, + srv: test.field.httpSrv, }, grpc: struct { srv *grpc.Server @@ -666,16 +673,16 @@ func Test_server_Shutdown(t *testing.T) { opts []grpc.ServerOption regs []func(*grpc.Server) }{ - srv: tt.field.grpcSrv, + srv: test.field.grpcSrv, }, - pwt: tt.field.pwt, - sddur: tt.field.sddur, - running: tt.field.running, - preStopFunc: tt.field.preStopFunc, + pwt: test.field.pwt, + sddur: test.field.sddur, + running: test.field.running, + preStopFunc: test.field.preStopFunc, } - got := s.Shutdown(tt.args.ctx) - if err := tt.checkFunc(s, got, tt.want); err != nil { + got := s.Shutdown(test.args.ctx) + if err := test.checkFunc(s, got, test.want); err != nil { t.Error(err) } }) diff --git a/internal/servers/servers_test.go b/internal/servers/servers_test.go index 63e16f47ab..5c7f06b02e 100644 --- a/internal/servers/servers_test.go +++ b/internal/servers/servers_test.go @@ -77,10 +77,11 @@ func TestNew(t *testing.T) { }, } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got := New(tt.opts...) - if err := tt.checkFunc(got.(*listener), tt.want); err != nil { + for _, tc := range tests { + test := tc + t.Run(test.name, func(t *testing.T) { + got := New(test.opts...) + if err := test.checkFunc(got.(*listener), test.want); err != nil { t.Error(err) } }) @@ -103,7 +104,7 @@ func Test_listener_ListenAndServe(t *testing.T) { args args field field checkFunc func(got, want <-chan error) error - afterFunc func() + afterFunc func(*testing.T) want <-chan error } @@ -185,7 +186,8 @@ func Test_listener_ListenAndServe(t *testing.T) { } return nil }, - afterFunc: func() { + afterFunc: func(t *testing.T) { + t.Helper() cancel() eg.Wait() }, @@ -193,22 +195,23 @@ func Test_listener_ListenAndServe(t *testing.T) { }(), } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - ctx, cancel := context.WithCancel(tt.args.ctx) + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + ctx, cancel := context.WithCancel(test.args.ctx) defer cancel() - if tt.afterFunc != nil { - defer tt.afterFunc() + if test.afterFunc != nil { + defer test.afterFunc(tt) } l := &listener{ - eg: tt.field.eg, - servers: tt.field.servers, - sus: tt.field.sus, + eg: test.field.eg, + servers: test.field.servers, + sus: test.field.sus, } errCh := l.ListenAndServe(ctx) - if err := tt.checkFunc(errCh, tt.want); err != nil { + if err := test.checkFunc(errCh, test.want); err != nil { t.Error(err) } }) @@ -232,7 +235,7 @@ func Test_listener_Shutdown(t *testing.T) { args args field field checkFunc func(got, want error) error - afterFunc func() + afterFunc func(*testing.T) want error } @@ -286,7 +289,8 @@ func Test_listener_Shutdown(t *testing.T) { servers: servers, sds: sds, }, - afterFunc: func() { + afterFunc: func(t *testing.T) { + t.Helper() cancel() eg.Wait() }, @@ -309,7 +313,8 @@ func Test_listener_Shutdown(t *testing.T) { "srv1", }, }, - afterFunc: func() { + afterFunc: func(t *testing.T) { + t.Helper() cancel() eg.Wait() }, @@ -349,7 +354,8 @@ func Test_listener_Shutdown(t *testing.T) { servers: servers, sds: sds, }, - afterFunc: func() { + afterFunc: func(t *testing.T) { + t.Helper() cancel() eg.Wait() }, @@ -358,27 +364,28 @@ func Test_listener_Shutdown(t *testing.T) { }(), } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - ctx, cancel := context.WithCancel(tt.args.ctx) + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + ctx, cancel := context.WithCancel(test.args.ctx) defer cancel() - if tt.afterFunc != nil { - defer tt.afterFunc() + if test.afterFunc != nil { + defer test.afterFunc(tt) } - if tt.checkFunc == nil { - tt.checkFunc = defaultCheckFunc + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc } l := &listener{ - eg: tt.field.eg, - servers: tt.field.servers, - sds: tt.field.sds, - sddur: tt.field.sddur, + eg: test.field.eg, + servers: test.field.servers, + sds: test.field.sds, + sddur: test.field.sddur, } err := l.Shutdown(ctx) - if err := tt.checkFunc(err, tt.want); err != nil { + if err := test.checkFunc(err, test.want); err != nil { t.Error(err) } }) diff --git a/internal/worker/queue_test.go b/internal/worker/queue_test.go index 1fca2cb644..66985e4f77 100644 --- a/internal/worker/queue_test.go +++ b/internal/worker/queue_test.go @@ -49,8 +49,9 @@ func TestNewQueue(t *testing.T) { args args want want checkFunc func(want, Queue, error) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + + afterFunc func(args) } defaultCheckFunc := func(w want, got Queue, err error) error { if !errors.Is(err, w.err) { @@ -135,7 +136,7 @@ func TestNewQueue(t *testing.T) { t.Run(test.name, func(tt *testing.T) { defer goleak.VerifyNone(tt, goleakIgnoreOptions...) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { defer test.afterFunc(test.args) @@ -176,8 +177,9 @@ func Test_queue_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(args) } defaultCheckFunc := func(w want, got <-chan error, err error) error { if !errors.Is(err, w.err) { @@ -223,7 +225,8 @@ func Test_queue_Start(t *testing.T) { want: want{ want: wantC, }, - beforeFunc: func(args) { + beforeFunc: func(t *testing.T, _ args) { + t.Helper() for i := 0; i < 10; i++ { inCh <- func(context.Context) error { return nil @@ -286,7 +289,8 @@ func Test_queue_Start(t *testing.T) { want: want{ want: wantC, }, - beforeFunc: func(args) { + beforeFunc: func(t *testing.T, _ args) { + t.Helper() go func() { time.Sleep(time.Millisecond * 50) cancel() @@ -322,7 +326,8 @@ func Test_queue_Start(t *testing.T) { want: want{ want: wantC, }, - beforeFunc: func(args) { + beforeFunc: func(t *testing.T, _ args) { + t.Helper() for i := 0; i < 10; i++ { inCh <- func(context.Context) error { return nil @@ -342,7 +347,7 @@ func Test_queue_Start(t *testing.T) { t.Run(test.name, func(tt *testing.T) { defer goleak.VerifyNone(tt, goleakIgnoreOptions...) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { defer test.afterFunc(test.args) @@ -455,8 +460,9 @@ func Test_queue_Push(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(args) } defaultCheckFunc := func(w want, err error) error { if !errors.Is(err, w.err) { @@ -555,7 +561,8 @@ func Test_queue_Push(t *testing.T) { want: want{ err: context.Canceled, }, - beforeFunc: func(args) { + beforeFunc: func(t *testing.T, _ args) { + t.Helper() inCh <- func(context.Context) error { return nil } @@ -573,7 +580,7 @@ func Test_queue_Push(t *testing.T) { t.Run(test.name, func(tt *testing.T) { defer goleak.VerifyNone(tt, goleakIgnoreOptions...) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { defer test.afterFunc(test.args) @@ -623,8 +630,9 @@ func Test_queue_Pop(t *testing.T) { fields fields want want checkFunc func(want, JobFunc, error) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + + afterFunc func(args) } defaultCheckFunc := func(w want, got JobFunc, err error) error { if !errors.Is(err, w.err) { @@ -665,7 +673,8 @@ func Test_queue_Pop(t *testing.T) { want: want{ want: f, }, - beforeFunc: func(args) { + beforeFunc: func(t *testing.T, _ args) { + t.Helper() outCh <- f }, } @@ -720,7 +729,8 @@ func Test_queue_Pop(t *testing.T) { want: f, err: nil, }, - beforeFunc: func(args) { + beforeFunc: func(t *testing.T, _ args) { + t.Helper() outCh <- nil outCh <- f }, @@ -756,7 +766,8 @@ func Test_queue_Pop(t *testing.T) { want: nil, err: errors.ErrJobFuncNotFound, }, - beforeFunc: func(args) { + beforeFunc: func(t *testing.T, _ args) { + t.Helper() outCh <- nil outCh <- nil outCh <- f @@ -789,7 +800,8 @@ func Test_queue_Pop(t *testing.T) { want: nil, err: context.Canceled, }, - beforeFunc: func(args) { + beforeFunc: func(t *testing.T, _ args) { + t.Helper() go func() { time.Sleep(time.Millisecond * 50) cancel() @@ -804,7 +816,7 @@ func Test_queue_Pop(t *testing.T) { t.Run(test.name, func(tt *testing.T) { defer goleak.VerifyNone(tt, goleakIgnoreOptions...) if test.beforeFunc != nil { - test.beforeFunc(test.args) + test.beforeFunc(tt, test.args) } if test.afterFunc != nil { defer test.afterFunc(test.args) diff --git a/pkg/agent/core/ngt/handler/grpc/handler_test.go b/pkg/agent/core/ngt/handler/grpc/handler_test.go index b5fdb1ffe6..32e6ef30d8 100644 --- a/pkg/agent/core/ngt/handler/grpc/handler_test.go +++ b/pkg/agent/core/ngt/handler/grpc/handler_test.go @@ -83,7 +83,6 @@ func newIndexedNGTService(ctx context.Context, eg errgroup.Group, t request.Obje } func TestNew(t *testing.T) { - t.Parallel() type args struct { opts []Option } @@ -96,12 +95,12 @@ func TestNew(t *testing.T) { args args want want checkFunc func(want, Server, error) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got Server, err error) error { if !errors.Is(err, w.err) { - return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant_error: \"%#v\"", err, w.err) + return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) } if !reflect.DeepEqual(got, w.want) { return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) @@ -118,6 +117,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() + }, }, */ @@ -131,6 +136,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() + }, } }(), */ @@ -140,11 +151,12 @@ func TestNew(t *testing.T) { test := tc t.Run(test.name, func(tt *testing.T) { tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + 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 { @@ -160,28 +172,20 @@ func TestNew(t *testing.T) { } func Test_server_newLocations(t *testing.T) { - t.Parallel() type args struct { uuids []string } - type fields struct { - name string - ip string - ngt service.NGT - eg errgroup.Group - streamConcurrency int - } type want struct { wantLocs *payload.Object_Locations } type test struct { name string args args - fields fields + s *server want want checkFunc func(want, *payload.Object_Locations) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotLocs *payload.Object_Locations) error { if !reflect.DeepEqual(gotLocs, w.wantLocs) { @@ -197,15 +201,14 @@ func Test_server_newLocations(t *testing.T) { args: args { uuids: nil, }, - fields: fields { - name: "", - ip: "", - ngt: nil, - eg: nil, - streamConcurrency: 0, - }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -217,15 +220,14 @@ func Test_server_newLocations(t *testing.T) { args: args { uuids: nil, }, - fields: fields { - name: "", - ip: "", - ngt: nil, - eg: nil, - streamConcurrency: 0, - }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -235,25 +237,19 @@ func Test_server_newLocations(t *testing.T) { test := tc t.Run(test.name, func(tt *testing.T) { tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + 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{ - name: test.fields.name, - ip: test.fields.ip, - ngt: test.fields.ngt, - eg: test.fields.eg, - streamConcurrency: test.fields.streamConcurrency, - } - gotLocs := s.newLocations(test.args.uuids...) + gotLocs := test.s.newLocations(test.args.uuids...) if err := checkFunc(test.want, gotLocs); err != nil { tt.Errorf("error = %v", err) } @@ -262,28 +258,20 @@ func Test_server_newLocations(t *testing.T) { } func Test_server_newLocation(t *testing.T) { - t.Parallel() type args struct { uuid string } - type fields struct { - name string - ip string - ngt service.NGT - eg errgroup.Group - streamConcurrency int - } type want struct { want *payload.Object_Location } type test struct { name string args args - fields fields + s *server want want checkFunc func(want, *payload.Object_Location) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, got *payload.Object_Location) error { if !reflect.DeepEqual(got, w.want) { @@ -299,15 +287,14 @@ func Test_server_newLocation(t *testing.T) { args: args { uuid: "", }, - fields: fields { - name: "", - ip: "", - ngt: nil, - eg: nil, - streamConcurrency: 0, - }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -319,15 +306,14 @@ func Test_server_newLocation(t *testing.T) { args: args { uuid: "", }, - fields: fields { - name: "", - ip: "", - ngt: nil, - eg: nil, - streamConcurrency: 0, - }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -337,25 +323,19 @@ func Test_server_newLocation(t *testing.T) { test := tc t.Run(test.name, func(tt *testing.T) { tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + 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{ - name: test.fields.name, - ip: test.fields.ip, - ngt: test.fields.ngt, - eg: test.fields.eg, - streamConcurrency: test.fields.streamConcurrency, - } - got := s.newLocation(test.args.uuid) + got := test.s.newLocation(test.args.uuid) if err := checkFunc(test.want, got); err != nil { tt.Errorf("error = %v", err) } diff --git a/pkg/agent/core/ngt/handler/grpc/index_test.go b/pkg/agent/core/ngt/handler/grpc/index_test.go index ea50cb43b3..1f9dfbd260 100644 --- a/pkg/agent/core/ngt/handler/grpc/index_test.go +++ b/pkg/agent/core/ngt/handler/grpc/index_test.go @@ -57,7 +57,7 @@ func Test_server_CreateIndex(t *testing.T) { want want checkFunc func(want, *payload.Empty, error) error beforeFunc func(*testing.T, context.Context, args, Server) - afterFunc func(args) + afterFunc func(*testing.T, args) } // common variables for test @@ -154,6 +154,7 @@ func Test_server_CreateIndex(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() if err := insert(ctx, s, 1); err != nil { t.Fatal(err) } @@ -178,6 +179,7 @@ func Test_server_CreateIndex(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() if err := insert(ctx, s, 100); err != nil { t.Fatal(err) } @@ -202,6 +204,7 @@ func Test_server_CreateIndex(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() if err := insert(ctx, s, 1); err != nil { t.Fatal(err) } @@ -234,6 +237,7 @@ func Test_server_CreateIndex(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() cnt := 100 if err := insert(ctx, s, cnt); err != nil { t.Fatal(err) @@ -267,6 +271,7 @@ func Test_server_CreateIndex(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() insertCnt := 1 removeCnt := 1 if err := insert(ctx, s, insertCnt); err != nil { @@ -296,6 +301,7 @@ func Test_server_CreateIndex(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() insertCnt := 100 removeCnt := 100 if err := insert(ctx, s, insertCnt); err != nil { @@ -344,6 +350,7 @@ func Test_server_CreateIndex(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() srv, ok := s.(*server) if !ok { t.Error("Server cannot convert to *server") @@ -382,6 +389,7 @@ func Test_server_CreateIndex(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() insertCnt := 100 if err := insert(ctx, s, insertCnt); err != nil { t.Fatal(err) @@ -407,6 +415,7 @@ func Test_server_CreateIndex(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() insertCnt := 100 if err := insert(ctx, s, insertCnt); err != nil { t.Fatal(err) @@ -432,6 +441,7 @@ func Test_server_CreateIndex(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() insertCnt := 100 if err := insert(ctx, s, insertCnt); err != nil { t.Fatal(err) @@ -457,6 +467,7 @@ func Test_server_CreateIndex(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() insertCnt := 100 if err := insert(ctx, s, insertCnt); err != nil { t.Fatal(err) @@ -476,7 +487,7 @@ func Test_server_CreateIndex(t *testing.T) { defer cancel() if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := test.checkFunc if test.checkFunc == nil { @@ -672,6 +683,7 @@ func Test_server_SaveIndex(t *testing.T) { indexPath: mkdirTemp(), }, beforeFunc: func(t *testing.T, ctx context.Context, s Server, n service.NGT) { + t.Helper() if _, err := s.Insert(ctx, irs.Requests[0]); err != nil { t.Error(err) } @@ -715,6 +727,7 @@ func Test_server_SaveIndex(t *testing.T) { indexPath: mkdirTemp(), }, beforeFunc: func(t *testing.T, ctx context.Context, s Server, n service.NGT) { + t.Helper() if _, err := s.MultiInsert(ctx, irs); err != nil { t.Error(err) } @@ -760,6 +773,7 @@ func Test_server_SaveIndex(t *testing.T) { indexPath: mkdirTemp(), }, beforeFunc: func(t *testing.T, ctx context.Context, s Server, n service.NGT) { + t.Helper() if _, err := s.MultiInsert(ctx, irs); err != nil { t.Error(err) } @@ -825,6 +839,7 @@ func Test_server_SaveIndex(t *testing.T) { indexPath: mkdirTemp(), }, beforeFunc: func(t *testing.T, ctx context.Context, s Server, n service.NGT) { + t.Helper() invalidDim := dim + 1 vecs, err := vector.GenF32Vec(vector.Gaussian, 1, invalidDim) if err != nil { @@ -912,6 +927,7 @@ func Test_server_SaveIndex(t *testing.T) { indexPath: mkdirTemp(), }, beforeFunc: func(t *testing.T, ctx context.Context, s Server, n service.NGT) { + t.Helper() if _, err := s.Insert(ctx, irs.Requests[0]); err != nil { t.Error(err) } @@ -955,6 +971,7 @@ func Test_server_SaveIndex(t *testing.T) { indexPath: mkdirTemp(), }, beforeFunc: func(t *testing.T, ctx context.Context, s Server, n service.NGT) { + t.Helper() if _, err := s.MultiInsert(ctx, irs); err != nil { t.Error(err) } @@ -1557,6 +1574,7 @@ func Test_server_CreateAndSaveIndex(t *testing.T) { indexPath: mkdirTemp(), }, beforeFunc: func(t *testing.T, ctx context.Context, s Server, n service.NGT, test test) { + t.Helper() invalidDim := dim + 1 vecs, err := vector.GenF32Vec(vector.Gaussian, 1, invalidDim) if err != nil { @@ -1929,7 +1947,7 @@ func Test_server_IndexInfo(t *testing.T) { want want checkFunc func(Server, context.Context, args, want, *payload.Info_Index_Count, error) error beforeFunc func(*testing.T, context.Context, args, Server) - afterFunc func(args) + afterFunc func(*testing.T, args) } // common variables for test @@ -2113,7 +2131,8 @@ func Test_server_IndexInfo(t *testing.T) { Saving: false, }, }, - afterFunc: func(a args) { + afterFunc: func(t *testing.T, _ args) { + t.Helper() cancel() os.RemoveAll(tmpDir) }, @@ -2151,6 +2170,7 @@ func Test_server_IndexInfo(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() if _, err := insertAndCreateIndex(s, ctx, insertCnt, false); err != nil { t.Fatal(err) } @@ -2176,6 +2196,7 @@ func Test_server_IndexInfo(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() // we need to insert request first before remove req, err := insertAndCreateIndex(s, ctx, removeCnt, true) if err != nil { @@ -2215,6 +2236,7 @@ func Test_server_IndexInfo(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() // we need vectors inserted before removal rreq, err := insertAndCreateIndex(s, ctx, removeCnt, true) if err != nil { @@ -2262,6 +2284,7 @@ func Test_server_IndexInfo(t *testing.T) { ), }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() insertCnt := 10000 if _, err := insertAndCreateIndex(s, ctx, insertCnt, false); err != nil { t.Fatal(err) @@ -2335,6 +2358,7 @@ func Test_server_IndexInfo(t *testing.T) { ), }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() insertCnt := 10000 if _, err := insertAndCreateIndex(s, ctx, insertCnt, true); err != nil { t.Fatal(err) @@ -2366,7 +2390,8 @@ func Test_server_IndexInfo(t *testing.T) { return periodicallyCheckIndexInfoFunc(s, ctx, args, w, chk) }, - afterFunc: func(a args) { + afterFunc: func(t *testing.T, _ args) { + t.Helper() os.RemoveAll(tmpDir) }, } @@ -2402,7 +2427,7 @@ func Test_server_IndexInfo(t *testing.T) { defer cancel() 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/agent/core/ngt/handler/grpc/insert_test.go b/pkg/agent/core/ngt/handler/grpc/insert_test.go index df664c332d..8d2647d159 100644 --- a/pkg/agent/core/ngt/handler/grpc/insert_test.go +++ b/pkg/agent/core/ngt/handler/grpc/insert_test.go @@ -60,7 +60,7 @@ func Test_server_Insert(t *testing.T) { fields fields want want checkFunc func(want, *payload.Object_Location, error) error - beforeFunc func(*server) + beforeFunc func(*testing.T, *server) afterFunc func(args) } defaultCheckFunc := func(w want, gotRes *payload.Object_Location, err error) error { @@ -1086,7 +1086,8 @@ func Test_server_Insert(t *testing.T) { service.WithEnableInMemoryMode(true), }, }, - beforeFunc: func(s *server) { + beforeFunc: func(t *testing.T, s *server) { + t.Helper() s.ngt.Insert(id, bVecs[0]) }, want: want{ @@ -1134,7 +1135,8 @@ func Test_server_Insert(t *testing.T) { service.WithEnableInMemoryMode(true), }, }, - beforeFunc: func(s *server) { + beforeFunc: func(t *testing.T, s *server) { + t.Helper() s.ngt.Insert(bID, intVec) }, want: want{ @@ -1176,7 +1178,8 @@ func Test_server_Insert(t *testing.T) { service.WithEnableInMemoryMode(true), }, }, - beforeFunc: func(s *server) { + beforeFunc: func(t *testing.T, s *server) { + t.Helper() s.ngt.Insert(id, intVec) }, want: want{ @@ -1227,7 +1230,8 @@ func Test_server_Insert(t *testing.T) { service.WithEnableInMemoryMode(true), }, }, - beforeFunc: func(s *server) { + beforeFunc: func(t *testing.T, s *server) { + t.Helper() s.ngt.Insert(id, bVec[0]) }, want: want{ @@ -1275,7 +1279,8 @@ func Test_server_Insert(t *testing.T) { service.WithEnableInMemoryMode(true), }, }, - beforeFunc: func(s *server) { + beforeFunc: func(t *testing.T, s *server) { + t.Helper() s.ngt.Insert(bID, intVec) }, want: want{ @@ -1317,7 +1322,8 @@ func Test_server_Insert(t *testing.T) { service.WithEnableInMemoryMode(true), }, }, - beforeFunc: func(s *server) { + beforeFunc: func(t *testing.T, s *server) { + t.Helper() s.ngt.Insert(id, intVec) }, want: want{ @@ -1365,7 +1371,7 @@ func Test_server_Insert(t *testing.T) { streamConcurrency: test.fields.streamConcurrency, } if test.beforeFunc != nil { - test.beforeFunc(s) + test.beforeFunc(tt, s) } gotRes, err := s.Insert(ctx, test.args.req) @@ -2368,6 +2374,7 @@ func Test_server_StreamInsert(t *testing.T) { ngtCfg: defaultF32SvcCfg, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() iv, err := vector.GenF32Vec(vector.Gaussian, 1, f32VecDim) if err != nil { t.Fatal(err) @@ -2417,6 +2424,7 @@ func Test_server_StreamInsert(t *testing.T) { ngtCfg: defaultF32SvcCfg, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() iv, err := vector.GenF32Vec(vector.Gaussian, 1, f32VecDim) if err != nil { t.Fatal(err) @@ -2466,6 +2474,7 @@ func Test_server_StreamInsert(t *testing.T) { ngtCfg: defaultF32SvcCfg, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() ir := &payload.Insert_Request{ Vector: &payload.Object_Vector{ Id: "non-exists-id", @@ -2506,6 +2515,7 @@ func Test_server_StreamInsert(t *testing.T) { ngtCfg: defaultF32SvcCfg, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() ir := &payload.Insert_Request{ Vector: &payload.Object_Vector{ Id: "non-exists-id", @@ -2546,6 +2556,7 @@ func Test_server_StreamInsert(t *testing.T) { ngtCfg: defaultF32SvcCfg, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() ir := &payload.Insert_Request{ Vector: &payload.Object_Vector{ Id: reqs.Requests[0].Vector.Id, @@ -2591,6 +2602,7 @@ func Test_server_StreamInsert(t *testing.T) { ngtCfg: defaultF32SvcCfg, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() ir := &payload.Insert_Request{ Vector: &payload.Object_Vector{ Id: reqs.Requests[0].Vector.Id, @@ -4972,6 +4984,7 @@ func Test_server_MultiInsert(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, s *server) { + t.Helper() vecs, err := vector.GenF32Vec(vector.Gaussian, 2, f32VecDim) if err != nil { t.Error(err) @@ -5029,6 +5042,7 @@ func Test_server_MultiInsert(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, s *server) { + t.Helper() vecs, err := vector.GenF32Vec(vector.Gaussian, insertNum, f32VecDim) if err != nil { t.Error(err) @@ -5077,6 +5091,7 @@ func Test_server_MultiInsert(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, s *server) { + t.Helper() vecs, err := vector.GenF32Vec(vector.Gaussian, 2, f32VecDim) if err != nil { t.Error(err) @@ -5134,6 +5149,7 @@ func Test_server_MultiInsert(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, s *server) { + t.Helper() vecs, err := vector.GenF32Vec(vector.Gaussian, insertNum, f32VecDim) if err != nil { t.Error(err) @@ -5182,6 +5198,7 @@ func Test_server_MultiInsert(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, s *server) { + t.Helper() // insert same request with different ID for i := 0; i < 2; i++ { ir := &payload.Insert_Request{ @@ -5227,6 +5244,7 @@ func Test_server_MultiInsert(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, s *server) { + t.Helper() // insert same request with different ID for i := range req.Requests { ir := &payload.Insert_Request{ @@ -5272,6 +5290,7 @@ func Test_server_MultiInsert(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, s *server) { + t.Helper() // insert same request with different ID for i := 0; i < 2; i++ { ir := &payload.Insert_Request{ @@ -5317,6 +5336,7 @@ func Test_server_MultiInsert(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, s *server) { + t.Helper() // insert same request with different ID for i := range req.Requests { ir := &payload.Insert_Request{ @@ -5362,6 +5382,7 @@ func Test_server_MultiInsert(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, s *server) { + t.Helper() for i := 0; i < 2; i++ { ir := &payload.Insert_Request{ Vector: req.Requests[i].Vector, @@ -5412,6 +5433,7 @@ func Test_server_MultiInsert(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, s *server) { + t.Helper() for _, r := range req.Requests { ir := &payload.Insert_Request{ Vector: r.Vector, @@ -5453,6 +5475,7 @@ func Test_server_MultiInsert(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, s *server) { + t.Helper() for i := 0; i < 2; i++ { ir := &payload.Insert_Request{ Vector: req.Requests[i].Vector, @@ -5503,6 +5526,7 @@ func Test_server_MultiInsert(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, s *server) { + t.Helper() for _, r := range req.Requests { ir := &payload.Insert_Request{ Vector: r.Vector, diff --git a/pkg/agent/core/ngt/handler/grpc/linear_search_test.go b/pkg/agent/core/ngt/handler/grpc/linear_search_test.go index bd6d977ad8..67290afd99 100644 --- a/pkg/agent/core/ngt/handler/grpc/linear_search_test.go +++ b/pkg/agent/core/ngt/handler/grpc/linear_search_test.go @@ -18,29 +18,17 @@ import ( "reflect" "testing" - agent "github.com/vdaas/vald/apis/grpc/v1/agent/core" "github.com/vdaas/vald/apis/grpc/v1/payload" "github.com/vdaas/vald/apis/grpc/v1/vald" - "github.com/vdaas/vald/internal/errgroup" "github.com/vdaas/vald/internal/errors" - "github.com/vdaas/vald/pkg/agent/core/ngt/service" + "github.com/vdaas/vald/internal/test/goleak" ) func Test_server_LinearSearch(t *testing.T) { - t.Parallel() type args struct { ctx context.Context req *payload.Search_Request } - type fields struct { - name string - ip string - ngt service.NGT - eg errgroup.Group - streamConcurrency int - UnimplementedAgentServer agent.UnimplementedAgentServer - UnimplementedValdServer vald.UnimplementedValdServer - } type want struct { wantRes *payload.Search_Response err error @@ -48,11 +36,11 @@ func Test_server_LinearSearch(t *testing.T) { type test struct { name string args args - fields fields + s *server want want checkFunc func(want, *payload.Search_Response, error) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotRes *payload.Search_Response, err error) error { if !errors.Is(err, w.err) { @@ -72,17 +60,14 @@ func Test_server_LinearSearch(t *testing.T) { ctx: nil, req: nil, }, - fields: fields { - name: "", - ip: "", - ngt: nil, - eg: nil, - streamConcurrency: 0, - UnimplementedAgentServer: nil, - UnimplementedValdServer: nil, - }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -95,17 +80,14 @@ func Test_server_LinearSearch(t *testing.T) { ctx: nil, req: nil, }, - fields: fields { - name: "", - ip: "", - ngt: nil, - eg: nil, - streamConcurrency: 0, - UnimplementedAgentServer: nil, - UnimplementedValdServer: nil, - }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -115,27 +97,20 @@ func Test_server_LinearSearch(t *testing.T) { test := tc t.Run(test.name, func(tt *testing.T) { tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + 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 { - test.checkFunc = defaultCheckFunc - } - s := &server{ - name: test.fields.name, - ip: test.fields.ip, - ngt: test.fields.ngt, - eg: test.fields.eg, - streamConcurrency: test.fields.streamConcurrency, - UnimplementedAgentServer: test.fields.UnimplementedAgentServer, - UnimplementedValdServer: test.fields.UnimplementedValdServer, + checkFunc = defaultCheckFunc } - gotRes, err := s.LinearSearch(test.args.ctx, test.args.req) - if err := test.checkFunc(test.want, gotRes, err); err != nil { + gotRes, err := test.s.LinearSearch(test.args.ctx, test.args.req) + if err := checkFunc(test.want, gotRes, err); err != nil { tt.Errorf("error = %v", err) } }) @@ -143,20 +118,10 @@ func Test_server_LinearSearch(t *testing.T) { } func Test_server_LinearSearchByID(t *testing.T) { - t.Parallel() type args struct { ctx context.Context req *payload.Search_IDRequest } - type fields struct { - name string - ip string - ngt service.NGT - eg errgroup.Group - streamConcurrency int - UnimplementedAgentServer agent.UnimplementedAgentServer - UnimplementedValdServer vald.UnimplementedValdServer - } type want struct { wantRes *payload.Search_Response err error @@ -164,11 +129,11 @@ func Test_server_LinearSearchByID(t *testing.T) { type test struct { name string args args - fields fields + s *server want want checkFunc func(want, *payload.Search_Response, error) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotRes *payload.Search_Response, err error) error { if !errors.Is(err, w.err) { @@ -188,17 +153,14 @@ func Test_server_LinearSearchByID(t *testing.T) { ctx: nil, req: nil, }, - fields: fields { - name: "", - ip: "", - ngt: nil, - eg: nil, - streamConcurrency: 0, - UnimplementedAgentServer: nil, - UnimplementedValdServer: nil, - }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -211,17 +173,14 @@ func Test_server_LinearSearchByID(t *testing.T) { ctx: nil, req: nil, }, - fields: fields { - name: "", - ip: "", - ngt: nil, - eg: nil, - streamConcurrency: 0, - UnimplementedAgentServer: nil, - UnimplementedValdServer: nil, - }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -231,27 +190,20 @@ func Test_server_LinearSearchByID(t *testing.T) { test := tc t.Run(test.name, func(tt *testing.T) { tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + 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 { - test.checkFunc = defaultCheckFunc - } - s := &server{ - name: test.fields.name, - ip: test.fields.ip, - ngt: test.fields.ngt, - eg: test.fields.eg, - streamConcurrency: test.fields.streamConcurrency, - UnimplementedAgentServer: test.fields.UnimplementedAgentServer, - UnimplementedValdServer: test.fields.UnimplementedValdServer, + checkFunc = defaultCheckFunc } - gotRes, err := s.LinearSearchByID(test.args.ctx, test.args.req) - if err := test.checkFunc(test.want, gotRes, err); err != nil { + gotRes, err := test.s.LinearSearchByID(test.args.ctx, test.args.req) + if err := checkFunc(test.want, gotRes, err); err != nil { tt.Errorf("error = %v", err) } }) @@ -259,30 +211,20 @@ func Test_server_LinearSearchByID(t *testing.T) { } func Test_server_StreamLinearSearch(t *testing.T) { - t.Parallel() type args struct { stream vald.Search_StreamLinearSearchServer } - type fields struct { - name string - ip string - ngt service.NGT - eg errgroup.Group - streamConcurrency int - UnimplementedAgentServer agent.UnimplementedAgentServer - UnimplementedValdServer vald.UnimplementedValdServer - } type want struct { err error } type test struct { name string args args - fields fields + s *server 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) { @@ -298,17 +240,14 @@ func Test_server_StreamLinearSearch(t *testing.T) { args: args { stream: nil, }, - fields: fields { - name: "", - ip: "", - ngt: nil, - eg: nil, - streamConcurrency: 0, - UnimplementedAgentServer: nil, - UnimplementedValdServer: nil, - }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -320,17 +259,14 @@ func Test_server_StreamLinearSearch(t *testing.T) { args: args { stream: nil, }, - fields: fields { - name: "", - ip: "", - ngt: nil, - eg: nil, - streamConcurrency: 0, - UnimplementedAgentServer: nil, - UnimplementedValdServer: nil, - }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -340,27 +276,20 @@ func Test_server_StreamLinearSearch(t *testing.T) { test := tc t.Run(test.name, func(tt *testing.T) { tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + 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 { - test.checkFunc = defaultCheckFunc - } - s := &server{ - name: test.fields.name, - ip: test.fields.ip, - ngt: test.fields.ngt, - eg: test.fields.eg, - streamConcurrency: test.fields.streamConcurrency, - UnimplementedAgentServer: test.fields.UnimplementedAgentServer, - UnimplementedValdServer: test.fields.UnimplementedValdServer, + checkFunc = defaultCheckFunc } - err := s.StreamLinearSearch(test.args.stream) - if err := test.checkFunc(test.want, err); err != nil { + err := test.s.StreamLinearSearch(test.args.stream) + if err := checkFunc(test.want, err); err != nil { tt.Errorf("error = %v", err) } }) @@ -368,30 +297,20 @@ func Test_server_StreamLinearSearch(t *testing.T) { } func Test_server_StreamLinearSearchByID(t *testing.T) { - t.Parallel() type args struct { stream vald.Search_StreamLinearSearchByIDServer } - type fields struct { - name string - ip string - ngt service.NGT - eg errgroup.Group - streamConcurrency int - UnimplementedAgentServer agent.UnimplementedAgentServer - UnimplementedValdServer vald.UnimplementedValdServer - } type want struct { err error } type test struct { name string args args - fields fields + s *server 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) { @@ -407,17 +326,14 @@ func Test_server_StreamLinearSearchByID(t *testing.T) { args: args { stream: nil, }, - fields: fields { - name: "", - ip: "", - ngt: nil, - eg: nil, - streamConcurrency: 0, - UnimplementedAgentServer: nil, - UnimplementedValdServer: nil, - }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -429,17 +345,14 @@ func Test_server_StreamLinearSearchByID(t *testing.T) { args: args { stream: nil, }, - fields: fields { - name: "", - ip: "", - ngt: nil, - eg: nil, - streamConcurrency: 0, - UnimplementedAgentServer: nil, - UnimplementedValdServer: nil, - }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -449,27 +362,20 @@ func Test_server_StreamLinearSearchByID(t *testing.T) { test := tc t.Run(test.name, func(tt *testing.T) { tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + 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 { - test.checkFunc = defaultCheckFunc - } - s := &server{ - name: test.fields.name, - ip: test.fields.ip, - ngt: test.fields.ngt, - eg: test.fields.eg, - streamConcurrency: test.fields.streamConcurrency, - UnimplementedAgentServer: test.fields.UnimplementedAgentServer, - UnimplementedValdServer: test.fields.UnimplementedValdServer, + checkFunc = defaultCheckFunc } - err := s.StreamLinearSearchByID(test.args.stream) - if err := test.checkFunc(test.want, err); err != nil { + err := test.s.StreamLinearSearchByID(test.args.stream) + if err := checkFunc(test.want, err); err != nil { tt.Errorf("error = %v", err) } }) @@ -477,20 +383,10 @@ func Test_server_StreamLinearSearchByID(t *testing.T) { } func Test_server_MultiLinearSearch(t *testing.T) { - t.Parallel() type args struct { ctx context.Context reqs *payload.Search_MultiRequest } - type fields struct { - name string - ip string - ngt service.NGT - eg errgroup.Group - streamConcurrency int - UnimplementedAgentServer agent.UnimplementedAgentServer - UnimplementedValdServer vald.UnimplementedValdServer - } type want struct { wantRes *payload.Search_Responses err error @@ -498,11 +394,11 @@ func Test_server_MultiLinearSearch(t *testing.T) { type test struct { name string args args - fields fields + s *server want want checkFunc func(want, *payload.Search_Responses, error) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotRes *payload.Search_Responses, err error) error { if !errors.Is(err, w.err) { @@ -522,17 +418,14 @@ func Test_server_MultiLinearSearch(t *testing.T) { ctx: nil, reqs: nil, }, - fields: fields { - name: "", - ip: "", - ngt: nil, - eg: nil, - streamConcurrency: 0, - UnimplementedAgentServer: nil, - UnimplementedValdServer: nil, - }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -545,17 +438,14 @@ func Test_server_MultiLinearSearch(t *testing.T) { ctx: nil, reqs: nil, }, - fields: fields { - name: "", - ip: "", - ngt: nil, - eg: nil, - streamConcurrency: 0, - UnimplementedAgentServer: nil, - UnimplementedValdServer: nil, - }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -565,27 +455,20 @@ func Test_server_MultiLinearSearch(t *testing.T) { test := tc t.Run(test.name, func(tt *testing.T) { tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + 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 { - test.checkFunc = defaultCheckFunc - } - s := &server{ - name: test.fields.name, - ip: test.fields.ip, - ngt: test.fields.ngt, - eg: test.fields.eg, - streamConcurrency: test.fields.streamConcurrency, - UnimplementedAgentServer: test.fields.UnimplementedAgentServer, - UnimplementedValdServer: test.fields.UnimplementedValdServer, + checkFunc = defaultCheckFunc } - gotRes, err := s.MultiLinearSearch(test.args.ctx, test.args.reqs) - if err := test.checkFunc(test.want, gotRes, err); err != nil { + gotRes, err := test.s.MultiLinearSearch(test.args.ctx, test.args.reqs) + if err := checkFunc(test.want, gotRes, err); err != nil { tt.Errorf("error = %v", err) } }) @@ -593,20 +476,10 @@ func Test_server_MultiLinearSearch(t *testing.T) { } func Test_server_MultiLinearSearchByID(t *testing.T) { - t.Parallel() type args struct { ctx context.Context reqs *payload.Search_MultiIDRequest } - type fields struct { - name string - ip string - ngt service.NGT - eg errgroup.Group - streamConcurrency int - UnimplementedAgentServer agent.UnimplementedAgentServer - UnimplementedValdServer vald.UnimplementedValdServer - } type want struct { wantRes *payload.Search_Responses err error @@ -614,11 +487,11 @@ func Test_server_MultiLinearSearchByID(t *testing.T) { type test struct { name string args args - fields fields + s *server want want checkFunc func(want, *payload.Search_Responses, error) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotRes *payload.Search_Responses, err error) error { if !errors.Is(err, w.err) { @@ -638,17 +511,14 @@ func Test_server_MultiLinearSearchByID(t *testing.T) { ctx: nil, reqs: nil, }, - fields: fields { - name: "", - ip: "", - ngt: nil, - eg: nil, - streamConcurrency: 0, - UnimplementedAgentServer: nil, - UnimplementedValdServer: nil, - }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -661,17 +531,14 @@ func Test_server_MultiLinearSearchByID(t *testing.T) { ctx: nil, reqs: nil, }, - fields: fields { - name: "", - ip: "", - ngt: nil, - eg: nil, - streamConcurrency: 0, - UnimplementedAgentServer: nil, - UnimplementedValdServer: nil, - }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -681,27 +548,20 @@ func Test_server_MultiLinearSearchByID(t *testing.T) { test := tc t.Run(test.name, func(tt *testing.T) { tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + 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 { - test.checkFunc = defaultCheckFunc - } - s := &server{ - name: test.fields.name, - ip: test.fields.ip, - ngt: test.fields.ngt, - eg: test.fields.eg, - streamConcurrency: test.fields.streamConcurrency, - UnimplementedAgentServer: test.fields.UnimplementedAgentServer, - UnimplementedValdServer: test.fields.UnimplementedValdServer, + checkFunc = defaultCheckFunc } - gotRes, err := s.MultiLinearSearchByID(test.args.ctx, test.args.reqs) - if err := test.checkFunc(test.want, gotRes, err); err != nil { + gotRes, err := test.s.MultiLinearSearchByID(test.args.ctx, test.args.reqs) + if err := checkFunc(test.want, gotRes, err); err != nil { tt.Errorf("error = %v", err) } }) diff --git a/pkg/agent/core/ngt/handler/grpc/object_test.go b/pkg/agent/core/ngt/handler/grpc/object_test.go index a709b41895..bccd75b985 100644 --- a/pkg/agent/core/ngt/handler/grpc/object_test.go +++ b/pkg/agent/core/ngt/handler/grpc/object_test.go @@ -30,6 +30,7 @@ import ( "github.com/vdaas/vald/internal/net/grpc/status" "github.com/vdaas/vald/internal/test/data/request" "github.com/vdaas/vald/internal/test/data/vector" + "github.com/vdaas/vald/internal/test/goleak" "github.com/vdaas/vald/pkg/agent/core/ngt/service" ) @@ -48,7 +49,7 @@ func Test_server_Exists(t *testing.T) { args args want want checkFunc func(want, *payload.Object_ID, error) error - beforeFunc func(context.Context, args) (Server, error) + beforeFunc func(*testing.T, context.Context, args) (Server, error) afterFunc func(args) } defaultCheckFunc := func(w want, gotRes *payload.Object_ID, err error) error { @@ -96,7 +97,8 @@ func Test_server_Exists(t *testing.T) { defaultInsertConfig := &payload.Insert_Config{ SkipStrictExistCheck: true, } - defaultBeforeFunc := func(ctx context.Context, a args) (Server, error) { + defaultBeforeFunc := func(t *testing.T, ctx context.Context, a args) (Server, error) { + t.Helper() eg, ctx := errgroup.New(ctx) ngt, err := newIndexedNGTService(ctx, eg, request.Float, vector.Gaussian, insertNum, defaultInsertConfig, defaultNgtConfig, nil, []string{a.indexID}, nil) if err != nil { @@ -317,7 +319,7 @@ func Test_server_Exists(t *testing.T) { if test.beforeFunc == nil { test.beforeFunc = defaultBeforeFunc } - s, err := test.beforeFunc(ctx, test.args) + s, err := test.beforeFunc(tt, ctx, test.args) if err != nil { tt.Errorf("error = %v", err) } @@ -485,6 +487,7 @@ func Test_server_GetObject(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() insertAndCreateIndex(t, ctx, s, ir) }, want: want{ @@ -520,6 +523,7 @@ func Test_server_GetObject(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() insertAndCreateIndex(t, ctx, s, ir) }, want: want{ @@ -554,6 +558,7 @@ func Test_server_GetObject(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() insertAndCreateIndex(t, ctx, s, ir) }, want: want{ @@ -587,6 +592,7 @@ func Test_server_GetObject(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() insertAndCreateIndex(t, ctx, s, ir) }, want: want{ @@ -623,6 +629,7 @@ func Test_server_GetObject(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() insertAndCreateIndex(t, ctx, s, ir) }, want: want{ @@ -659,6 +666,7 @@ func Test_server_GetObject(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() insertAndCreateIndex(t, ctx, s, ir) }, want: want{ @@ -695,6 +703,7 @@ func Test_server_GetObject(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() insertAndCreateIndex(t, ctx, s, ir) }, want: want{ @@ -731,6 +740,7 @@ func Test_server_GetObject(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() insertAndCreateIndex(t, ctx, s, ir) }, want: want{ @@ -767,6 +777,7 @@ func Test_server_GetObject(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() insertAndCreateIndex(t, ctx, s, ir) }, want: want{ @@ -803,6 +814,7 @@ func Test_server_GetObject(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() insertAndCreateIndex(t, ctx, s, ir) }, want: want{ @@ -839,6 +851,7 @@ func Test_server_GetObject(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() insertAndCreateIndex(t, ctx, s, ir) }, want: want{ @@ -872,6 +885,7 @@ func Test_server_GetObject(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() insertAndCreateIndex(t, ctx, s, ir) }, want: want{ @@ -905,6 +919,7 @@ func Test_server_GetObject(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() insertAndCreateIndex(t, ctx, s, ir) }, want: want{ @@ -938,6 +953,7 @@ func Test_server_GetObject(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() insertAndCreateIndex(t, ctx, s, ir) }, want: want{ @@ -974,6 +990,7 @@ func Test_server_GetObject(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() insertAndCreateIndex(t, ctx, s, ir) }, want: want{ @@ -1007,6 +1024,7 @@ func Test_server_GetObject(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() insertAndCreateIndex(t, ctx, s, ir) }, want: want{ @@ -1040,6 +1058,7 @@ func Test_server_GetObject(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() insertAndCreateIndex(t, ctx, s, ir) }, want: want{ @@ -1073,6 +1092,7 @@ func Test_server_GetObject(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() insertAndCreateIndex(t, ctx, s, ir) }, want: want{ @@ -1109,6 +1129,7 @@ func Test_server_GetObject(t *testing.T) { svcOpts: defaultSvcOpts, }, beforeFunc: func(t *testing.T, ctx context.Context, a args, s Server) { + t.Helper() insertAndCreateIndex(t, ctx, s, ir) }, want: want{ @@ -1161,28 +1182,20 @@ func Test_server_GetObject(t *testing.T) { } func Test_server_StreamGetObject(t *testing.T) { - t.Parallel() type args struct { stream vald.Object_StreamGetObjectServer } - type fields struct { - name string - ip string - ngt service.NGT - eg errgroup.Group - streamConcurrency int - } type want struct { err error } type test struct { name string args args - fields fields + s *server 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) { @@ -1198,15 +1211,14 @@ func Test_server_StreamGetObject(t *testing.T) { args: args { stream: nil, }, - fields: fields { - name: "", - ip: "", - ngt: nil, - eg: nil, - streamConcurrency: 0, - }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -1218,15 +1230,14 @@ func Test_server_StreamGetObject(t *testing.T) { args: args { stream: nil, }, - fields: fields { - name: "", - ip: "", - ngt: nil, - eg: nil, - streamConcurrency: 0, - }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -1236,25 +1247,19 @@ func Test_server_StreamGetObject(t *testing.T) { test := tc t.Run(test.name, func(tt *testing.T) { tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + 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{ - name: test.fields.name, - ip: test.fields.ip, - ngt: test.fields.ngt, - eg: test.fields.eg, - streamConcurrency: test.fields.streamConcurrency, - } - err := s.StreamGetObject(test.args.stream) + err := test.s.StreamGetObject(test.args.stream) if err := checkFunc(test.want, err); err != nil { tt.Errorf("error = %v", err) } diff --git a/pkg/agent/core/ngt/handler/grpc/remove_test.go b/pkg/agent/core/ngt/handler/grpc/remove_test.go index 2bc81fc308..9be888ab70 100644 --- a/pkg/agent/core/ngt/handler/grpc/remove_test.go +++ b/pkg/agent/core/ngt/handler/grpc/remove_test.go @@ -29,7 +29,7 @@ import ( "github.com/vdaas/vald/internal/net/grpc/status" "github.com/vdaas/vald/internal/test/data/request" "github.com/vdaas/vald/internal/test/data/vector" - "github.com/vdaas/vald/pkg/agent/core/ngt/service" + "github.com/vdaas/vald/internal/test/goleak" ) func Test_server_Remove(t *testing.T) { @@ -48,7 +48,7 @@ func Test_server_Remove(t *testing.T) { args args want want checkFunc func(want, *payload.Object_Location, error) error - beforeFunc func(context.Context, args) (Server, error) + beforeFunc func(*testing.T, context.Context, args) (Server, error) afterFunc func(args) } defaultCheckFunc := func(w want, gotRes *payload.Object_Location, err error) error { @@ -99,7 +99,8 @@ func Test_server_Remove(t *testing.T) { defaultInsertConfig := &payload.Insert_Config{ SkipStrictExistCheck: true, } - defaultBeforeFunc := func(ctx context.Context, a args) (Server, error) { + defaultBeforeFunc := func(t *testing.T, ctx context.Context, a args) (Server, error) { + t.Helper() eg, ctx := errgroup.New(ctx) ngt, err := newIndexedNGTService(ctx, eg, request.Float, vector.Gaussian, insertNum, defaultInsertConfig, defaultNgtConfig, nil, []string{a.indexID}, nil) if err != nil { @@ -342,7 +343,7 @@ func Test_server_Remove(t *testing.T) { if test.beforeFunc == nil { test.beforeFunc = defaultBeforeFunc } - s, err := test.beforeFunc(ctx, test.args) + s, err := test.beforeFunc(tt, ctx, test.args) if err != nil { tt.Errorf("error = %v", err) } @@ -368,28 +369,20 @@ func Test_server_Remove(t *testing.T) { } func Test_server_StreamRemove(t *testing.T) { - t.Parallel() type args struct { stream vald.Remove_StreamRemoveServer } - type fields struct { - name string - ip string - ngt service.NGT - eg errgroup.Group - streamConcurrency int - } type want struct { err error } type test struct { name string args args - fields fields + s *server 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) { @@ -405,15 +398,14 @@ func Test_server_StreamRemove(t *testing.T) { args: args { stream: nil, }, - fields: fields { - name: "", - ip: "", - ngt: nil, - eg: nil, - streamConcurrency: 0, - }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -425,15 +417,14 @@ func Test_server_StreamRemove(t *testing.T) { args: args { stream: nil, }, - fields: fields { - name: "", - ip: "", - ngt: nil, - eg: nil, - streamConcurrency: 0, - }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -443,25 +434,19 @@ func Test_server_StreamRemove(t *testing.T) { test := tc t.Run(test.name, func(tt *testing.T) { tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + 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{ - name: test.fields.name, - ip: test.fields.ip, - ngt: test.fields.ngt, - eg: test.fields.eg, - streamConcurrency: test.fields.streamConcurrency, - } - err := s.StreamRemove(test.args.stream) + err := test.s.StreamRemove(test.args.stream) if err := checkFunc(test.want, err); err != nil { tt.Errorf("error = %v", err) } @@ -470,18 +455,10 @@ func Test_server_StreamRemove(t *testing.T) { } func Test_server_MultiRemove(t *testing.T) { - t.Parallel() type args struct { ctx context.Context reqs *payload.Remove_MultiRequest } - type fields struct { - name string - ip string - ngt service.NGT - eg errgroup.Group - streamConcurrency int - } type want struct { wantRes *payload.Object_Locations err error @@ -489,11 +466,11 @@ func Test_server_MultiRemove(t *testing.T) { type test struct { name string args args - fields fields + s *server want want checkFunc func(want, *payload.Object_Locations, error) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotRes *payload.Object_Locations, err error) error { if !errors.Is(err, w.err) { @@ -513,15 +490,14 @@ func Test_server_MultiRemove(t *testing.T) { ctx: nil, reqs: nil, }, - fields: fields { - name: "", - ip: "", - ngt: nil, - eg: nil, - streamConcurrency: 0, - }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -534,15 +510,14 @@ func Test_server_MultiRemove(t *testing.T) { ctx: nil, reqs: nil, }, - fields: fields { - name: "", - ip: "", - ngt: nil, - eg: nil, - streamConcurrency: 0, - }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -552,25 +527,19 @@ func Test_server_MultiRemove(t *testing.T) { test := tc t.Run(test.name, func(tt *testing.T) { tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + 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{ - name: test.fields.name, - ip: test.fields.ip, - ngt: test.fields.ngt, - eg: test.fields.eg, - streamConcurrency: test.fields.streamConcurrency, - } - gotRes, err := s.MultiRemove(test.args.ctx, test.args.reqs) + gotRes, err := test.s.MultiRemove(test.args.ctx, test.args.reqs) if err := checkFunc(test.want, gotRes, err); err != nil { tt.Errorf("error = %v", err) } diff --git a/pkg/agent/core/ngt/handler/grpc/search_test.go b/pkg/agent/core/ngt/handler/grpc/search_test.go index 789b77e419..c948787f13 100644 --- a/pkg/agent/core/ngt/handler/grpc/search_test.go +++ b/pkg/agent/core/ngt/handler/grpc/search_test.go @@ -31,6 +31,7 @@ import ( "github.com/vdaas/vald/internal/net/grpc/status" "github.com/vdaas/vald/internal/test/data/request" "github.com/vdaas/vald/internal/test/data/vector" + "github.com/vdaas/vald/internal/test/goleak" "github.com/vdaas/vald/pkg/agent/core/ngt/model" "github.com/vdaas/vald/pkg/agent/core/ngt/service" ) @@ -60,7 +61,7 @@ func Test_server_Search(t *testing.T) { fields fields want want checkFunc func(want, *payload.Search_Response, error) error - beforeFunc func(context.Context, fields, args) (Server, error) + beforeFunc func(*testing.T, context.Context, fields, args) (Server, error) afterFunc func(args) } @@ -71,7 +72,8 @@ func Test_server_Search(t *testing.T) { defaultInsertConfig := &payload.Insert_Config{ SkipStrictExistCheck: true, } - defaultBeforeFunc := func(ctx context.Context, f fields, a args) (Server, error) { + defaultBeforeFunc := func(t *testing.T, ctx context.Context, f fields, a args) (Server, error) { + t.Helper() eg, ctx := errgroup.New(ctx) ngt, err := newIndexedNGTService(ctx, eg, f.objectType, f.distribution, a.insertNum, defaultInsertConfig, f.ngtCfg, f.ngtOpts, nil, f.overwriteVec) if err != nil { @@ -775,7 +777,7 @@ func Test_server_Search(t *testing.T) { if test.beforeFunc == nil { test.beforeFunc = defaultBeforeFunc } - s, err := test.beforeFunc(ctx, test.fields, test.args) + s, err := test.beforeFunc(tt, ctx, test.fields, test.args) if err != nil { tt.Errorf("error = %v", err) } @@ -811,7 +813,7 @@ func Test_server_SearchByID(t *testing.T) { args args want want checkFunc func(want, *payload.Search_Response, error) error - beforeFunc func(context.Context, args) (Server, error) + beforeFunc func(*testing.T, context.Context, args) (Server, error) afterFunc func(args) } defaultCheckFunc := func(w want, gotRes *payload.Search_Response, err error) error { @@ -861,7 +863,8 @@ func Test_server_SearchByID(t *testing.T) { defaultInsertConfig := &payload.Insert_Config{ SkipStrictExistCheck: true, } - defaultBeforeFunc := func(ctx context.Context, a args) (Server, error) { + defaultBeforeFunc := func(t *testing.T, ctx context.Context, a args) (Server, error) { + t.Helper() eg, ctx := errgroup.New(ctx) ngt, err := newIndexedNGTService(ctx, eg, request.Float, vector.Gaussian, insertNum, defaultInsertConfig, defaultNgtConfig, nil, []string{a.indexID}, nil) if err != nil { @@ -1117,7 +1120,7 @@ func Test_server_SearchByID(t *testing.T) { if test.beforeFunc == nil { test.beforeFunc = defaultBeforeFunc } - s, err := test.beforeFunc(ctx, test.args) + s, err := test.beforeFunc(tt, ctx, test.args) if err != nil { tt.Errorf("error = %v", err) } @@ -1141,31 +1144,26 @@ func Test_server_SearchByID(t *testing.T) { } } -func Test_toSearchResponse(t *testing.T) { - t.Parallel() +func Test_server_StreamSearch(t *testing.T) { type args struct { - dists []model.Distance - err error + stream vald.Search_StreamSearchServer } type want struct { - wantRes *payload.Search_Response - err error + err error } type test struct { name string args args + s *server want want - checkFunc func(want, *payload.Search_Response, error) error - beforeFunc func(args) - afterFunc func(args) + checkFunc func(want, error) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } - defaultCheckFunc := func(w want, gotRes *payload.Search_Response, err error) error { + defaultCheckFunc := func(w want, err error) error { if !errors.Is(err, w.err) { return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) } - if !reflect.DeepEqual(gotRes, w.wantRes) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", gotRes, w.wantRes) - } return nil } tests := []test{ @@ -1174,11 +1172,16 @@ func Test_toSearchResponse(t *testing.T) { { name: "test_case_1", args: args { - dists: nil, - err: nil, + stream: nil, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -1188,11 +1191,16 @@ func Test_toSearchResponse(t *testing.T) { return test { name: "test_case_2", args: args { - dists: nil, - err: nil, + stream: nil, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -1202,36 +1210,29 @@ func Test_toSearchResponse(t *testing.T) { test := tc t.Run(test.name, func(tt *testing.T) { tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + 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 } - gotRes, err := toSearchResponse(test.args.dists, test.args.err) - if err := checkFunc(test.want, gotRes, err); err != nil { + err := test.s.StreamSearch(test.args.stream) + if err := checkFunc(test.want, err); err != nil { tt.Errorf("error = %v", err) } }) } } -func Test_server_StreamSearch(t *testing.T) { - t.Parallel() +func Test_server_StreamSearchByID(t *testing.T) { type args struct { - stream vald.Search_StreamSearchServer - } - type fields struct { - name string - ip string - ngt service.NGT - eg errgroup.Group - streamConcurrency int + stream vald.Search_StreamSearchByIDServer } type want struct { err error @@ -1239,11 +1240,11 @@ func Test_server_StreamSearch(t *testing.T) { type test struct { name string args args - fields fields + s *server 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) { @@ -1259,15 +1260,14 @@ func Test_server_StreamSearch(t *testing.T) { args: args { stream: nil, }, - fields: fields { - name: "", - ip: "", - ngt: nil, - eg: nil, - streamConcurrency: 0, - }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -1279,15 +1279,14 @@ func Test_server_StreamSearch(t *testing.T) { args: args { stream: nil, }, - fields: fields { - name: "", - ip: "", - ngt: nil, - eg: nil, - streamConcurrency: 0, - }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -1297,25 +1296,19 @@ func Test_server_StreamSearch(t *testing.T) { test := tc t.Run(test.name, func(tt *testing.T) { tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + 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{ - name: test.fields.name, - ip: test.fields.ip, - ngt: test.fields.ngt, - eg: test.fields.eg, - streamConcurrency: test.fields.streamConcurrency, - } - err := s.StreamSearch(test.args.stream) + err := test.s.StreamSearchByID(test.args.stream) if err := checkFunc(test.want, err); err != nil { tt.Errorf("error = %v", err) } @@ -1323,34 +1316,31 @@ func Test_server_StreamSearch(t *testing.T) { } } -func Test_server_StreamSearchByID(t *testing.T) { - t.Parallel() +func Test_server_MultiSearch(t *testing.T) { type args struct { - stream vald.Search_StreamSearchByIDServer - } - type fields struct { - name string - ip string - ngt service.NGT - eg errgroup.Group - streamConcurrency int + ctx context.Context + reqs *payload.Search_MultiRequest } type want struct { - err error + wantRes *payload.Search_Responses + err error } type test struct { name string args args - fields fields + s *server want want - checkFunc func(want, error) error - beforeFunc func(args) - afterFunc func(args) + checkFunc func(want, *payload.Search_Responses, error) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } - defaultCheckFunc := func(w want, err error) error { + defaultCheckFunc := func(w want, gotRes *payload.Search_Responses, err error) error { if !errors.Is(err, w.err) { return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) } + if !reflect.DeepEqual(gotRes, w.wantRes) { + return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", gotRes, w.wantRes) + } return nil } tests := []test{ @@ -1359,17 +1349,17 @@ func Test_server_StreamSearchByID(t *testing.T) { { name: "test_case_1", args: args { - stream: nil, - }, - fields: fields { - name: "", - ip: "", - ngt: nil, - eg: nil, - streamConcurrency: 0, + ctx: nil, + reqs: nil, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -1379,17 +1369,17 @@ func Test_server_StreamSearchByID(t *testing.T) { return test { name: "test_case_2", args: args { - stream: nil, - }, - fields: fields { - name: "", - ip: "", - ngt: nil, - eg: nil, - streamConcurrency: 0, + ctx: nil, + reqs: nil, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -1399,44 +1389,30 @@ func Test_server_StreamSearchByID(t *testing.T) { test := tc t.Run(test.name, func(tt *testing.T) { tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + 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{ - name: test.fields.name, - ip: test.fields.ip, - ngt: test.fields.ngt, - eg: test.fields.eg, - streamConcurrency: test.fields.streamConcurrency, - } - err := s.StreamSearchByID(test.args.stream) - if err := checkFunc(test.want, err); err != nil { + gotRes, err := test.s.MultiSearch(test.args.ctx, test.args.reqs) + if err := checkFunc(test.want, gotRes, err); err != nil { tt.Errorf("error = %v", err) } }) } } -func Test_server_MultiSearch(t *testing.T) { - t.Parallel() +func Test_server_MultiSearchByID(t *testing.T) { type args struct { ctx context.Context - reqs *payload.Search_MultiRequest - } - type fields struct { - name string - ip string - ngt service.NGT - eg errgroup.Group - streamConcurrency int + reqs *payload.Search_MultiIDRequest } type want struct { wantRes *payload.Search_Responses @@ -1445,11 +1421,11 @@ func Test_server_MultiSearch(t *testing.T) { type test struct { name string args args - fields fields + s *server want want checkFunc func(want, *payload.Search_Responses, error) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotRes *payload.Search_Responses, err error) error { if !errors.Is(err, w.err) { @@ -1469,15 +1445,14 @@ func Test_server_MultiSearch(t *testing.T) { ctx: nil, reqs: nil, }, - fields: fields { - name: "", - ip: "", - ngt: nil, - eg: nil, - streamConcurrency: 0, - }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -1490,15 +1465,14 @@ func Test_server_MultiSearch(t *testing.T) { ctx: nil, reqs: nil, }, - fields: fields { - name: "", - ip: "", - ngt: nil, - eg: nil, - streamConcurrency: 0, - }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -1508,25 +1482,19 @@ func Test_server_MultiSearch(t *testing.T) { test := tc t.Run(test.name, func(tt *testing.T) { tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + 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{ - name: test.fields.name, - ip: test.fields.ip, - ngt: test.fields.ngt, - eg: test.fields.eg, - streamConcurrency: test.fields.streamConcurrency, - } - gotRes, err := s.MultiSearch(test.args.ctx, test.args.reqs) + gotRes, err := test.s.MultiSearchByID(test.args.ctx, test.args.reqs) if err := checkFunc(test.want, gotRes, err); err != nil { tt.Errorf("error = %v", err) } @@ -1534,33 +1502,24 @@ func Test_server_MultiSearch(t *testing.T) { } } -func Test_server_MultiSearchByID(t *testing.T) { - t.Parallel() +func Test_toSearchResponse(t *testing.T) { type args struct { - ctx context.Context - reqs *payload.Search_MultiIDRequest - } - type fields struct { - name string - ip string - ngt service.NGT - eg errgroup.Group - streamConcurrency int + dists []model.Distance + err error } type want struct { - wantRes *payload.Search_Responses + wantRes *payload.Search_Response err error } type test struct { name string args args - fields fields want want - checkFunc func(want, *payload.Search_Responses, error) error - beforeFunc func(args) - afterFunc func(args) + checkFunc func(want, *payload.Search_Response, error) error + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } - defaultCheckFunc := func(w want, gotRes *payload.Search_Responses, err error) error { + defaultCheckFunc := func(w want, gotRes *payload.Search_Response, err error) error { if !errors.Is(err, w.err) { return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) } @@ -1575,18 +1534,17 @@ func Test_server_MultiSearchByID(t *testing.T) { { name: "test_case_1", args: args { - ctx: nil, - reqs: nil, - }, - fields: fields { - name: "", - ip: "", - ngt: nil, - eg: nil, - streamConcurrency: 0, + dists: nil, + err: nil, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -1596,18 +1554,17 @@ func Test_server_MultiSearchByID(t *testing.T) { return test { name: "test_case_2", args: args { - ctx: nil, - reqs: nil, - }, - fields: fields { - name: "", - ip: "", - ngt: nil, - eg: nil, - streamConcurrency: 0, + dists: nil, + err: nil, }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -1617,25 +1574,19 @@ func Test_server_MultiSearchByID(t *testing.T) { test := tc t.Run(test.name, func(tt *testing.T) { tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + 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{ - name: test.fields.name, - ip: test.fields.ip, - ngt: test.fields.ngt, - eg: test.fields.eg, - streamConcurrency: test.fields.streamConcurrency, - } - gotRes, err := s.MultiSearchByID(test.args.ctx, test.args.reqs) + gotRes, err := toSearchResponse(test.args.dists, test.args.err) if err := checkFunc(test.want, gotRes, err); err != nil { tt.Errorf("error = %v", err) } diff --git a/pkg/agent/core/ngt/handler/grpc/update_test.go b/pkg/agent/core/ngt/handler/grpc/update_test.go index 4daa98041c..58470e11d9 100644 --- a/pkg/agent/core/ngt/handler/grpc/update_test.go +++ b/pkg/agent/core/ngt/handler/grpc/update_test.go @@ -30,7 +30,7 @@ import ( "github.com/vdaas/vald/internal/net/grpc/status" "github.com/vdaas/vald/internal/test/data/request" "github.com/vdaas/vald/internal/test/data/vector" - "github.com/vdaas/vald/pkg/agent/core/ngt/service" + "github.com/vdaas/vald/internal/test/goleak" ) func Test_server_Update(t *testing.T) { @@ -54,7 +54,7 @@ func Test_server_Update(t *testing.T) { fields fields want want checkFunc func(want, *payload.Object_Location, error) error - beforeFunc func(args) (Server, error) + beforeFunc func(*testing.T, args) (Server, error) afterFunc func(args) } defaultCheckFunc := func(w want, gotRes *payload.Object_Location, err error) error { @@ -95,7 +95,8 @@ func Test_server_Update(t *testing.T) { defaultInsertConfig := &payload.Insert_Config{ SkipStrictExistCheck: true, } - beforeFunc := func(ctx context.Context, objectType string) func(args) (Server, error) { + beforeFunc := func(t *testing.T, ctx context.Context, objectType string) func(*testing.T, args) (Server, error) { + t.Helper() if objectType == "" { objectType = ngt.Float.String() } @@ -115,7 +116,8 @@ func Test_server_Update(t *testing.T) { }, } - return func(a args) (Server, error) { + return func(t *testing.T, a args) (Server, error) { + t.Helper() var overwriteVec [][]float32 if a.indexVector != nil { overwriteVec = [][]float32{ @@ -844,9 +846,9 @@ func Test_server_Update(t *testing.T) { defer cancel() if test.beforeFunc == nil { - test.beforeFunc = beforeFunc(ctx, tc.fields.objectType) + test.beforeFunc = beforeFunc(tt, ctx, tc.fields.objectType) } - s, err := test.beforeFunc(test.args) + s, err := test.beforeFunc(tt, test.args) if err != nil { tt.Errorf("error = %v", err) } @@ -867,28 +869,20 @@ func Test_server_Update(t *testing.T) { } func Test_server_StreamUpdate(t *testing.T) { - t.Parallel() type args struct { stream vald.Update_StreamUpdateServer } - type fields struct { - name string - ip string - ngt service.NGT - eg errgroup.Group - streamConcurrency int - } type want struct { err error } type test struct { name string args args - fields fields + s *server 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) { @@ -904,15 +898,14 @@ func Test_server_StreamUpdate(t *testing.T) { args: args { stream: nil, }, - fields: fields { - name: "", - ip: "", - ngt: nil, - eg: nil, - streamConcurrency: 0, - }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -924,15 +917,14 @@ func Test_server_StreamUpdate(t *testing.T) { args: args { stream: nil, }, - fields: fields { - name: "", - ip: "", - ngt: nil, - eg: nil, - streamConcurrency: 0, - }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -942,25 +934,19 @@ func Test_server_StreamUpdate(t *testing.T) { test := tc t.Run(test.name, func(tt *testing.T) { tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + 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{ - name: test.fields.name, - ip: test.fields.ip, - ngt: test.fields.ngt, - eg: test.fields.eg, - streamConcurrency: test.fields.streamConcurrency, - } - err := s.StreamUpdate(test.args.stream) + err := test.s.StreamUpdate(test.args.stream) if err := checkFunc(test.want, err); err != nil { tt.Errorf("error = %v", err) } @@ -969,18 +955,10 @@ func Test_server_StreamUpdate(t *testing.T) { } func Test_server_MultiUpdate(t *testing.T) { - t.Parallel() type args struct { ctx context.Context reqs *payload.Update_MultiRequest } - type fields struct { - name string - ip string - ngt service.NGT - eg errgroup.Group - streamConcurrency int - } type want struct { wantRes *payload.Object_Locations err error @@ -988,11 +966,11 @@ func Test_server_MultiUpdate(t *testing.T) { type test struct { name string args args - fields fields + s *server want want checkFunc func(want, *payload.Object_Locations, error) error - beforeFunc func(args) - afterFunc func(args) + beforeFunc func(*testing.T, args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, gotRes *payload.Object_Locations, err error) error { if !errors.Is(err, w.err) { @@ -1012,15 +990,14 @@ func Test_server_MultiUpdate(t *testing.T) { ctx: nil, reqs: nil, }, - fields: fields { - name: "", - ip: "", - ngt: nil, - eg: nil, - streamConcurrency: 0, - }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, }, */ @@ -1033,15 +1010,14 @@ func Test_server_MultiUpdate(t *testing.T) { ctx: nil, reqs: nil, }, - fields: fields { - name: "", - ip: "", - ngt: nil, - eg: nil, - streamConcurrency: 0, - }, want: want{}, checkFunc: defaultCheckFunc, + beforeFunc: func(t *testing.T, args args) { + t.Helper() + }, + afterFunc: func(t *testing.T, args args) { + t.Helper() + }, } }(), */ @@ -1051,25 +1027,19 @@ func Test_server_MultiUpdate(t *testing.T) { test := tc t.Run(test.name, func(tt *testing.T) { tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc != nil { - test.beforeFunc(test.args) + 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{ - name: test.fields.name, - ip: test.fields.ip, - ngt: test.fields.ngt, - eg: test.fields.eg, - streamConcurrency: test.fields.streamConcurrency, - } - gotRes, err := s.MultiUpdate(test.args.ctx, test.args.reqs) + gotRes, err := test.s.MultiUpdate(test.args.ctx, test.args.reqs) if err := checkFunc(test.want, gotRes, err); err != nil { tt.Errorf("error = %v", err) } diff --git a/pkg/agent/core/ngt/handler/grpc/upsert_test.go b/pkg/agent/core/ngt/handler/grpc/upsert_test.go index d37c7d8079..a67e948e0a 100644 --- a/pkg/agent/core/ngt/handler/grpc/upsert_test.go +++ b/pkg/agent/core/ngt/handler/grpc/upsert_test.go @@ -55,7 +55,7 @@ func Test_server_Upsert(t *testing.T) { args args want want checkFunc func(want, *payload.Object_Location, error) error - beforeFunc func(context.Context, optIdx) (Server, error) + beforeFunc func(*testing.T, context.Context, optIdx) (Server, error) afterFunc func() } defaultCheckFunc := func(w want, gotRes *payload.Object_Location, err error) error { @@ -96,7 +96,7 @@ func Test_server_Upsert(t *testing.T) { defaultInsertConfig := &payload.Insert_Config{ SkipStrictExistCheck: true, } - defaultBeforeFunc := func(objectType string, insertNum int) func(context.Context, optIdx) (Server, error) { + defaultBeforeFunc := func(objectType string, insertNum int) func(*testing.T, context.Context, optIdx) (Server, error) { cfg := &config.NGT{ Dimension: dimension, DistanceType: ngt.L2.String(), @@ -112,7 +112,8 @@ func Test_server_Upsert(t *testing.T) { }, } - return func(ctx context.Context, opt optIdx) (Server, error) { + return func(t *testing.T, ctx context.Context, opt optIdx) (Server, error) { + t.Helper() var overwriteID []string if opt.id != "" { overwriteID = []string{ @@ -1572,7 +1573,7 @@ func Test_server_Upsert(t *testing.T) { if test.beforeFunc == nil { test.beforeFunc = defaultBeforeFunc(ngt.Float.String(), defaultInsertNum) } - s, err := test.beforeFunc(ctx, test.args.optIdx) + s, err := test.beforeFunc(tt, ctx, test.args.optIdx) if err != nil { tt.Errorf("error = %v", err) } diff --git a/pkg/agent/core/ngt/service/kvs/kvs_test.go b/pkg/agent/core/ngt/service/kvs/kvs_test.go index d4c7b7a452..2df9b63a66 100644 --- a/pkg/agent/core/ngt/service/kvs/kvs_test.go +++ b/pkg/agent/core/ngt/service/kvs/kvs_test.go @@ -118,7 +118,7 @@ func Test_bidi_Get(t *testing.T) { fields fields want want checkFunc func(want, uint32, bool, *bidi) error - beforeFunc func(args, BidiMap) + beforeFunc func(*testing.T, args, BidiMap) afterFunc func(args, BidiMap) } defaultCheckFunc := func(w want, got uint32, got1 bool, bm *bidi) error { @@ -154,7 +154,8 @@ func Test_bidi_Get(t *testing.T) { key: key, }, fields: fields, - beforeFunc: func(a args, bm BidiMap) { + beforeFunc: func(t *testing.T, a args, bm BidiMap) { + t.Helper() bm.Set(a.key, val) }, want: want{ @@ -184,7 +185,7 @@ func Test_bidi_Get(t *testing.T) { key: key, }, fields: fields, - beforeFunc: func(a args, bm BidiMap) { + beforeFunc: func(t *testing.T, a args, bm BidiMap) { t.Helper() bm.Set(a.key, val) }, @@ -215,7 +216,8 @@ func Test_bidi_Get(t *testing.T) { key: key, }, fields: fields, - beforeFunc: func(a args, bm BidiMap) { + beforeFunc: func(t *testing.T, a args, bm BidiMap) { + t.Helper() bm.Set(a.key, val) }, want: want{ @@ -245,7 +247,8 @@ func Test_bidi_Get(t *testing.T) { key: "84a333-59633fd4-4553-414a", }, fields: fields, - beforeFunc: func(a args, bm BidiMap) { + beforeFunc: func(t *testing.T, a args, bm BidiMap) { + t.Helper() bm.Set(key, val) }, want: want{ @@ -273,7 +276,8 @@ func Test_bidi_Get(t *testing.T) { name: "return (0, false) when there is no value for the key and the key is empty string", args: args{}, fields: fields, - beforeFunc: func(a args, bm BidiMap) { + beforeFunc: func(t *testing.T, a args, bm BidiMap) { + t.Helper() bm.Set(key, val) }, want: want{ @@ -301,7 +305,8 @@ func Test_bidi_Get(t *testing.T) { name: "return (0, true) when the default value is set for the key and the key is empty string", args: args{}, fields: fields, - beforeFunc: func(a args, bm BidiMap) { + beforeFunc: func(t *testing.T, a args, bm BidiMap) { + t.Helper() bm.Set(key, val) }, want: want{ @@ -324,7 +329,7 @@ func Test_bidi_Get(t *testing.T) { l: test.fields.l, } if test.beforeFunc != nil { - test.beforeFunc(test.args, b) + test.beforeFunc(tt, test.args, b) } if test.afterFunc != nil { defer test.afterFunc(test.args, b) @@ -363,7 +368,7 @@ func Test_bidi_GetInverse(t *testing.T) { fields fields want want checkFunc func(want, string, bool, *bidi) error - beforeFunc func(args, BidiMap) + beforeFunc func(*testing.T, args, BidiMap) afterFunc func(args, BidiMap) } defaultCheckFunc := func(w want, got string, got1 bool, bm *bidi) error { @@ -399,7 +404,8 @@ func Test_bidi_GetInverse(t *testing.T) { val: val, }, fields: fields, - beforeFunc: func(_ args, bm BidiMap) { + beforeFunc: func(t *testing.T, _ args, bm BidiMap) { + t.Helper() bm.Set(key, val) }, want: want{ @@ -429,7 +435,8 @@ func Test_bidi_GetInverse(t *testing.T) { val: val, }, fields: fields, - beforeFunc: func(_ args, bm BidiMap) { + beforeFunc: func(t *testing.T, _ args, bm BidiMap) { + t.Helper() bm.Set(key, val) }, want: want{ @@ -459,7 +466,8 @@ func Test_bidi_GetInverse(t *testing.T) { val: val, }, fields: fields, - beforeFunc: func(_ args, bm BidiMap) { + beforeFunc: func(t *testing.T, _ args, bm BidiMap) { + t.Helper() bm.Set(key, val) }, want: want{ @@ -489,7 +497,8 @@ func Test_bidi_GetInverse(t *testing.T) { val: 10000, }, fields: fields, - beforeFunc: func(_ args, bm BidiMap) { + beforeFunc: func(t *testing.T, _ args, bm BidiMap) { + t.Helper() bm.Set(key, val) }, want: want{ @@ -517,7 +526,8 @@ func Test_bidi_GetInverse(t *testing.T) { name: "return false when there is a no key for the value and the val is 0", args: args{}, fields: fields, - beforeFunc: func(_ args, bm BidiMap) { + beforeFunc: func(t *testing.T, _ args, bm BidiMap) { + t.Helper() bm.Set(key, val) }, want: want{ @@ -545,7 +555,8 @@ func Test_bidi_GetInverse(t *testing.T) { name: "return (0, true) when the default value is set for the key and the val is 0", args: args{}, fields: fields, - beforeFunc: func(_ args, bm BidiMap) { + beforeFunc: func(t *testing.T, _ args, bm BidiMap) { + t.Helper() bm.Set(key, val) }, want: want{ @@ -569,7 +580,7 @@ func Test_bidi_GetInverse(t *testing.T) { l: test.fields.l, } if test.beforeFunc != nil { - test.beforeFunc(test.args, b) + test.beforeFunc(tt, test.args, b) } if test.afterFunc != nil { defer test.afterFunc(test.args, b) @@ -609,7 +620,7 @@ func Test_bidi_Set(t *testing.T) { fields fields want want checkFunc func(w want, args args, b *bidi) error - beforeFunc func(args, *bidi) + beforeFunc func(*testing.T, args, *bidi) afterFunc func(args) } defaultCheckFunc := func(w want, args args, b *bidi) error { @@ -740,7 +751,8 @@ func Test_bidi_Set(t *testing.T) { val: val, }, fields: fields, - beforeFunc: func(a args, b *bidi) { + beforeFunc: func(t *testing.T, a args, b *bidi) { + t.Helper() b.Set(a.key, oldVal) }, want: want{ @@ -830,7 +842,7 @@ func Test_bidi_Set(t *testing.T) { l: test.fields.l, } if test.beforeFunc != nil { - test.beforeFunc(test.args, b) + test.beforeFunc(tt, test.args, b) } if test.afterFunc != nil { defer test.afterFunc(test.args) @@ -869,7 +881,7 @@ func Test_bidi_Delete(t *testing.T) { fields fields want want checkFunc func(want, args, *bidi, uint32, bool) error - beforeFunc func(args, BidiMap) + beforeFunc func(*testing.T, args, BidiMap) afterFunc func(args) } defaultCheckFunc := func(w want, _ args, _ *bidi, gotVal uint32, gotOk bool) error { @@ -902,7 +914,8 @@ func Test_bidi_Delete(t *testing.T) { key: key, }, fields: fields, - beforeFunc: func(a args, bm BidiMap) { + beforeFunc: func(t *testing.T, a args, bm BidiMap) { + t.Helper() bm.Set(a.key, val) }, checkFunc: func(w want, a args, b *bidi, gotVal uint32, gotOk bool) error { @@ -947,7 +960,8 @@ func Test_bidi_Delete(t *testing.T) { key: key, }, fields: fields, - beforeFunc: func(a args, bm BidiMap) { + beforeFunc: func(t *testing.T, a args, bm BidiMap) { + t.Helper() bm.Set(a.key, val) }, checkFunc: func(w want, a args, b *bidi, gotVal uint32, gotOk bool) error { @@ -992,7 +1006,8 @@ func Test_bidi_Delete(t *testing.T) { key: key, }, fields: fields, - beforeFunc: func(a args, bm BidiMap) { + beforeFunc: func(t *testing.T, a args, bm BidiMap) { + t.Helper() bm.Set(a.key, val) }, checkFunc: func(w want, a args, b *bidi, gotVal uint32, gotOk bool) error { @@ -1032,7 +1047,8 @@ func Test_bidi_Delete(t *testing.T) { name: "return val and true when the delete successes and the key is empty string", args: args{}, fields: fields, - beforeFunc: func(a args, bm BidiMap) { + beforeFunc: func(t *testing.T, a args, bm BidiMap) { + t.Helper() bm.Set(a.key, val) }, checkFunc: func(w want, a args, b *bidi, gotVal uint32, gotOk bool) error { @@ -1077,7 +1093,8 @@ func Test_bidi_Delete(t *testing.T) { key: "95314ec4-d95f-14ea-19d0", }, fields: fields, - beforeFunc: func(a args, bm BidiMap) { + beforeFunc: func(t *testing.T, a args, bm BidiMap) { + t.Helper() bm.Set(key, val) }, want: want{ @@ -1099,7 +1116,7 @@ func Test_bidi_Delete(t *testing.T) { l: test.fields.l, } if test.beforeFunc != nil { - test.beforeFunc(test.args, b) + test.beforeFunc(tt, test.args, b) } if test.afterFunc != nil { defer test.afterFunc(test.args) @@ -1138,7 +1155,7 @@ func Test_bidi_DeleteInverse(t *testing.T) { fields fields want want checkFunc func(want, args, *bidi, string, bool) error - beforeFunc func(args, BidiMap) + beforeFunc func(*testing.T, args, BidiMap) afterFunc func(args) } defaultCheckFunc := func(w want, _ args, _ *bidi, gotKey string, gotOk bool) error { @@ -1170,7 +1187,8 @@ func Test_bidi_DeleteInverse(t *testing.T) { args: args{ val: val, }, - beforeFunc: func(a args, bm BidiMap) { + beforeFunc: func(t *testing.T, a args, bm BidiMap) { + t.Helper() bm.Set(key, val) }, checkFunc: func(w want, a args, b *bidi, gotKey string, gotOk bool) error { @@ -1215,7 +1233,8 @@ func Test_bidi_DeleteInverse(t *testing.T) { args: args{ val: val, }, - beforeFunc: func(a args, bm BidiMap) { + beforeFunc: func(t *testing.T, a args, bm BidiMap) { + t.Helper() bm.Set(key, val) }, checkFunc: func(w want, a args, b *bidi, gotKey string, gotOk bool) error { @@ -1260,7 +1279,8 @@ func Test_bidi_DeleteInverse(t *testing.T) { args: args{ val: val, }, - beforeFunc: func(a args, bm BidiMap) { + beforeFunc: func(t *testing.T, a args, bm BidiMap) { + t.Helper() bm.Set(key, val) }, checkFunc: func(w want, a args, b *bidi, gotKey string, gotOk bool) error { @@ -1300,7 +1320,8 @@ func Test_bidi_DeleteInverse(t *testing.T) { return test{ name: "return key and true when the delete successes and the val is 0", args: args{}, - beforeFunc: func(a args, bm BidiMap) { + beforeFunc: func(t *testing.T, a args, bm BidiMap) { + t.Helper() bm.Set(key, a.val) }, checkFunc: func(w want, a args, b *bidi, gotKey string, gotOk bool) error { @@ -1345,7 +1366,8 @@ func Test_bidi_DeleteInverse(t *testing.T) { args: args{ val: 10000, }, - beforeFunc: func(a args, bm BidiMap) { + beforeFunc: func(t *testing.T, a args, bm BidiMap) { + t.Helper() bm.Set(key, val) }, fields: fields, @@ -1369,7 +1391,7 @@ func Test_bidi_DeleteInverse(t *testing.T) { l: test.fields.l, } if test.beforeFunc != nil { - test.beforeFunc(test.args, b) + test.beforeFunc(tt, test.args, b) } if test.afterFunc != nil { defer test.afterFunc(test.args) @@ -1407,7 +1429,7 @@ func Test_bidi_Range(t *testing.T) { fields fields want want checkFunc func(want, *bidi) error - beforeFunc func(args, BidiMap) + beforeFunc func(*testing.T, args, BidiMap) afterFunc func(args) } defaultCheckFunc := func(w want, bm *bidi) error { @@ -1444,7 +1466,8 @@ func Test_bidi_Range(t *testing.T) { return true }, }, - beforeFunc: func(a args, bm BidiMap) { + beforeFunc: func(t *testing.T, a args, bm BidiMap) { + t.Helper() for key, id := range wantMap { bm.Set(key, id) } @@ -1495,7 +1518,8 @@ func Test_bidi_Range(t *testing.T) { return true }, }, - beforeFunc: func(a args, bm BidiMap) { + beforeFunc: func(t *testing.T, a args, bm BidiMap) { + t.Helper() for key, id := range wantMap { bm.Set(key, id) } @@ -1546,7 +1570,8 @@ func Test_bidi_Range(t *testing.T) { return true }, }, - beforeFunc: func(a args, bm BidiMap) { + beforeFunc: func(t *testing.T, a args, bm BidiMap) { + t.Helper() for key, id := range wantMap { bm.Set(key, id) } @@ -1584,7 +1609,7 @@ func Test_bidi_Range(t *testing.T) { eg: eg, } if test.beforeFunc != nil { - test.beforeFunc(test.args, b) + test.beforeFunc(tt, test.args, b) } if test.afterFunc != nil { defer test.afterFunc(test.args) diff --git a/pkg/agent/core/ngt/service/option_test.go b/pkg/agent/core/ngt/service/option_test.go index 4268f5b1e9..c6c41ad63e 100644 --- a/pkg/agent/core/ngt/service/option_test.go +++ b/pkg/agent/core/ngt/service/option_test.go @@ -42,7 +42,7 @@ func TestWithErrGroup(t *testing.T) { want want checkFunc func(want, *T, error) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, obj *T, err error) error { if !errors.Is(err, w.err) { @@ -68,7 +68,8 @@ func TestWithErrGroup(t *testing.T) { eg: eg, }, }, - afterFunc: func(a args) { + afterFunc: func(t *testing.T, _ args) { + t.Helper() cancel() }, } @@ -92,7 +93,7 @@ func TestWithErrGroup(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := defaultCheckFunc if test.checkFunc != nil { @@ -123,7 +124,7 @@ func TestWithEnableInMemoryMode(t *testing.T) { want want checkFunc func(want, *T, error) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, obj *T, err error) error { if !errors.Is(err, w.err) { @@ -167,7 +168,7 @@ func TestWithEnableInMemoryMode(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := defaultCheckFunc if test.checkFunc != nil { @@ -198,7 +199,7 @@ func TestWithIndexPath(t *testing.T) { want want checkFunc func(want, *T, error) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, obj *T, err error) error { if !errors.Is(err, w.err) { @@ -243,7 +244,7 @@ func TestWithIndexPath(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := defaultCheckFunc if test.checkFunc != nil { @@ -274,7 +275,7 @@ func TestWithAutoIndexCheckDuration(t *testing.T) { want want checkFunc func(want, *T, error) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, obj *T, err error) error { if !errors.Is(err, w.err) { @@ -328,7 +329,7 @@ func TestWithAutoIndexCheckDuration(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := defaultCheckFunc if test.checkFunc != nil { @@ -359,7 +360,7 @@ func TestWithAutoIndexDurationLimit(t *testing.T) { want want checkFunc func(want, *T, error) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, obj *T, err error) error { if !errors.Is(err, w.err) { @@ -413,7 +414,7 @@ func TestWithAutoIndexDurationLimit(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := defaultCheckFunc if test.checkFunc != nil { @@ -444,7 +445,7 @@ func TestWithAutoSaveIndexDuration(t *testing.T) { want want checkFunc func(want, *T, error) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, obj *T, err error) error { if !errors.Is(err, w.err) { @@ -498,7 +499,7 @@ func TestWithAutoSaveIndexDuration(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := defaultCheckFunc if test.checkFunc != nil { @@ -529,7 +530,7 @@ func TestWithAutoIndexLength(t *testing.T) { want want checkFunc func(want, *T, error) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, obj *T, err error) error { if !errors.Is(err, w.err) { @@ -573,7 +574,7 @@ func TestWithAutoIndexLength(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := defaultCheckFunc if test.checkFunc != nil { @@ -604,7 +605,7 @@ func TestWithInitialDelayMaxDuration(t *testing.T) { want want checkFunc func(want, *T, error) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, obj *T, err error) error { if !errors.Is(err, w.err) { @@ -659,7 +660,7 @@ func TestWithInitialDelayMaxDuration(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := defaultCheckFunc if test.checkFunc != nil { @@ -690,7 +691,7 @@ func TestWithMinLoadIndexTimeout(t *testing.T) { want want checkFunc func(want, *T, error) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, obj *T, err error) error { if !errors.Is(err, w.err) { @@ -744,7 +745,7 @@ func TestWithMinLoadIndexTimeout(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := defaultCheckFunc if test.checkFunc != nil { @@ -775,7 +776,7 @@ func TestWithMaxLoadIndexTimeout(t *testing.T) { want want checkFunc func(want, *T, error) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, obj *T, err error) error { if !errors.Is(err, w.err) { @@ -829,7 +830,7 @@ func TestWithMaxLoadIndexTimeout(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := defaultCheckFunc if test.checkFunc != nil { @@ -860,7 +861,7 @@ func TestWithLoadIndexTimeoutFactor(t *testing.T) { want want checkFunc func(want, *T, error) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, obj *T, err error) error { if !errors.Is(err, w.err) { @@ -914,7 +915,7 @@ func TestWithLoadIndexTimeoutFactor(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := defaultCheckFunc if test.checkFunc != nil { @@ -945,7 +946,7 @@ func TestWithDefaultPoolSize(t *testing.T) { want want checkFunc func(want, *T, error) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, obj *T, err error) error { if !errors.Is(err, w.err) { @@ -989,7 +990,7 @@ func TestWithDefaultPoolSize(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := defaultCheckFunc if test.checkFunc != nil { @@ -1020,7 +1021,7 @@ func TestWithDefaultRadius(t *testing.T) { want want checkFunc func(want, *T, error) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, obj *T, err error) error { if !errors.Is(err, w.err) { @@ -1064,7 +1065,7 @@ func TestWithDefaultRadius(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := defaultCheckFunc if test.checkFunc != nil { @@ -1095,7 +1096,7 @@ func TestWithDefaultEpsilon(t *testing.T) { want want checkFunc func(want, *T, error) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, obj *T, err error) error { if !errors.Is(err, w.err) { @@ -1139,7 +1140,7 @@ func TestWithDefaultEpsilon(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := defaultCheckFunc if test.checkFunc != nil { @@ -1170,7 +1171,7 @@ func TestWithProactiveGC(t *testing.T) { want want checkFunc func(want, *T, error) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, obj *T, err error) error { if !errors.Is(err, w.err) { @@ -1214,7 +1215,7 @@ func TestWithProactiveGC(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := defaultCheckFunc if test.checkFunc != nil { @@ -1245,7 +1246,7 @@ func TestWithCopyOnWrite(t *testing.T) { want want checkFunc func(want, *T, error) error beforeFunc func(args) - afterFunc func(args) + afterFunc func(*testing.T, args) } defaultCheckFunc := func(w want, obj *T, err error) error { if !errors.Is(err, w.err) { @@ -1289,7 +1290,7 @@ func TestWithCopyOnWrite(t *testing.T) { test.beforeFunc(test.args) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc(tt, test.args) } checkFunc := defaultCheckFunc if test.checkFunc != nil {