diff --git a/.golangci.yml b/.golangci.yml index d066023864..6b7e892d72 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -11,6 +11,7 @@ linters: - asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers [fast: true, auto-fix: false] - bidichk # Checks for dangerous unicode character sequences [fast: true, auto-fix: false] - bodyclose # checks whether HTTP response body is closed successfully [fast: false, auto-fix: false] + - canonicalheader # canonicalheader checks whether net/http.Header uses canonical header [fast: false, auto-fix: false] - copyloopvar # copyloopvar is a linter detects places where loop variables are copied [fast: true, auto-fix: false] - decorder # check declaration order and count of types, constants, variables and functions [fast: true, auto-fix: false] - dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f()) [fast: true, auto-fix: false] @@ -50,6 +51,7 @@ linters: - predeclared # find code that shadows one of Go's predeclared identifiers [fast: true, auto-fix: false] - promlinter # Check Prometheus metrics naming via promlint [fast: true, auto-fix: false] - protogetter # Reports direct reads from proto message fields when getters should be used [fast: false, auto-fix: true] + - reassign # Checks that package variables are not reassigned [fast: false, auto-fix: false] - revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint. [fast: false, auto-fix: false] - rowserrcheck # checks whether Err of rows is checked successfully [fast: false, auto-fix: false] - sloglint # ensure consistent code style when using log/slog [fast: false, auto-fix: false] @@ -58,6 +60,7 @@ linters: - tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17 [fast: false, auto-fix: false] - testifylint # Checks usage of github.com/stretchr/testify. [fast: false, auto-fix: false] - testpackage # linter that makes you use a separate _test package [fast: true, auto-fix: false] + - thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers [fast: false, auto-fix: false] - tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes [fast: false, auto-fix: false] - typecheck # Like the front-end of a Go compiler, parses and type-checks Go code [fast: false, auto-fix: false] - unconvert # Remove unnecessary type conversions [fast: false, auto-fix: false] diff --git a/internal/args/args_test.go b/internal/args/args_test.go index aa695e798a..6dbc3b8ac8 100644 --- a/internal/args/args_test.go +++ b/internal/args/args_test.go @@ -170,6 +170,7 @@ func TestGetArgType(t *testing.T) { run := func(tc *TestCase) func(*testing.T) { return func(t *testing.T) { + t.Helper() res, err := args.GetArgType(tc.ArgType, tc.Name) if tc.expectedError == "" { require.NoError(t, err) diff --git a/internal/args/marshal_test.go b/internal/args/marshal_test.go index 51dd606551..40827a5063 100644 --- a/internal/args/marshal_test.go +++ b/internal/args/marshal_test.go @@ -22,6 +22,7 @@ func TestMarshal(t *testing.T) { run := func(testCase TestCase) func(t *testing.T) { return func(t *testing.T) { + t.Helper() args, err := args.MarshalStruct(testCase.data) if testCase.error == "" { @@ -235,6 +236,7 @@ func TestMarshalValue(t *testing.T) { run := func(testCase TestCase) func(t *testing.T) { return func(t *testing.T) { + t.Helper() value, err := args.MarshalValue(testCase.data) if testCase.error == "" { diff --git a/internal/args/unmarshal_test.go b/internal/args/unmarshal_test.go index 896099cb93..46c0aab47d 100644 --- a/internal/args/unmarshal_test.go +++ b/internal/args/unmarshal_test.go @@ -29,6 +29,7 @@ func TestUnmarshalStruct(t *testing.T) { run := func(testCase TestCase) func(t *testing.T) { return func(t *testing.T) { + t.Helper() if testCase.data == nil { testCase.data = reflect.New(reflect.TypeOf(testCase.expected).Elem()).Interface() } @@ -540,6 +541,7 @@ func TestIsUmarshalableValue(t *testing.T) { run := func(testCase TestCase) func(t *testing.T) { return func(t *testing.T) { + t.Helper() value := args.IsUmarshalableValue(testCase.data) assert.Equal(t, testCase.expected, value) } diff --git a/internal/core/autocomplete_test.go b/internal/core/autocomplete_test.go index 74038ebc6f..bbee9b74b6 100644 --- a/internal/core/autocomplete_test.go +++ b/internal/core/autocomplete_test.go @@ -86,6 +86,7 @@ type autoCompleteTestCase struct { func runAutocompleteTest(ctx context.Context, tc *autoCompleteTestCase) func(*testing.T) { return func(t *testing.T) { + t.Helper() words := tc.Words if len(words) == 0 { name := strings.Replace(t.Name(), "TestAutocomplete/", "", -1) diff --git a/internal/core/bootstrap_test.go b/internal/core/bootstrap_test.go index fcd6b09bd8..c77f77ed65 100644 --- a/internal/core/bootstrap_test.go +++ b/internal/core/bootstrap_test.go @@ -149,6 +149,7 @@ func TestInterruptError(t *testing.T) { ), Cmd: "scw -o json test empty success", Check: func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.Equal(t, "[]\n", string(ctx.Stdout)) }, })) diff --git a/internal/core/build_info_test.go b/internal/core/build_info_test.go index a2ff7024d7..28bb310a99 100644 --- a/internal/core/build_info_test.go +++ b/internal/core/build_info_test.go @@ -34,6 +34,7 @@ func Test_CheckVersion(t *testing.T) { Cmd: "scw plop", Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.Equal(t, "A new version of scw is available (2.5.4), beware that you are currently running 1.20.0\n", ctx.LogBuffer) }, ), @@ -48,6 +49,7 @@ func Test_CheckVersion(t *testing.T) { Cmd: "scw plop -D", Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.Contains(t, ctx.LogBuffer, "version is up to date (99.99.0)\n") }, ), @@ -65,6 +67,7 @@ func Test_CheckVersion(t *testing.T) { Cmd: "scw plop -D", Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.Contains(t, ctx.LogBuffer, "version was already checked during past 24 hours\n") }, ), @@ -86,6 +89,7 @@ func Test_CheckVersion(t *testing.T) { Cmd: "scw plop", Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.Contains(t, ctx.LogBuffer, "A new version of scw is available (2.5.4), beware that you are currently running 1.0.0\n") }, ), diff --git a/internal/core/checks_test.go b/internal/core/checks_test.go index fc3e10a409..c87b809a02 100644 --- a/internal/core/checks_test.go +++ b/internal/core/checks_test.go @@ -75,6 +75,7 @@ func TestCheckAPIKey(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckExitCode(0), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.True(t, strings.HasPrefix(ctx.LogBuffer, "Current api key expires in")) }, ), diff --git a/internal/core/cobra_utils_test.go b/internal/core/cobra_utils_test.go index 806b2cd708..21cd3b1e71 100644 --- a/internal/core/cobra_utils_test.go +++ b/internal/core/cobra_utils_test.go @@ -280,6 +280,7 @@ func Test_MultiPositionalArg(t *testing.T) { core.TestCheckExitCode(0), core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() res := ctx.Result.(*testAcceptMultiPositionalArgsType) assert.Len(t, res.NameIDs, 1) assert.Equal(t, "pos1", res.NameIDs[0]) @@ -295,6 +296,7 @@ func Test_MultiPositionalArg(t *testing.T) { core.TestCheckExitCode(0), core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() res := ctx.Result.(*testAcceptMultiPositionalArgsType) assert.Len(t, res.NameIDs, 3) assert.Equal(t, "pos1", res.NameIDs[0]) diff --git a/internal/core/command_interceptor_test.go b/internal/core/command_interceptor_test.go index 0fb1aad089..c39e8c50af 100644 --- a/internal/core/command_interceptor_test.go +++ b/internal/core/command_interceptor_test.go @@ -27,6 +27,7 @@ func Test_CombineCommandInterceptor(t *testing.T) { run := func(tc *TestCase) func(t *testing.T) { return func(t *testing.T) { + t.Helper() interceptor := core.CombineCommandInterceptor(tc.Interceptors...) res, _ := interceptor(nil, nil, runner) assert.Equal(t, tc.Expected, res) diff --git a/internal/core/default_test.go b/internal/core/default_test.go index 76886f9bcd..e96b8b5184 100644 --- a/internal/core/default_test.go +++ b/internal/core/default_test.go @@ -18,6 +18,7 @@ func Test_ApplyDefaultValues(t *testing.T) { run := func(tc *testCase) func(t *testing.T) { return func(t *testing.T) { + t.Helper() result := core.ApplyDefaultValues(context.Background(), tc.argSpecs, tc.rawArgs) assert.Equal(t, tc.expected, result) } diff --git a/internal/core/reflect_test.go b/internal/core/reflect_test.go index 6955125b4d..753a844794 100644 --- a/internal/core/reflect_test.go +++ b/internal/core/reflect_test.go @@ -87,6 +87,7 @@ func Test_getValuesForFieldByName(t *testing.T) { expectedValues: []reflect.Value{reflect.ValueOf("value1")}, }, testFunc: func(t *testing.T, tc TestCase) { + t.Helper() values, err := core.GetValuesForFieldByName(reflect.ValueOf(tc.cmdArgs), strings.Split(tc.fieldName, ".")) if err != nil { assert.Equal(t, tc.expectedError, err.Error()) @@ -117,6 +118,7 @@ func Test_getValuesForFieldByName(t *testing.T) { expectedValues: []reflect.Value{reflect.ValueOf("value1")}, }, testFunc: func(t *testing.T, tc TestCase) { + t.Helper() values, err := core.GetValuesForFieldByName(reflect.ValueOf(tc.cmdArgs), strings.Split(tc.fieldName, ".")) if err != nil { assert.Equal(t, tc.expectedError, err.Error()) @@ -160,6 +162,7 @@ func Test_getValuesForFieldByName(t *testing.T) { expectedValues: []reflect.Value{reflect.ValueOf(expectedServiceIP)}, }, testFunc: func(t *testing.T, tc TestCase) { + t.Helper() values, err := core.GetValuesForFieldByName(reflect.ValueOf(tc.cmdArgs), strings.Split(tc.fieldName, ".")) if err != nil { assert.Equal(t, nil, err.Error()) diff --git a/internal/core/testing.go b/internal/core/testing.go index b1ce9878e6..e95199b743 100644 --- a/internal/core/testing.go +++ b/internal/core/testing.go @@ -200,6 +200,7 @@ type TestConfig struct { // getTestFilePath returns a valid filename path based on the go test name and suffix. (Take care of non fs friendly char) func getTestFilePath(t *testing.T, suffix string) string { + t.Helper() specialChars := regexp.MustCompile(`[\\?%*:|"<>. ]`) // Replace nested tests separators. @@ -214,6 +215,7 @@ func getTestFilePath(t *testing.T, suffix string) string { } func createTestClient(t *testing.T, testConfig *TestConfig, httpClient *http.Client) (client *scw.Client) { + t.Helper() var err error // Init default options @@ -277,6 +279,7 @@ var DefaultRetryInterval *time.Duration // Run a CLI integration test. See TestConfig for configuration option func Test(config *TestConfig) func(t *testing.T) { return func(t *testing.T) { + t.Helper() if !config.DisableParallel { t.Parallel() } @@ -588,6 +591,7 @@ func ExecAfterCmd(cmd string) AfterFunc { // TestCheckCombine combines multiple check functions into one. func TestCheckCombine(checks ...TestCheck) TestCheck { return func(t *testing.T, ctx *CheckFuncCtx) { + t.Helper() for _, check := range checks { check(t, ctx) } @@ -597,6 +601,7 @@ func TestCheckCombine(checks ...TestCheck) TestCheck { // TestCheckExitCode assert exitCode func TestCheckExitCode(expectedCode int) TestCheck { return func(t *testing.T, ctx *CheckFuncCtx) { + t.Helper() assert.Equal(t, expectedCode, ctx.ExitCode, "Invalid exit code\n%s", string(ctx.Stderr)) } } @@ -640,6 +645,7 @@ func GoldenReplacePatterns(golden string, replacements ...GoldenReplacement) (st // golden are matched against given regex and edited with replacements func TestCheckGoldenAndReplacePatterns(replacements ...GoldenReplacement) TestCheck { return func(t *testing.T, ctx *CheckFuncCtx) { + t.Helper() actual := marshalGolden(t, ctx) actual, actualReplaceErr := GoldenReplacePatterns(actual, replacements...) @@ -660,6 +666,7 @@ func TestCheckGoldenAndReplacePatterns(replacements ...GoldenReplacement) TestCh // TestCheckGolden assert stderr and stdout using golden func TestCheckGolden() TestCheck { return func(t *testing.T, ctx *CheckFuncCtx) { + t.Helper() actual := marshalGolden(t, ctx) goldenPath := getTestFilePath(t, ".golden") @@ -678,6 +685,7 @@ func TestCheckGolden() TestCheck { // TestCheckS3Golden assert stderr and stdout using golden, and omits the random suffix in the bucket name func TestCheckS3Golden() TestCheck { return func(t *testing.T, ctx *CheckFuncCtx) { + t.Helper() actual := marshalGolden(t, ctx) normalizedActual := removeRandomPrefixFromOutput(actual) @@ -710,6 +718,7 @@ func removeRandomPrefixFromOutput(output string) string { // TestCheckError asserts error func TestCheckError(err error) TestCheck { return func(t *testing.T, ctx *CheckFuncCtx) { + t.Helper() assert.Equal(t, err, ctx.Err, "Invalid error") } } @@ -717,6 +726,7 @@ func TestCheckError(err error) TestCheck { // TestCheckStdout asserts stdout using string func TestCheckStdout(stdout string) TestCheck { return func(t *testing.T, ctx *CheckFuncCtx) { + t.Helper() assert.Equal(t, stdout, string(ctx.Stdout), "Invalid stdout") } } @@ -736,6 +746,7 @@ func uniformTimestamps(input string) string { } func validateJSONGolden(t *testing.T, jsonStdout, jsonStderr *bytes.Buffer) { + t.Helper() var jsonInterface interface{} if jsonStdout.Len() > 0 { err := json.Unmarshal(jsonStdout.Bytes(), &jsonInterface) @@ -748,6 +759,7 @@ func validateJSONGolden(t *testing.T, jsonStdout, jsonStderr *bytes.Buffer) { } func marshalGolden(t *testing.T, ctx *CheckFuncCtx) string { + t.Helper() jsonStderr := &bytes.Buffer{} jsonStdout := &bytes.Buffer{} diff --git a/internal/core/testing_recorder.go b/internal/core/testing_recorder.go index 7f02a865aa..edcd6931a8 100644 --- a/internal/core/testing_recorder.go +++ b/internal/core/testing_recorder.go @@ -114,6 +114,7 @@ func customS3Matcher(r *http.Request, i cassette.Request) bool { // It is important to call add a `defer cleanup()` so the given cassette files are correctly // closed and saved after the requests. func getHTTPRecoder(t *testing.T, update bool) (client *http.Client, cleanup func(), err error) { + t.Helper() recorderMode := recorder.ModeReplaying if update { recorderMode = recorder.ModeRecording diff --git a/internal/core/validate_test.go b/internal/core/validate_test.go index 5e414933c2..e82b8999d6 100644 --- a/internal/core/validate_test.go +++ b/internal/core/validate_test.go @@ -40,6 +40,7 @@ func Test_DefaultCommandValidateFunc(t *testing.T) { run := func(testCase TestCase) func(t *testing.T) { return func(t *testing.T) { + t.Helper() err := core.DefaultCommandValidateFunc()(context.Background(), testCase.command, testCase.parsedArguments, testCase.rawArgs) assert.Equal(t, errors.New("arg validation called"), err) } @@ -197,6 +198,7 @@ func Test_DefaultCommandRequiredFunc(t *testing.T) { runOK := func(testCase TestCase) func(t *testing.T) { return func(t *testing.T) { + t.Helper() err := core.DefaultCommandValidateFunc()(context.Background(), testCase.command, testCase.parsedArguments, testCase.rawArgs) assert.Equal(t, nil, err) } @@ -204,6 +206,7 @@ func Test_DefaultCommandRequiredFunc(t *testing.T) { runErr := func(testCase TestCase, argName string) func(t *testing.T) { return func(t *testing.T) { + t.Helper() err := core.DefaultCommandValidateFunc()(context.Background(), testCase.command, testCase.parsedArguments, testCase.rawArgs) assert.Equal(t, core.MissingRequiredArgumentError(argName), err) } @@ -301,6 +304,7 @@ func Test_ValidateNoConflict(t *testing.T) { runOK := func(testCase TestCase) func(t *testing.T) { return func(t *testing.T) { + t.Helper() err := core.ValidateNoConflict(testCase.command, testCase.rawArgs) assert.Equal(t, nil, err) } @@ -308,6 +312,7 @@ func Test_ValidateNoConflict(t *testing.T) { runErr := func(testCase TestCase) func(t *testing.T) { return func(t *testing.T) { + t.Helper() err := core.ValidateNoConflict(testCase.command, testCase.rawArgs) assert.Equal(t, core.ArgumentConflictError(testCase.arg1, testCase.arg2), err) } @@ -366,6 +371,7 @@ func Test_ValidateDeprecated(t *testing.T) { Cmd: "scw plop a=yo", Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.Equal(t, "The argument 'a' is deprecated, more info with: scw plop --help\n", ctx.LogBuffer) }, ), @@ -397,6 +403,7 @@ func TestNewOneOfGroupManager(t *testing.T) { expectedRequiredGroups: map[string]bool{}, }, testFunc: func(t *testing.T, tc TestCase) { + t.Helper() manager := core.NewOneOfGroupManager(tc.command) assert.Equal(t, tc.expectedGroups, manager.Groups) assert.Equal(t, tc.expectedRequiredGroups, manager.RequiredGroups) @@ -415,6 +422,7 @@ func TestNewOneOfGroupManager(t *testing.T) { expectedRequiredGroups: map[string]bool{"group1": true}, }, testFunc: func(t *testing.T, tc TestCase) { + t.Helper() manager := core.NewOneOfGroupManager(tc.command) assert.Equal(t, tc.expectedGroups, manager.Groups) assert.Equal(t, tc.expectedRequiredGroups, manager.RequiredGroups) @@ -438,6 +446,7 @@ func TestNewOneOfGroupManager(t *testing.T) { expectedRequiredGroups: map[string]bool{}, }, testFunc: func(t *testing.T, tc TestCase) { + t.Helper() manager := core.NewOneOfGroupManager(tc.command) assert.Equal(t, tc.expectedGroups, manager.Groups) assert.Equal(t, tc.expectedRequiredGroups, manager.RequiredGroups) @@ -463,6 +472,7 @@ func TestNewOneOfGroupManager(t *testing.T) { }, }, testFunc: func(t *testing.T, tc TestCase) { + t.Helper() manager := core.NewOneOfGroupManager(tc.command) assert.Equal(t, tc.expectedGroups, manager.Groups) assert.Equal(t, tc.expectedRequiredGroups, manager.RequiredGroups) diff --git a/internal/gofields/gofields_test.go b/internal/gofields/gofields_test.go index 0e004a6435..e6c32cbacf 100644 --- a/internal/gofields/gofields_test.go +++ b/internal/gofields/gofields_test.go @@ -45,6 +45,7 @@ func TestGetValue(t *testing.T) { run := func(tc *TestCase) func(*testing.T) { return func(t *testing.T) { + t.Helper() actual, err := gofields.GetValue(tc.Data, tc.Path) if err != nil { assert.Equal(t, tc.Expected, err.Error()) @@ -154,6 +155,7 @@ func TestGetType(t *testing.T) { run := func(tc *TestCase) func(*testing.T) { return func(t *testing.T) { + t.Helper() actual, err := gofields.GetType(tc.Data, tc.Path) if err != nil { assert.Equal(t, tc.Expected, err.Error()) @@ -229,6 +231,7 @@ func TestListFields(t *testing.T) { run := func(tc *TestCase) func(*testing.T) { return func(t *testing.T) { + t.Helper() actual := gofields.ListFields(tc.Data) assert.Equal(t, tc.Expected, actual) } @@ -249,6 +252,7 @@ func TestListFieldsWithFilter(t *testing.T) { run := func(tc *TestCase) func(*testing.T) { return func(t *testing.T) { + t.Helper() actual := gofields.ListFieldsWithFilter(tc.Data, tc.Filter) assert.Equal(t, tc.Expected, actual) } diff --git a/internal/human/marshal_test.go b/internal/human/marshal_test.go index 9543349cda..6e7dd7283b 100644 --- a/internal/human/marshal_test.go +++ b/internal/human/marshal_test.go @@ -76,6 +76,7 @@ func TestMarshal(t *testing.T) { run := func(tc *testCase) func(*testing.T) { return func(t *testing.T) { + t.Helper() result, err := human.Marshal(tc.data, tc.opt) // Format expected to allow indentation when writing test diff --git a/internal/namespaces/alias/alias_test.go b/internal/namespaces/alias/alias_test.go index 9f038bd713..718652737a 100644 --- a/internal/namespaces/alias/alias_test.go +++ b/internal/namespaces/alias/alias_test.go @@ -23,6 +23,7 @@ func Test_Alias(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.Contains(t, string(ctx.Stderr), "instance server list") }, ), @@ -41,6 +42,7 @@ func Test_Alias(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.Contains(t, string(ctx.Stderr), "instance server list") }, ), @@ -57,6 +59,7 @@ func Test_Alias(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.Contains(t, string(ctx.Stdout), "myalias") assert.Contains(t, string(ctx.Stdout), "iam") }, @@ -88,6 +91,7 @@ func Test_Alias(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.Contains(t, string(ctx.Stdout), "Deleted") }, ), diff --git a/internal/namespaces/autocomplete/autocomplete_test.go b/internal/namespaces/autocomplete/autocomplete_test.go index 1f9605178c..f3424f1913 100644 --- a/internal/namespaces/autocomplete/autocomplete_test.go +++ b/internal/namespaces/autocomplete/autocomplete_test.go @@ -15,6 +15,7 @@ func TestTrimText(t *testing.T) { run := func(tc *testCase) func(*testing.T) { return func(t *testing.T) { + t.Helper() result := autocomplete.TrimText(tc.Script) assert.Equal(t, tc.TrimedScript, result) } diff --git a/internal/namespaces/baremetal/v1/custom_server_create_test.go b/internal/namespaces/baremetal/v1/custom_server_create_test.go index 1d04d9bcf7..fb926bb442 100644 --- a/internal/namespaces/baremetal/v1/custom_server_create_test.go +++ b/internal/namespaces/baremetal/v1/custom_server_create_test.go @@ -29,6 +29,7 @@ func Test_CreateServer(t *testing.T) { Cmd: "scw baremetal server create name=test-create-server-with-name zone=nl-ams-1 type=GP-BM2-S -w", Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.Equal(t, "test-create-server-with-name", ctx.Result.(*baremetalSDK.Server).Name) }, core.TestCheckExitCode(0), @@ -41,6 +42,7 @@ func Test_CreateServer(t *testing.T) { Cmd: "scw baremetal server create tags.0=prod tags.1=blue zone=nl-ams-1 type=GP-BM2-S -w", Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.Equal(t, "prod", ctx.Result.(*baremetalSDK.Server).Tags[0]) assert.Equal(t, "blue", ctx.Result.(*baremetalSDK.Server).Tags[1]) }, diff --git a/internal/namespaces/config/commands_test.go b/internal/namespaces/config/commands_test.go index 9a8a6da1a1..33ffa6afea 100644 --- a/internal/namespaces/config/commands_test.go +++ b/internal/namespaces/config/commands_test.go @@ -68,6 +68,7 @@ func Test_ConfigSetCommand(t *testing.T) { core.TestCheckExitCode(0), core.TestCheckGolden(), checkConfig(func(t *testing.T, config *scw.Config) { + t.Helper() assert.Equal(t, "SCWNEWXXXXXXXXXXXXXX", *config.AccessKey) }), ), @@ -82,6 +83,7 @@ func Test_ConfigSetCommand(t *testing.T) { core.TestCheckExitCode(0), core.TestCheckGolden(), checkConfig(func(t *testing.T, config *scw.Config) { + t.Helper() assert.Equal(t, "SCWNEWXXXXXXXXXXXXXX", *config.Profiles["p1"].AccessKey) }), ), @@ -96,6 +98,7 @@ func Test_ConfigSetCommand(t *testing.T) { core.TestCheckExitCode(0), core.TestCheckGolden(), checkConfig(func(t *testing.T, config *scw.Config) { + t.Helper() assert.Equal(t, true, *config.SendTelemetry) }), ), @@ -110,6 +113,7 @@ func Test_ConfigSetCommand(t *testing.T) { core.TestCheckExitCode(0), core.TestCheckGolden(), checkConfig(func(t *testing.T, config *scw.Config) { + t.Helper() assert.Equal(t, "SCWNEWXXXXXXXXXXXXXX", *config.Profiles["test"].AccessKey) }), ), @@ -126,6 +130,7 @@ func Test_ConfigUnsetCommand(t *testing.T) { core.TestCheckExitCode(0), core.TestCheckGolden(), checkConfig(func(t *testing.T, config *scw.Config) { + t.Helper() assert.Nil(t, config.AccessKey) }), ), @@ -140,6 +145,7 @@ func Test_ConfigUnsetCommand(t *testing.T) { core.TestCheckExitCode(0), core.TestCheckGolden(), checkConfig(func(t *testing.T, config *scw.Config) { + t.Helper() assert.Nil(t, config.Profiles["p1"].AccessKey) }), ), @@ -154,6 +160,7 @@ func Test_ConfigUnsetCommand(t *testing.T) { core.TestCheckExitCode(0), core.TestCheckGolden(), checkConfig(func(t *testing.T, config *scw.Config) { + t.Helper() assert.Nil(t, config.SendTelemetry) }), ), @@ -181,6 +188,7 @@ func Test_ConfigDeleteProfileCommand(t *testing.T) { core.TestCheckExitCode(0), core.TestCheckGolden(), checkConfig(func(t *testing.T, config *scw.Config) { + t.Helper() assert.Nil(t, config.Profiles["p2"]) }), ), @@ -320,6 +328,7 @@ func Test_ConfigImportCommand(t *testing.T) { core.TestCheckExitCode(0), core.TestCheckGolden(), checkConfig(func(t *testing.T, config *scw.Config) { + t.Helper() // config assert.Equal(t, "22222222-2222-2222-2222-222222222222", *config.SecretKey) assert.Equal(t, "nl-ams", *config.DefaultRegion) @@ -374,6 +383,7 @@ func Test_ConfigValidateCommand(t *testing.T) { func checkConfig(f func(t *testing.T, config *scw.Config)) core.TestCheck { return func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() homeDir := ctx.OverrideEnv["HOME"] config, err := scw.LoadConfigFromPath(path.Join(homeDir, ".config", "scw", "config.yaml")) require.NoError(t, err) diff --git a/internal/namespaces/container/v1beta1/custom_container_test.go b/internal/namespaces/container/v1beta1/custom_container_test.go index 4fe64586c7..6b34f4f073 100644 --- a/internal/namespaces/container/v1beta1/custom_container_test.go +++ b/internal/namespaces/container/v1beta1/custom_container_test.go @@ -31,6 +31,7 @@ func Test_Create(t *testing.T) { Cmd: fmt.Sprintf("scw container container create namespace-id={{ .Namespace.ID }} name=%s deploy=true", core.GetRandomName("test")), Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() c := ctx.Result.(*containerSDK.Container) assert.Equal(t, containerSDK.ContainerStatusPending, c.Status) }, diff --git a/internal/namespaces/iam/v1alpha1/custom_policy_test.go b/internal/namespaces/iam/v1alpha1/custom_policy_test.go index f7113d2efe..1132644d29 100644 --- a/internal/namespaces/iam/v1alpha1/custom_policy_test.go +++ b/internal/namespaces/iam/v1alpha1/custom_policy_test.go @@ -22,6 +22,7 @@ func Test_getPolicyWithRules(t *testing.T) { Cmd: `scw iam policy get {{ .Policy.ID }}`, Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.Contains(t, string(ctx.Stdout), "IPAMReadOnly") }, core.TestCheckGolden(), diff --git a/internal/namespaces/iam/v1alpha1/custom_rule_test.go b/internal/namespaces/iam/v1alpha1/custom_rule_test.go index 7cf8f0b78a..4997973ee8 100644 --- a/internal/namespaces/iam/v1alpha1/custom_rule_test.go +++ b/internal/namespaces/iam/v1alpha1/custom_rule_test.go @@ -23,6 +23,7 @@ func Test_createRule(t *testing.T) { Cmd: `scw iam rule create {{ .Policy.ID }} permission-set-names.0=VPCReadOnly project-ids.0={{ .Project.ID }}`, Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.Contains(t, string(ctx.Stdout), "IPAMReadOnly") assert.Contains(t, string(ctx.Stdout), "VPCReadOnly") }, @@ -60,6 +61,7 @@ func Test_deleteRule(t *testing.T) { Cmd: `scw iam rule delete {{ .Policy.ID }} rule-id={{ .Rule.ID }}`, Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.NotContains(t, string(ctx.Stdout), "IPAMReadOnly") assert.Contains(t, string(ctx.Stdout), "VPCReadOnly") }, diff --git a/internal/namespaces/init/custom_init_autocomplete_test.go b/internal/namespaces/init/custom_init_autocomplete_test.go index 959de6126b..d37e396bf7 100644 --- a/internal/namespaces/init/custom_init_autocomplete_test.go +++ b/internal/namespaces/init/custom_init_autocomplete_test.go @@ -39,6 +39,7 @@ func Test_InitAutocomplete(t *testing.T) { } runAllShells := func(t *testing.T) { + t.Helper() t.Run("Without", core.Test(&core.TestConfig{ Commands: initCLI.GetCommands(), BeforeFunc: baseBeforeFunc(), @@ -59,6 +60,7 @@ eval "$(scw autocomplete script shell=zsh)" Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() if runtime.GOOS == windows { // autocomplete installation is not yet supported on windows return @@ -108,6 +110,7 @@ eval (scw autocomplete script shell=fish) Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() if runtime.GOOS == windows { // autocomplete installation is not yet supported on windows return @@ -144,6 +147,7 @@ eval "$(scw autocomplete script shell=bash)" Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() homeDir := ctx.OverrideEnv["HOME"] filePath := "" switch runtime.GOOS { diff --git a/internal/namespaces/init/init_test.go b/internal/namespaces/init/init_test.go index 88c22adbcb..037a6f15d0 100644 --- a/internal/namespaces/init/init_test.go +++ b/internal/namespaces/init/init_test.go @@ -15,6 +15,7 @@ import ( func checkConfig(check func(t *testing.T, ctx *core.CheckFuncCtx, config *scw.Config)) core.TestCheck { return func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() homeDir := ctx.OverrideEnv["HOME"] config, err := scw.LoadConfigFromPath(path.Join(homeDir, ".config", "scw", "config.yaml")) require.NoError(t, err) @@ -56,6 +57,7 @@ func TestInit(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), checkConfig(func(t *testing.T, ctx *core.CheckFuncCtx, config *scw.Config) { + t.Helper() secretKey, _ := ctx.Client.GetSecretKey() assert.Equal(t, secretKey, *config.SecretKey) assert.NotEmpty(t, *config.DefaultProjectID) @@ -78,6 +80,7 @@ func TestInit(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() config, err := scw.LoadConfigFromPath(ctx.Meta["CONFIG_PATH"].(string)) require.NoError(t, err) secretKey, _ := ctx.Client.GetSecretKey() @@ -93,6 +96,7 @@ func TestInit(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), checkConfig(func(t *testing.T, ctx *core.CheckFuncCtx, config *scw.Config) { + t.Helper() secretKey, _ := ctx.Client.GetSecretKey() assert.Equal(t, secretKey, *config.Profiles["foobar"].SecretKey) }), @@ -127,6 +131,7 @@ func TestInit(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), checkConfig(func(t *testing.T, _ *core.CheckFuncCtx, config *scw.Config) { + t.Helper() assert.Equal(t, dummyConfig.String(), config.String()) }), ), @@ -147,6 +152,7 @@ func TestInit(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), checkConfig(func(t *testing.T, ctx *core.CheckFuncCtx, config *scw.Config) { + t.Helper() secretKey, _ := ctx.Client.GetSecretKey() assert.Equal(t, secretKey, *config.SecretKey) }), @@ -168,6 +174,7 @@ func TestInit(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), checkConfig(func(t *testing.T, _ *core.CheckFuncCtx, config *scw.Config) { + t.Helper() assert.NotNil(t, config.Profiles["test2"], "new profile should have been created") }), ), @@ -188,6 +195,7 @@ func TestInit(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), checkConfig(func(t *testing.T, _ *core.CheckFuncCtx, config *scw.Config) { + t.Helper() assert.NotNil(t, config.Profiles["test"].DefaultZone) assert.Equal(t, *config.Profiles["test"].DefaultZone, "fr-test") }), @@ -207,6 +215,7 @@ func TestInit(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), checkConfig(func(t *testing.T, _ *core.CheckFuncCtx, config *scw.Config) { + t.Helper() assert.NotNil(t, config.ActiveProfile) assert.Equal(t, "newprofile", *config.ActiveProfile) }), @@ -250,6 +259,7 @@ func TestInit_Prompt(t *testing.T) { }, ), checkConfig(func(t *testing.T, ctx *core.CheckFuncCtx, config *scw.Config) { + t.Helper() secretKey, _ := ctx.Client.GetSecretKey() assert.Equal(t, secretKey, *config.SecretKey) assert.NotEmpty(t, *config.DefaultProjectID) diff --git a/internal/namespaces/instance/v1/args_test.go b/internal/namespaces/instance/v1/args_test.go index b758e4c46e..b4648a3f23 100644 --- a/internal/namespaces/instance/v1/args_test.go +++ b/internal/namespaces/instance/v1/args_test.go @@ -22,6 +22,7 @@ func TestNullableStringValueUnmarshal(t *testing.T) { run := func(tc *testCase) func(t *testing.T) { return func(t *testing.T) { + t.Helper() err := args.UnmarshalStruct(tc.args, tc.data) assert.Equal(t, tc.expectedError, err) assert.Equal(t, tc.expectedStruct, tc.data) @@ -72,6 +73,7 @@ func TestNullableStringValueMarshal(t *testing.T) { run := func(tc *testCase) func(t *testing.T) { return func(t *testing.T) { + t.Helper() args, err := args.MarshalStruct(tc.data) assert.Equal(t, tc.expectedError, err) assert.Equal(t, tc.expectedStruct, args) diff --git a/internal/namespaces/instance/v1/custom_image_test.go b/internal/namespaces/instance/v1/custom_image_test.go index 374c5fab76..9bba13dabb 100644 --- a/internal/namespaces/instance/v1/custom_image_test.go +++ b/internal/namespaces/instance/v1/custom_image_test.go @@ -59,6 +59,7 @@ func Test_ImageDelete(t *testing.T) { core.TestCheckGolden(), core.TestCheckExitCode(0), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() // Assert snapshot are deleted with the image api := instanceSDK.NewAPI(ctx.Client) _, err := api.GetSnapshot(&instanceSDK.GetSnapshotRequest{ @@ -103,6 +104,7 @@ func Test_ImageUpdate(t *testing.T) { Cmd: "scw instance image update {{ .ImageName.Image.ID }} name=foo", Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.NotNil(t, ctx.Result) assert.Equal(t, "foo", ctx.Result.(*instanceSDK.UpdateImageResponse).Image.Name) }, @@ -123,6 +125,7 @@ func Test_ImageUpdate(t *testing.T) { core.TestCheckGolden(), core.TestCheckExitCode(0), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.NotNil(t, ctx.Result) assert.Equal(t, true, ctx.Result.(*instanceSDK.UpdateImageResponse).Image.Public) }, @@ -143,6 +146,7 @@ func Test_ImageUpdate(t *testing.T) { Cmd: "scw instance image update {{ .ImageExtraVol.Image.ID }} extra-volumes.1.id={{ .SnapshotVol.ID }}", Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.NotNil(t, ctx.Result) assert.Equal(t, "snapVol", ctx.Result.(*instanceSDK.UpdateImageResponse).Image.ExtraVolumes["1"].Name) }, diff --git a/internal/namespaces/instance/v1/custom_server_action_test.go b/internal/namespaces/instance/v1/custom_server_action_test.go index e13f4b18a4..31002419d5 100644 --- a/internal/namespaces/instance/v1/custom_server_action_test.go +++ b/internal/namespaces/instance/v1/custom_server_action_test.go @@ -25,6 +25,7 @@ func Test_ServerTerminate(t *testing.T) { core.TestCheckGolden(), core.TestCheckExitCode(0), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() api := instanceSDK.NewAPI(ctx.Client) server := ctx.Meta["Server"].(*instanceSDK.Server) _, err := api.GetIP(&instanceSDK.GetIPRequest{ @@ -45,6 +46,7 @@ func Test_ServerTerminate(t *testing.T) { core.TestCheckGolden(), core.TestCheckExitCode(0), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() api := instanceSDK.NewAPI(ctx.Client) server := ctx.Meta["Server"].(*instanceSDK.Server) _, err := api.GetIP(&instanceSDK.GetIPRequest{ @@ -80,6 +82,7 @@ func Test_ServerTerminate(t *testing.T) { core.TestCheckGolden(), core.TestCheckExitCode(0), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() api := instanceSDK.NewAPI(ctx.Client) server := ctx.Meta["Server"].(*instanceSDK.Server) _, err := api.GetVolume(&instanceSDK.GetVolumeRequest{ @@ -121,6 +124,7 @@ func Test_ServerAction(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckExitCode(0), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() storedServer := ctx.Meta["Server"].(*instanceSDK.Server) api := instanceSDK.NewAPI(ctx.Client) resp, err := api.GetServer(&instanceSDK.GetServerRequest{ @@ -145,6 +149,7 @@ func Test_ServerEnableRoutedIP(t *testing.T) { Cmd: `scw instance server enable-routed-ip zone=fr-par-3 {{ .Server.ID }} --wait`, Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() storedServer := ctx.Meta["Server"].(*instanceSDK.Server) api := instanceSDK.NewAPI(ctx.Client) server, err := api.GetServer(&instanceSDK.GetServerRequest{ diff --git a/internal/namespaces/instance/v1/custom_server_create_test.go b/internal/namespaces/instance/v1/custom_server_create_test.go index 9a0ae09f8a..4a2d484362 100644 --- a/internal/namespaces/instance/v1/custom_server_create_test.go +++ b/internal/namespaces/instance/v1/custom_server_create_test.go @@ -29,6 +29,7 @@ func Test_CreateServer(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.NotNil(t, ctx.Result) assert.Equal(t, "Ubuntu 22.04 Jammy Jellyfish", ctx.Result.(*instanceSDK.Server).Image.Name) }, @@ -42,6 +43,7 @@ func Test_CreateServer(t *testing.T) { Cmd: "scw instance server create type=GP1-XS image=ubuntu_bionic stopped=true", Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.NotNil(t, ctx.Result) assert.Equal(t, "GP1-XS", ctx.Result.(*instanceSDK.Server).CommercialType) }, @@ -55,6 +57,7 @@ func Test_CreateServer(t *testing.T) { Cmd: "scw instance server create image=ubuntu_bionic name=yo stopped=true", Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.NotNil(t, ctx.Result) assert.Equal(t, "yo", ctx.Result.(*instanceSDK.Server).Name) }, @@ -68,6 +71,7 @@ func Test_CreateServer(t *testing.T) { Cmd: "scw instance server create image=ubuntu_bionic -w", Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.NotNil(t, ctx.Result) assert.Equal(t, instanceSDK.ServerStateRunning, ctx.Result.(*instanceSDK.Server).State) }, @@ -81,6 +85,7 @@ func Test_CreateServer(t *testing.T) { Cmd: "scw instance server create image=f974feac-abae-4365-b988-8ec7d1cec10d stopped=true", Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.NotNil(t, ctx.Result) assert.Equal(t, "Ubuntu Bionic Beaver", ctx.Result.(*instanceSDK.Server).Image.Name) }, @@ -94,6 +99,7 @@ func Test_CreateServer(t *testing.T) { Cmd: "scw instance server create image=ubuntu_bionic tags.0=prod tags.1=blue stopped=true", Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.NotNil(t, ctx.Result) assert.Equal(t, "prod", ctx.Result.(*instanceSDK.Server).Tags[0]) assert.Equal(t, "blue", ctx.Result.(*instanceSDK.Server).Tags[1]) @@ -113,6 +119,7 @@ func Test_CreateServer(t *testing.T) { Cmd: "scw instance server create image=ubuntu_bionic root-volume=local:20GB stopped=true", Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.NotNil(t, ctx.Result) assert.Equal(t, 20*scw.GB, ctx.Result.(*instanceSDK.Server).Volumes["0"].Size) }, @@ -131,6 +138,7 @@ func Test_CreateServer(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckExitCode(0), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.NotNil(t, ctx.Result) assert.Equal(t, 20*scw.GB, ctx.Result.(*instanceSDK.Server).Volumes["0"].Size) }, @@ -152,6 +160,7 @@ func Test_CreateServer(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckExitCode(0), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.NotNil(t, ctx.Result) assert.Equal(t, 20*scw.GB, ctx.Result.(*instanceSDK.Server).Volumes["0"].Size) }, @@ -168,6 +177,7 @@ func Test_CreateServer(t *testing.T) { Cmd: "scw instance server create image=ubuntu_bionic root-volume=local:10GB additional-volumes.0=l:10G stopped=true", Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.NotNil(t, ctx.Result) assert.Equal(t, 10*scw.GB, ctx.Result.(*instanceSDK.Server).Volumes["0"].Size) assert.Equal(t, 10*scw.GB, ctx.Result.(*instanceSDK.Server).Volumes["1"].Size) @@ -187,6 +197,7 @@ func Test_CreateServer(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckExitCode(0), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.NotNil(t, ctx.Result) assert.Equal(t, 20*scw.GB, ctx.Result.(*instanceSDK.Server).Volumes["0"].Size) assert.Equal(t, 20*scw.GB, ctx.Result.(*instanceSDK.Server).Volumes["1"].Size) @@ -204,6 +215,7 @@ func Test_CreateServer(t *testing.T) { Cmd: "scw instance server create image=ubuntu_bionic additional-volumes.0=b:1G additional-volumes.1=b:5G additional-volumes.2=b:10G stopped=true", Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.NotNil(t, ctx.Result) assert.Equal(t, 1*scw.GB, ctx.Result.(*instanceSDK.Server).Volumes["1"].Size) assert.Equal(t, 5*scw.GB, ctx.Result.(*instanceSDK.Server).Volumes["2"].Size) @@ -225,6 +237,7 @@ func Test_CreateServer(t *testing.T) { Cmd: "scw instance server create image=ubuntu_jammy additional-volumes.0={{.Volume.ID}} stopped=true", Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.NotNil(t, ctx.Result) assert.Equal(t, instanceSDK.VolumeServerVolumeTypeSbsVolume, ctx.Result.(*instanceSDK.Server).Volumes["1"].VolumeType) }, @@ -247,6 +260,7 @@ func Test_CreateServer(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckExitCode(0), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.NotNil(t, ctx.Result) assert.Equal(t, instanceSDK.VolumeServerVolumeTypeSbsVolume, ctx.Result.(*instanceSDK.Server).Volumes["0"].VolumeType) }, @@ -286,6 +300,7 @@ func Test_CreateServer(t *testing.T) { Cmd: "scw instance server create image=ubuntu_bionic ip=new stopped=true", Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.NotNil(t, ctx.Result) assert.NotEmpty(t, ctx.Result.(*instanceSDK.Server).PublicIP.Address) assert.Equal(t, false, ctx.Result.(*instanceSDK.Server).PublicIP.Dynamic) @@ -300,6 +315,7 @@ func Test_CreateServer(t *testing.T) { Cmd: "scw instance server create image=ubuntu_bionic ip=dynamic -w", // dynamic IP is created at runtime Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.NoError(t, ctx.Err) assert.NotNil(t, ctx.Result) assert.NotEmpty(t, ctx.Result.(*instanceSDK.Server).PublicIP.Address) @@ -316,6 +332,7 @@ func Test_CreateServer(t *testing.T) { Cmd: "scw instance server create image=ubuntu_bionic ip={{ .IP.Address }} stopped=true", Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.NotNil(t, ctx.Result) assert.NotEmpty(t, ctx.Result.(*instanceSDK.Server).PublicIP.Address) assert.Equal(t, false, ctx.Result.(*instanceSDK.Server).PublicIP.Dynamic) @@ -331,6 +348,7 @@ func Test_CreateServer(t *testing.T) { Cmd: "scw instance server create image=ubuntu_bionic ip={{ .IP.ID }} stopped=true", Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.NotNil(t, ctx.Result) assert.NotEmpty(t, ctx.Result.(*instanceSDK.Server).PublicIP.Address) assert.Equal(t, false, ctx.Result.(*instanceSDK.Server).PublicIP.Dynamic) @@ -345,6 +363,7 @@ func Test_CreateServer(t *testing.T) { Cmd: "scw instance server create image=ubuntu_bionic routed-ip-enabled=false ipv6=true -w", // IPv6 is created at runtime Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.NotNil(t, ctx.Result) assert.NotNil(t, ctx.Result.(*instanceSDK.Server).IPv6) assert.NotEmpty(t, ctx.Result.(*instanceSDK.Server).IPv6.Address) @@ -599,6 +618,7 @@ func Test_CreateServerScratchStorage(t *testing.T) { }, core.TestCheckExitCode(0), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() server, isServer := ctx.Result.(*instanceSDK.Server) if !isServer { t.Fatalf("Result is not a server") diff --git a/internal/namespaces/instance/v1/custom_server_rdp_test.go b/internal/namespaces/instance/v1/custom_server_rdp_test.go index 2cf0c39e7b..9e9fcc48b9 100644 --- a/internal/namespaces/instance/v1/custom_server_rdp_test.go +++ b/internal/namespaces/instance/v1/custom_server_rdp_test.go @@ -126,6 +126,7 @@ func Test_ServerGetRdpPassword(t *testing.T) { core.TestCheckGolden(), core.TestCheckExitCode(0), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.NotNil(t, ctx.Result) resp, ok := ctx.Result.(*instance.ServerGetRdpPasswordResponse) if !ok { diff --git a/internal/namespaces/instance/v1/custom_server_test.go b/internal/namespaces/instance/v1/custom_server_test.go index e961e907e4..b3d86e4717 100644 --- a/internal/namespaces/instance/v1/custom_server_test.go +++ b/internal/namespaces/instance/v1/custom_server_test.go @@ -24,6 +24,7 @@ func Test_ServerVolumeUpdate(t *testing.T) { ), Cmd: "scw instance server attach-volume server-id={{ .Server.ID }} volume-id={{ .Volume.ID }}", Check: func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() require.NoError(t, ctx.Err) assert.Equal(t, 20*scw.GB, ctx.Result.(*instanceSDK.AttachVolumeResponse).Server.Volumes["0"].Size) assert.Equal(t, 10*scw.GB, ctx.Result.(*instanceSDK.AttachVolumeResponse).Server.Volumes["1"].Size) @@ -41,6 +42,7 @@ func Test_ServerVolumeUpdate(t *testing.T) { ), Cmd: "scw instance server attach-volume server-id={{ .Server.ID }} volume-id={{ .Volume.ID }}", Check: func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() require.NoError(t, ctx.Err) assert.Equal(t, 20*scw.GB, ctx.Result.(*instanceSDK.AttachVolumeResponse).Server.Volumes["0"].Size) assert.Equal(t, 10*scw.GB, ctx.Result.(*instanceSDK.AttachVolumeResponse).Server.Volumes["1"].Size) @@ -68,6 +70,7 @@ func Test_ServerVolumeUpdate(t *testing.T) { BeforeFunc: core.ExecStoreBeforeCmd("Server", "scw instance server create stopped=true image=ubuntu-bionic additional-volumes.0=block:10G"), Cmd: `scw instance server detach-volume volume-id={{ (index .Server.Volumes "1").ID }}`, Check: func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() require.NoError(t, ctx.Err) assert.NotZero(t, ctx.Result.(*instanceSDK.DetachVolumeResponse).Server.Volumes["0"]) assert.Nil(t, ctx.Result.(*instanceSDK.DetachVolumeResponse).Server.Volumes["1"]) @@ -102,6 +105,7 @@ func Test_ServerUpdateCustom(t *testing.T) { Cmd: "scw instance server update {{ .Server.ID }} ip=none", Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.Equal(t, (*instanceSDK.ServerIP)(nil), ctx.Result.(*instanceSDK.UpdateServerResponse).Server.PublicIP) }, core.TestCheckExitCode(0), @@ -118,6 +122,7 @@ func Test_ServerUpdateCustom(t *testing.T) { Cmd: "scw instance server update {{ .Server.ID }} ip={{ .IP.Address }}", Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.Equal(t, ctx.Meta["IP"].(*instanceSDK.IP).Address, ctx.Result.(*instanceSDK.UpdateServerResponse).Server.PublicIP.Address) }, core.TestCheckExitCode(0), @@ -138,6 +143,7 @@ func Test_ServerUpdateCustom(t *testing.T) { Cmd: "scw instance server update {{ .Server.ID }} ip={{ .IP2.Address }}", Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() // Test that the Server WAS attached to IP1. assert.Equal(t, ctx.Meta["IP1"].(*instanceSDK.IP).Address, @@ -167,6 +173,7 @@ func Test_ServerUpdateCustom(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckExitCode(0), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.Equal(t, ctx.Meta["PlacementGroup2"].(*instanceSDK.PlacementGroup).ID, ctx.Result.(*instanceSDK.UpdateServerResponse).Server.PlacementGroup.ID) @@ -191,6 +198,7 @@ func Test_ServerUpdateCustom(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckExitCode(0), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.Equal(t, ctx.Meta["SecurityGroup2"].(*instanceSDK.SecurityGroup).ID, ctx.Result.(*instanceSDK.UpdateServerResponse).Server.SecurityGroup.ID) @@ -213,6 +221,7 @@ func Test_ServerUpdateCustom(t *testing.T) { ), Cmd: `scw instance server update {{ .Server.ID }} volume-ids.0={{ (index .Server.Volumes "0").ID }} volume-ids.1={{ .Volume.ID }}`, Check: func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() require.NoError(t, ctx.Err) assert.Equal(t, 20*scw.GB, ctx.Result.(*instanceSDK.UpdateServerResponse).Server.Volumes["0"].Size) assert.Equal(t, 10*scw.GB, ctx.Result.(*instanceSDK.UpdateServerResponse).Server.Volumes["1"].Size) @@ -225,6 +234,7 @@ func Test_ServerUpdateCustom(t *testing.T) { BeforeFunc: core.ExecStoreBeforeCmd("Server", "scw instance server create stopped=true image=ubuntu-bionic additional-volumes.0=block:10G"), Cmd: `scw instance server update {{ .Server.ID }} volume-ids=none`, Check: func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() require.NoError(t, ctx.Err) assert.Equal(t, 0, len(ctx.Result.(*instanceSDK.UpdateServerResponse).Server.Volumes)) }, @@ -285,6 +295,7 @@ func Test_ServerDelete(t *testing.T) { core.TestCheckGolden(), core.TestCheckExitCode(0), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() api := instanceSDK.NewAPI(ctx.Client) server := ctx.Meta["Server"].(*instanceSDK.Server) _, err := api.GetVolume(&instanceSDK.GetVolumeRequest{ @@ -312,6 +323,7 @@ func Test_ServerDelete(t *testing.T) { core.TestCheckGolden(), core.TestCheckExitCode(0), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() api := block.NewAPI(ctx.Client) blockVolume := ctx.Meta["BlockVolume"].(*block.Volume) resp, err := api.GetVolume(&block.GetVolumeRequest{ diff --git a/internal/namespaces/instance/v1/custom_snapshot_test.go b/internal/namespaces/instance/v1/custom_snapshot_test.go index 454566c9d2..f8b93da1fd 100644 --- a/internal/namespaces/instance/v1/custom_snapshot_test.go +++ b/internal/namespaces/instance/v1/custom_snapshot_test.go @@ -22,6 +22,7 @@ func Test_UpdateSnapshot(t *testing.T) { core.TestCheckGolden(), core.TestCheckExitCode(0), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.NotNil(t, ctx.Result) snapshot := ctx.Result.(*instanceSDK.Snapshot) assert.Equal(t, snapshot.Name, "cli-test-snapshot-update-tags") @@ -46,6 +47,7 @@ func Test_UpdateSnapshot(t *testing.T) { core.TestCheckGolden(), core.TestCheckExitCode(0), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.NotNil(t, ctx.Result) snapshot := ctx.Result.(*instanceSDK.Snapshot) assert.Equal(t, snapshot.Name, "cli-test-snapshot-update-name-updated") diff --git a/internal/namespaces/instance/v1/custom_ssh_config_test.go b/internal/namespaces/instance/v1/custom_ssh_config_test.go index 8fe10d33b4..bd90d6a525 100644 --- a/internal/namespaces/instance/v1/custom_ssh_config_test.go +++ b/internal/namespaces/instance/v1/custom_ssh_config_test.go @@ -28,6 +28,7 @@ func Test_SSHConfigInstall(t *testing.T) { ), core.TestCheckExitCode(0), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() server := ctx.Meta["Server"].(*instanceSDK.Server) configPath := sshconfig.ConfigFilePath(ctx.Meta["HOME"].(string)) @@ -69,6 +70,7 @@ func Test_SSHConfigInstall(t *testing.T) { ), core.TestCheckExitCode(0), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() server := ctx.Meta["Server"].(*instanceSDK.Server) defaultConfigPath := sshconfig.DefaultConfigFilePath(ctx.Meta["HOME"].(string)) diff --git a/internal/namespaces/instance/v1/custom_ssh_key_test.go b/internal/namespaces/instance/v1/custom_ssh_key_test.go index 412149a190..98cc285d0b 100644 --- a/internal/namespaces/instance/v1/custom_ssh_key_test.go +++ b/internal/namespaces/instance/v1/custom_ssh_key_test.go @@ -44,6 +44,7 @@ func Test_SSHKey(t *testing.T) { core.TestCheckGolden(), core.TestCheckExitCode(0), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() server := ctx.Meta["Server"].(*instanceSDK.Server) resp, err := instanceSDK.NewAPI(ctx.Client).GetServer(&instanceSDK.GetServerRequest{ Zone: server.Zone, @@ -67,6 +68,7 @@ func Test_SSHKey(t *testing.T) { core.TestCheckGolden(), core.TestCheckExitCode(0), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() out := string(ctx.Stdout) assert.Contains(t, out, "key1") assert.Contains(t, out, "key2") @@ -86,6 +88,7 @@ func Test_SSHKey(t *testing.T) { core.TestCheckGolden(), core.TestCheckExitCode(0), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() server := ctx.Meta["Server"].(*instanceSDK.Server) resp, err := instanceSDK.NewAPI(ctx.Client).GetServer(&instanceSDK.GetServerRequest{ Zone: server.Zone, diff --git a/internal/namespaces/instance/v1/instance_cli_test.go b/internal/namespaces/instance/v1/instance_cli_test.go index ea462839bb..e46774071b 100644 --- a/internal/namespaces/instance/v1/instance_cli_test.go +++ b/internal/namespaces/instance/v1/instance_cli_test.go @@ -42,6 +42,7 @@ func Test_CreateVolume(t *testing.T) { Cmd: "scw instance volume create name=test size=20G", Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.Equal(t, "test", ctx.Result.(*instanceSDK.CreateVolumeResponse).Volume.Name) }, core.TestCheckExitCode(0), @@ -77,6 +78,7 @@ func Test_ServerUpdate(t *testing.T) { Cmd: "scw instance server update {{ .Server.ID }} placement-group-id=none", Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() require.NoError(t, ctx.Err) assert.Nil(t, ctx.Result.(*instanceSDK.UpdateServerResponse).Server.PlacementGroup) }, @@ -94,6 +96,7 @@ func Test_ServerUpdate(t *testing.T) { Cmd: `scw instance server update {{ .Server.ID }} placement-group-id={{ .PlacementGroup.ID }}`, Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() require.NoError(t, ctx.Err) assert.Equal(t, ctx.Meta["PlacementGroup"].(*instanceSDK.PlacementGroup).ID, @@ -139,6 +142,7 @@ func Test_ServerUpdate(t *testing.T) { Cmd: `scw instance server update {{ .Server.ID }} placement-group-id=none`, Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() require.NoError(t, ctx.Err) assert.Nil(t, ctx.Result.(*instanceSDK.UpdateServerResponse).Server.PlacementGroup) }, @@ -159,6 +163,7 @@ func Test_ServerUpdate(t *testing.T) { Cmd: `scw instance server update {{ .Server.ID }} placement-group-id={{ .PlacementGroup.ID }}`, Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() require.NoError(t, ctx.Err) assert.Equal(t, ctx.Meta["PlacementGroup"].(*instanceSDK.PlacementGroup).ID, @@ -183,6 +188,7 @@ func Test_ServerUpdate(t *testing.T) { Cmd: `scw instance server update {{ .Server.ID }} placement-group-id={{ .PlacementGroup2.ID }}`, Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() require.NoError(t, ctx.Err) assert.Equal(t, ctx.Meta["PlacementGroup2"].(*instanceSDK.PlacementGroup).ID, diff --git a/internal/namespaces/k8s/v1/custom_kubeconfig_get_test.go b/internal/namespaces/k8s/v1/custom_kubeconfig_get_test.go index 45ea5af2aa..46c7fbe34f 100644 --- a/internal/namespaces/k8s/v1/custom_kubeconfig_get_test.go +++ b/internal/namespaces/k8s/v1/custom_kubeconfig_get_test.go @@ -21,6 +21,7 @@ func Test_GetKubeconfig(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() config, err := yaml.Marshal(ctx.Meta["Kubeconfig"].(api.Config)) assert.Equal(t, err, nil) assert.Equal(t, ctx.Result.(string), string(config)) diff --git a/internal/namespaces/k8s/v1/custom_kubeconfig_install_test.go b/internal/namespaces/k8s/v1/custom_kubeconfig_install_test.go index f80221e71c..866443ab4b 100644 --- a/internal/namespaces/k8s/v1/custom_kubeconfig_install_test.go +++ b/internal/namespaces/k8s/v1/custom_kubeconfig_install_test.go @@ -92,6 +92,7 @@ y7JHcXauRKI7bxgOugSep2d0lhYxJl65CPOCllawcu70Ds34MKi3XkCe20I= // testIfKubeconfigInFile checks if the given kubeconfig is in the given file // it test if the user, cluster and context of the kubeconfig file are in the given file func testIfKubeconfigInFile(t *testing.T, filePath string, suffix string, kubeconfig api.Config) { + t.Helper() kubeconfigBytes, err := os.ReadFile(filePath) assert.Nil(t, err) var existingKubeconfig api.Config @@ -147,6 +148,7 @@ func Test_InstallKubeconfig(t *testing.T) { Check: core.TestCheckCombine( // no golden tests since it's os specific func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() testIfKubeconfigInFile(t, path.Join(os.TempDir(), "cli-test"), "-"+ctx.Meta["Cluster"].(*k8sSDK.Cluster).ID, ctx.Meta["Kubeconfig"].(api.Config)) }, core.TestCheckExitCode(0), @@ -164,6 +166,7 @@ func Test_InstallKubeconfig(t *testing.T) { Check: core.TestCheckCombine( // no golden tests since it's os specific func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() testIfKubeconfigInFile(t, path.Join(os.TempDir(), "cli-merge-test"), "-"+ctx.Meta["Cluster"].(*k8sSDK.Cluster).ID, ctx.Meta["Kubeconfig"].(api.Config)) testIfKubeconfigInFile(t, path.Join(os.TempDir(), "cli-merge-test"), "", testKubeconfig) }, diff --git a/internal/namespaces/k8s/v1/custom_kubeconfig_uninstall_test.go b/internal/namespaces/k8s/v1/custom_kubeconfig_uninstall_test.go index 5ff948b5d9..3ddf59ef3d 100644 --- a/internal/namespaces/k8s/v1/custom_kubeconfig_uninstall_test.go +++ b/internal/namespaces/k8s/v1/custom_kubeconfig_uninstall_test.go @@ -16,6 +16,7 @@ import ( // testIfKubeconfigNotInFile checks if the given kubeconfig is not in the given file // it tests if the user, cluster and context of the kubeconfig file are not in the given file func testIfKubeconfigNotInFile(t *testing.T, filePath string, suffix string, kubeconfig api.Config) { + t.Helper() kubeconfigBytes, err := os.ReadFile(filePath) assert.Nil(t, err) var existingKubeconfig k8sSDK.Kubeconfig @@ -61,6 +62,7 @@ func Test_UninstallKubeconfig(t *testing.T) { Check: core.TestCheckCombine( // no golden tests since it's os specific func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() testIfKubeconfigNotInFile(t, path.Join(os.TempDir(), "cli-uninstall-test"), "-"+ctx.Meta["Cluster"].(*k8sSDK.Cluster).ID, ctx.Meta["Kubeconfig"].(api.Config)) }, core.TestCheckExitCode(0), @@ -77,6 +79,7 @@ func Test_UninstallKubeconfig(t *testing.T) { Check: core.TestCheckCombine( // no golden tests since it's os specific func(t *testing.T, _ *core.CheckFuncCtx) { + t.Helper() _, err := os.Stat(path.Join(os.TempDir(), "emptyfile")) assert.True(t, os.IsNotExist(err)) }, @@ -94,6 +97,7 @@ func Test_UninstallKubeconfig(t *testing.T) { Check: core.TestCheckCombine( // no golden tests since it's os specific func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() testIfKubeconfigNotInFile(t, path.Join(os.TempDir(), "cli-uninstall-merge-test"), "-"+ctx.Meta["Cluster"].(*k8sSDK.Cluster).ID, ctx.Meta["Kubeconfig"].(api.Config)) testIfKubeconfigInFile(t, path.Join(os.TempDir(), "cli-uninstall-merge-test"), "", testKubeconfig) }, diff --git a/internal/namespaces/mnq/v1beta1/custom_nats_test.go b/internal/namespaces/mnq/v1beta1/custom_nats_test.go index 4d00a9edce..ece6dd69bd 100644 --- a/internal/namespaces/mnq/v1beta1/custom_nats_test.go +++ b/internal/namespaces/mnq/v1beta1/custom_nats_test.go @@ -30,6 +30,7 @@ func Test_CreateContext(t *testing.T) { }, ), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() result, isSuccessResult := ctx.Result.(*core.SuccessResult) assert.True(t, isSuccessResult, "Expected result to be of type *core.SuccessResult, got %s", reflect.TypeOf(result).String()) assert.NotNil(t, result) diff --git a/internal/namespaces/object/v1/custom_bucket_test.go b/internal/namespaces/object/v1/custom_bucket_test.go index d312fdf4bb..c5e1d1a5aa 100644 --- a/internal/namespaces/object/v1/custom_bucket_test.go +++ b/internal/namespaces/object/v1/custom_bucket_test.go @@ -28,6 +28,7 @@ func Test_BucketCreate(t *testing.T) { Cmd: "scw object bucket create " + bucketName1, Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() bucket := ctx.Result.(*object.BucketResponse).BucketInfo assert.Equal(t, bucketName1, bucket.ID) assert.Equal(t, false, bucket.EnableVersioning) @@ -49,6 +50,7 @@ func Test_BucketCreate(t *testing.T) { core.TestCheckS3Golden(), core.TestCheckExitCode(0), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() bucket := ctx.Result.(*object.BucketResponse).BucketInfo assert.Equal(t, bucketName2, bucket.ID) assert.Equal(t, false, bucket.EnableVersioning) @@ -77,6 +79,7 @@ func Test_BucketCreate(t *testing.T) { core.TestCheckS3Golden(), core.TestCheckExitCode(0), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() bucket := ctx.Result.(*object.BucketResponse).BucketInfo assert.Equal(t, bucketName3, bucket.ID) assert.Equal(t, true, bucket.EnableVersioning) @@ -96,6 +99,7 @@ func Test_BucketCreate(t *testing.T) { core.TestCheckS3Golden(), core.TestCheckExitCode(0), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() bucket := ctx.Result.(*object.BucketResponse).BucketInfo assert.Equal(t, bucketName4, bucket.ID) assert.Equal(t, false, bucket.EnableVersioning) @@ -132,6 +136,7 @@ func Test_BucketGet(t *testing.T) { core.TestCheckS3Golden(), core.TestCheckExitCode(0), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() bucket := ctx.Result.(object.BucketGetResult) assert.Equal(t, bucketName1, bucket.ID) assert.Equal(t, false, bucket.EnableVersioning) @@ -152,6 +157,7 @@ func Test_BucketGet(t *testing.T) { core.TestCheckS3Golden(), core.TestCheckExitCode(0), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() bucket := ctx.Result.(object.BucketGetResult) assert.Equal(t, bucketName2, bucket.ID) assert.Equal(t, false, bucket.EnableVersioning) @@ -199,6 +205,7 @@ func Test_BucketUpdate(t *testing.T) { core.TestCheckS3Golden(), core.TestCheckExitCode(0), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() bucket := ctx.Result.(*object.BucketResponse).BucketInfo assert.Equal(t, bucketName1, bucket.ID) assert.Equal(t, false, bucket.EnableVersioning) @@ -224,6 +231,7 @@ func Test_BucketUpdate(t *testing.T) { core.TestCheckS3Golden(), core.TestCheckExitCode(0), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() bucket := ctx.Result.(*object.BucketResponse).BucketInfo assert.Equal(t, bucketName2, bucket.ID) assert.Equal(t, true, bucket.EnableVersioning) @@ -261,6 +269,7 @@ func deleteBucket(name string) core.AfterFunc { } func checkACL(t *testing.T, expected string, actual []object.CustomS3ACLGrant, owner string) { + t.Helper() grantsMap := make(map[types.Permission]string) for _, actualACL := range actual { if actualACL.Grantee == nil { diff --git a/internal/namespaces/object/v1/custom_config_install_test.go b/internal/namespaces/object/v1/custom_config_install_test.go index 5060100ec4..f6f6e407fc 100644 --- a/internal/namespaces/object/v1/custom_config_install_test.go +++ b/internal/namespaces/object/v1/custom_config_install_test.go @@ -29,6 +29,7 @@ func Test_ConfigInstall(t *testing.T) { Cmd: "scw object config install type=rclone", Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() filePath := path.Join(ctx.OverrideEnv["HOME"], ".config", "rclone", "rclone.conf") assert.FileExists(t, filePath) }, @@ -43,6 +44,7 @@ func Test_ConfigInstall(t *testing.T) { Cmd: "scw object config install type=mc", Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() filePath := path.Join(ctx.OverrideEnv["HOME"], ".mc", "config.json") assert.FileExists(t, filePath) }, @@ -57,6 +59,7 @@ func Test_ConfigInstall(t *testing.T) { Cmd: "scw object config install type=s3cmd", Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() filePath := path.Join(ctx.OverrideEnv["HOME"], ".s3cfg") assert.FileExists(t, filePath) }, diff --git a/internal/namespaces/rdb/v1/custom_acl_test.go b/internal/namespaces/rdb/v1/custom_acl_test.go index 186c345b53..7d5c0c3680 100644 --- a/internal/namespaces/rdb/v1/custom_acl_test.go +++ b/internal/namespaces/rdb/v1/custom_acl_test.go @@ -16,7 +16,8 @@ func Test_AddACL(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { - verifyACL(ctx, t, []string{"0.0.0.0/0", "1.2.3.4/32"}) + t.Helper() + verifyACL(t, ctx, []string{"0.0.0.0/0", "1.2.3.4/32"}) }, ), AfterFunc: deleteInstance(), @@ -29,7 +30,8 @@ func Test_AddACL(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { - verifyACL(ctx, t, []string{"0.0.0.0/0", "1.2.3.4/32"}) + t.Helper() + verifyACL(t, ctx, []string{"0.0.0.0/0", "1.2.3.4/32"}) }, ), AfterFunc: deleteInstance(), @@ -42,7 +44,8 @@ func Test_AddACL(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { - verifyACL(ctx, t, []string{"0.0.0.0/0", "1.2.3.4/32", "192.168.1.0/30", "10.10.10.10/32"}) + t.Helper() + verifyACL(t, ctx, []string{"0.0.0.0/0", "1.2.3.4/32", "192.168.1.0/30", "10.10.10.10/32"}) }, ), AfterFunc: deleteInstance(), @@ -55,7 +58,8 @@ func Test_AddACL(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { - verifyACL(ctx, t, []string{"0.0.0.0/0", "1.2.3.4/32", "192.168.1.0/30", "10.10.10.10/32"}) + t.Helper() + verifyACL(t, ctx, []string{"0.0.0.0/0", "1.2.3.4/32", "192.168.1.0/30", "10.10.10.10/32"}) }, ), AfterFunc: deleteInstance(), @@ -70,7 +74,8 @@ func Test_DeleteACL(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { - verifyACL(ctx, t, []string{}) + t.Helper() + verifyACL(t, ctx, []string{}) }, ), AfterFunc: deleteInstance(), @@ -86,7 +91,8 @@ func Test_DeleteACL(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { - verifyACL(ctx, t, []string{"0.0.0.0/0"}) + t.Helper() + verifyACL(t, ctx, []string{"0.0.0.0/0"}) }, ), AfterFunc: deleteInstance(), @@ -102,7 +108,8 @@ func Test_DeleteACL(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { - verifyACL(ctx, t, []string{"0.0.0.0/0"}) + t.Helper() + verifyACL(t, ctx, []string{"0.0.0.0/0"}) }, ), AfterFunc: deleteInstance(), @@ -117,7 +124,8 @@ func Test_SetACL(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { - verifyACL(ctx, t, []string{"1.2.3.4/32"}) + t.Helper() + verifyACL(t, ctx, []string{"1.2.3.4/32"}) acls := ctx.Result.(*rdb.CustomACLResult).Rules assert.Equal(t, "something", acls[0].Description) }, @@ -135,7 +143,8 @@ func Test_SetACL(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { - verifyACL(ctx, t, []string{"1.2.3.4/32", "192.168.1.0/31", "11.11.11.11/32"}) + t.Helper() + verifyACL(t, ctx, []string{"1.2.3.4/32", "192.168.1.0/31", "11.11.11.11/32"}) acls := ctx.Result.(*rdb.CustomACLResult).Rules for _, acl := range acls { switch acl.IP.String() { @@ -153,7 +162,8 @@ func Test_SetACL(t *testing.T) { })) } -func verifyACLCustomResponse(res *rdb.CustomACLResult, t *testing.T, expectedRules []string) { +func verifyACLCustomResponse(t *testing.T, res *rdb.CustomACLResult, expectedRules []string) { + t.Helper() actualRules := res.Rules rulesFound := map[string]bool{} @@ -177,12 +187,13 @@ func verifyACLCustomResponse(res *rdb.CustomACLResult, t *testing.T, expectedRul } } -func verifyACL(ctx *core.CheckFuncCtx, t *testing.T, expectedRules []string) { +func verifyACL(t *testing.T, ctx *core.CheckFuncCtx, expectedRules []string) { + t.Helper() switch res := ctx.Result.(type) { case *rdb.CustomACLResult: - verifyACLCustomResponse(res, t, expectedRules) + verifyACLCustomResponse(t, res, expectedRules) case core.MultiResults: - verifyACLCustomResponse(res[len(res)-1].(*rdb.CustomACLResult), t, expectedRules) + verifyACLCustomResponse(t, res[len(res)-1].(*rdb.CustomACLResult), expectedRules) default: t.Errorf("action is undefined for this type") } diff --git a/internal/namespaces/rdb/v1/custom_endpoint_test.go b/internal/namespaces/rdb/v1/custom_endpoint_test.go index 894d15851c..b47b7dc8db 100644 --- a/internal/namespaces/rdb/v1/custom_endpoint_test.go +++ b/internal/namespaces/rdb/v1/custom_endpoint_test.go @@ -25,6 +25,7 @@ func Test_EndpointCreate(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() instance := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance checkEndpoints(t, ctx.Client, instance, []string{privateEndpointStatic, publicEndpoint}) }, @@ -42,6 +43,7 @@ func Test_EndpointCreate(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() instance := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance checkEndpoints(t, ctx.Client, instance, []string{privateEndpointStatic, publicEndpoint}) }, @@ -62,6 +64,7 @@ func Test_EndpointCreate(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() instance := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance checkEndpoints(t, ctx.Client, instance, []string{privateEndpointIpam, publicEndpoint}) }, @@ -88,6 +91,7 @@ func Test_EndpointDelete(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() instance := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance checkEndpoints(t, ctx.Client, instance, []string{privateEndpointStatic}) }, @@ -109,6 +113,7 @@ func Test_EndpointDelete(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() instance := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance checkEndpoints(t, ctx.Client, instance, []string{publicEndpoint}) }, @@ -129,6 +134,7 @@ func Test_EndpointDelete(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() instance := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance checkEndpoints(t, ctx.Client, instance, []string{}) }, @@ -154,6 +160,7 @@ func Test_EndpointGet(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() instance := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance checkEndpoints(t, ctx.Client, instance, []string{publicEndpoint, privateEndpointStatic}) }, @@ -175,6 +182,7 @@ func Test_EndpointGet(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() instance := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance checkEndpoints(t, ctx.Client, instance, []string{publicEndpoint, privateEndpointStatic}) }, @@ -206,6 +214,7 @@ func Test_EndpointList(t *testing.T) { } func checkEndpoints(t *testing.T, client *scw.Client, instance *rdbSDK.Instance, expected []string) { + t.Helper() rdbAPI := rdbSDK.NewAPI(client) ipamAPI := ipam.NewAPI(client) foundEndpoints := map[string]bool{} diff --git a/internal/namespaces/rdb/v1/custom_instance_test.go b/internal/namespaces/rdb/v1/custom_instance_test.go index c21585aaf9..82009e0f3d 100644 --- a/internal/namespaces/rdb/v1/custom_instance_test.go +++ b/internal/namespaces/rdb/v1/custom_instance_test.go @@ -49,6 +49,7 @@ func Test_CreateInstance(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() instance := ctx.Result.(rdb.CreateInstanceResult).Instance checkEndpoints(t, ctx.Client, instance, []string{publicEndpoint}) }, @@ -63,6 +64,7 @@ func Test_CreateInstance(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckExitCode(0), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() instance := ctx.Result.(rdb.CreateInstanceResult).Instance checkEndpoints(t, ctx.Client, instance, []string{publicEndpoint}) }, @@ -82,6 +84,7 @@ func Test_CreateInstanceInitEndpoints(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() instance := ctx.Result.(rdb.CreateInstanceResult).Instance checkEndpoints(t, ctx.Client, instance, []string{privateEndpointStatic}) }, @@ -99,6 +102,7 @@ func Test_CreateInstanceInitEndpoints(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() instance := ctx.Result.(rdb.CreateInstanceResult).Instance checkEndpoints(t, ctx.Client, instance, []string{publicEndpoint, privateEndpointStatic}) }, @@ -116,6 +120,7 @@ func Test_CreateInstanceInitEndpoints(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() instance := ctx.Result.(rdb.CreateInstanceResult).Instance checkEndpoints(t, ctx.Client, instance, []string{privateEndpointIpam}) }, @@ -133,6 +138,7 @@ func Test_CreateInstanceInitEndpoints(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() instance := ctx.Result.(rdb.CreateInstanceResult).Instance checkEndpoints(t, ctx.Client, instance, []string{publicEndpoint, privateEndpointIpam}) }, @@ -171,6 +177,7 @@ func Test_UpdateInstance(t *testing.T) { Cmd: "scw rdb instance update {{ .Instance.ID }} name=foo --wait", Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.Equal(t, "foo", ctx.Result.(*rdbSDK.Instance).Name) }, core.TestCheckGolden(), @@ -185,6 +192,7 @@ func Test_UpdateInstance(t *testing.T) { Cmd: "scw rdb instance update {{ .Instance.ID }} tags.0=a --wait", Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.Equal(t, "a", ctx.Result.(*rdbSDK.Instance).Tags[0]) }, core.TestCheckGolden(), @@ -199,6 +207,7 @@ func Test_UpdateInstance(t *testing.T) { Cmd: "scw rdb instance update {{ .Instance.ID }} settings.0.name=timezone settings.0.value=UTC --wait", Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.Equal(t, "timezone", ctx.Result.(*rdbSDK.Instance).Settings[5].Name) assert.Equal(t, "UTC", ctx.Result.(*rdbSDK.Instance).Settings[5].Value) }, @@ -214,6 +223,7 @@ func Test_UpdateInstance(t *testing.T) { Cmd: "scw rdb instance update {{ .Instance.ID }} settings.0.name=work_mem settings.0.value=8 --wait", Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.Equal(t, "work_mem", ctx.Result.(*rdbSDK.Instance).Settings[5].Name) assert.Equal(t, "8", ctx.Result.(*rdbSDK.Instance).Settings[5].Value) }, @@ -239,6 +249,7 @@ func Test_UpdateInstance(t *testing.T) { " name=foo2 --wait", Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.Equal(t, "effective_cache_size", ctx.Result.(*rdbSDK.Instance).Settings[0].Name) assert.Equal(t, "1200", ctx.Result.(*rdbSDK.Instance).Settings[0].Value) assert.Equal(t, "maintenance_work_mem", ctx.Result.(*rdbSDK.Instance).Settings[1].Name) diff --git a/internal/namespaces/rdb/v1/custom_url_test.go b/internal/namespaces/rdb/v1/custom_url_test.go index c28c4dcbdd..5c2dbf7ddb 100644 --- a/internal/namespaces/rdb/v1/custom_url_test.go +++ b/internal/namespaces/rdb/v1/custom_url_test.go @@ -21,6 +21,7 @@ func Test_UserGetURL(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() ip := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance.Endpoints[0].IP port := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance.Endpoints[0].Port expected := fmt.Sprintf("postgresql://%s@%s", user, net.JoinHostPort(ip.String(), strconv.Itoa(int(port)))) @@ -39,6 +40,7 @@ func Test_UserGetURL(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() ip := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance.Endpoints[0].IP port := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance.Endpoints[0].Port expected := fmt.Sprintf("mysql://%s@%s", user, net.JoinHostPort(ip.String(), strconv.Itoa(int(port)))) @@ -62,6 +64,7 @@ func Test_UserGetURL(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() ip := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance.Endpoints[0].IP port := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance.Endpoints[0].Port expected := fmt.Sprintf("postgresql://%s@%s", customUserName, net.JoinHostPort(ip.String(), strconv.Itoa(int(port)))) @@ -81,6 +84,7 @@ func Test_UserGetURL(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() ip := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance.Endpoints[0].IP port := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance.Endpoints[0].Port expected := fmt.Sprintf("postgresql://%s@%s/%s", user, net.JoinHostPort(ip.String(), strconv.Itoa(int(port))), customDBName) @@ -101,6 +105,7 @@ func Test_DatabaseGetURL(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() ip := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance.Endpoints[0].IP port := ctx.Meta["Instance"].(rdb.CreateInstanceResult).Instance.Endpoints[0].Port expected := fmt.Sprintf("postgresql://%s@%s", user, net.JoinHostPort(ip.String(), strconv.Itoa(int(port)))) diff --git a/internal/namespaces/redis/v1/custom_cluster_test.go b/internal/namespaces/redis/v1/custom_cluster_test.go index 82f5ba2b3b..2c40e1ce6a 100644 --- a/internal/namespaces/redis/v1/custom_cluster_test.go +++ b/internal/namespaces/redis/v1/custom_cluster_test.go @@ -37,6 +37,7 @@ func Test_Endpoints(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() endpoints := ctx.Result.(*redisSDK.Cluster).Endpoints checkEndpoints(t, endpoints, 1, 0, 0) }, @@ -60,6 +61,7 @@ func Test_Endpoints(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() endpoints := ctx.Result.(*redisSDK.Cluster).Endpoints checkEndpoints(t, endpoints, 0, 1, 0) }, @@ -89,6 +91,7 @@ func Test_Endpoints(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() endpoints := ctx.Result.(*redisSDK.Cluster).Endpoints checkEndpoints(t, endpoints, 0, 2, 0) }, @@ -122,6 +125,7 @@ func Test_IpamConfig(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() endpoints := ctx.Result.(*redisSDK.Cluster).Endpoints checkEndpoints(t, endpoints, 0, 0, 1) }, @@ -151,6 +155,7 @@ func Test_IpamConfig(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() endpoints := ctx.Result.(*redisSDK.Cluster).Endpoints checkEndpoints(t, endpoints, 0, 0, 2) }, @@ -181,6 +186,7 @@ func Test_IpamConfig(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() endpoints := ctx.Result.(*redisSDK.Cluster).Endpoints checkEndpoints(t, endpoints, 0, 1, 1) }, @@ -217,6 +223,7 @@ func Test_EndpointsEdgeCases(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckExitCode(1), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.Contains(t, ctx.Err.Error(), expectedError) }, ), @@ -242,6 +249,7 @@ func Test_EndpointsEdgeCases(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckExitCode(1), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() assert.Contains(t, ctx.Err.Error(), expectedError) }, ), @@ -260,6 +268,7 @@ func deletePrivateNetwork(metaName string) core.AfterFunc { } func checkEndpoints(t *testing.T, endpoints []*redisSDK.Endpoint, nbExpectedPub, nbExpectedPrivStatic, nbExpectedPrivIpam int) { + t.Helper() expectedEndpoints := map[string]int{ "public": nbExpectedPub, "private-static": nbExpectedPrivStatic, diff --git a/internal/namespaces/registry/v1/custom_docker_helper_test.go b/internal/namespaces/registry/v1/custom_docker_helper_test.go index 5de04f8c5e..6ba503e97d 100644 --- a/internal/namespaces/registry/v1/custom_docker_helper_test.go +++ b/internal/namespaces/registry/v1/custom_docker_helper_test.go @@ -23,6 +23,7 @@ func TestRegistryInstallDockerHelperCommand(t *testing.T) { Commands: registry.GetCommands(), Cmd: "scw registry install-docker-helper path={{ .HOME }}", Check: func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() scriptPath := path.Join(ctx.Meta["HOME"].(string), "docker-credential-scw") scriptContent, err := os.ReadFile(scriptPath) require.NoError(t, err) @@ -49,6 +50,7 @@ func TestRegistryInstallDockerHelperCommand(t *testing.T) { Commands: registry.GetCommands(), Cmd: "scw -p profile01 registry install-docker-helper path={{ .HOME }}", Check: func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() scriptPath := path.Join(ctx.Meta["HOME"].(string), "docker-credential-scw") scriptContent, err := os.ReadFile(scriptPath) require.NoError(t, err) diff --git a/internal/namespaces/secret/v1beta1/custom_secret_version_test.go b/internal/namespaces/secret/v1beta1/custom_secret_version_test.go index 71d8c6e556..815137f56f 100644 --- a/internal/namespaces/secret/v1beta1/custom_secret_version_test.go +++ b/internal/namespaces/secret/v1beta1/custom_secret_version_test.go @@ -21,6 +21,7 @@ func Test_AccessSecret(t *testing.T) { Check: core.TestCheckCombine( core.TestCheckGolden(), func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() rawResult, isBytes := ctx.Result.(core.RawResult) if !isBytes { t.Fatalf("Expecting result to be bytes") diff --git a/internal/tabwriter/tabwriter_test.go b/internal/tabwriter/tabwriter_test.go index 8124603f90..fc4e527814 100644 --- a/internal/tabwriter/tabwriter_test.go +++ b/internal/tabwriter/tabwriter_test.go @@ -39,6 +39,7 @@ func (b *buffer) Write(buf []byte) (written int, err error) { func (b *buffer) String() string { return string(b.a) } func write(t *testing.T, testname string, w *tabwriter.Writer, src string) { + t.Helper() written, err := io.WriteString(w, src) if err != nil { t.Errorf("--- test: %s\n--- src:\n%q\n--- write error: %v\n", testname, src, err) @@ -49,6 +50,7 @@ func write(t *testing.T, testname string, w *tabwriter.Writer, src string) { } func verify(t *testing.T, testname string, w *tabwriter.Writer, b *buffer, src, expected string) { + t.Helper() err := w.Flush() if err != nil { t.Errorf("--- test: %s\n--- src:\n%q\n--- flush error: %v\n", testname, src, err) @@ -61,6 +63,7 @@ func verify(t *testing.T, testname string, w *tabwriter.Writer, b *buffer, src, } func check(t *testing.T, testname string, minwidth, tabwidth, padding int, padchar byte, flags uint, src, expected string) { + t.Helper() var b buffer b.init(1000) @@ -657,6 +660,7 @@ func (panicWriter) Write([]byte) (int, error) { } func wantPanicString(t *testing.T, want string) { + t.Helper() if e := recover(); e != nil { got, ok := e.(string) switch {