Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Add t.Helper() on test helper function #1935

Merged
merged 11 commits into from
Feb 1, 2023
21 changes: 12 additions & 9 deletions internal/cache/gache/gache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
},
},
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
},
},
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
},
},
Expand All @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand All @@ -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()
Expand Down
7 changes: 4 additions & 3 deletions internal/config/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand All @@ -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()
Expand Down
7 changes: 4 additions & 3 deletions internal/config/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand All @@ -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()
Expand Down
7 changes: 4 additions & 3 deletions internal/config/ngt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 4 additions & 3 deletions internal/config/tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand All @@ -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()
Expand Down
7 changes: 4 additions & 3 deletions internal/db/nosql/cassandra/option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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{
Expand All @@ -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)
Expand Down
Loading