Skip to content

Commit

Permalink
Fix linter
Browse files Browse the repository at this point in the history
  • Loading branch information
remyleone committed Feb 24, 2025
1 parent bc8d7b7 commit 220526c
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 19 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ linters:
- staticcheck
- stylecheck # Stylecheck is a replacement for golint [fast: false, auto-fix: false]
- tagalign # check that struct tags are well aligned [fast: true, auto-fix: true]
- 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]
Expand Down
8 changes: 4 additions & 4 deletions core/autocomplete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func runAutocompleteTest(ctx context.Context, tc *autoCompleteTestCase) func(*te
}

func TestAutocomplete(t *testing.T) {
ctx := core.InjectMeta(context.Background(), &core.Meta{
ctx := core.InjectMeta(t.Context(), &core.Meta{
Commands: testAutocompleteGetCommands(),
})

Expand Down Expand Up @@ -253,7 +253,7 @@ func TestAutocompleteArgs(t *testing.T) {
}, nil
},
})
ctx := core.InjectMeta(context.Background(), &core.Meta{
ctx := core.InjectMeta(t.Context(), &core.Meta{
Commands: commands,
BetaMode: true,
})
Expand All @@ -272,7 +272,7 @@ func TestAutocompleteArgs(t *testing.T) {

func TestAutocompleteProfiles(t *testing.T) {
commands := testAutocompleteGetCommands()
ctx := core.InjectMeta(context.Background(), &core.Meta{
ctx := core.InjectMeta(t.Context(), &core.Meta{
Commands: commands,
BetaMode: true,
Platform: terminal.NewPlatform(""),
Expand Down Expand Up @@ -300,7 +300,7 @@ func TestAutocompleteProfiles(t *testing.T) {
}

func TestAutocompleteDeprecatedCommand(t *testing.T) {
ctx := core.InjectMeta(context.Background(), &core.Meta{
ctx := core.InjectMeta(t.Context(), &core.Meta{
Commands: testAutocompleteGetCommands(),
})

Expand Down
3 changes: 1 addition & 2 deletions core/cobra_usage_builder_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package core_test

import (
"context"
"reflect"
"testing"

Expand Down Expand Up @@ -41,7 +40,7 @@ func Test_buildUsageArgs(t *testing.T) {
[root-volume.name] Root volume name
[additional-volumes.{index}.name] Additional volume name`

got := core.BuildUsageArgs(context.Background(), &core.Command{
got := core.BuildUsageArgs(t.Context(), &core.Command{
ArgsType: reflect.TypeOf(instanceListServerArgs{}),
ArgSpecs: core.ArgSpecs{
{
Expand Down
3 changes: 1 addition & 2 deletions core/default_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package core_test

import (
"context"
"testing"

"github.com/scaleway/scaleway-cli/v2/core"
Expand All @@ -19,7 +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)
result := core.ApplyDefaultValues(t.Context(), tc.argSpecs, tc.rawArgs)
assert.Equal(t, tc.expected, result)
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func Test(config *TestConfig) func(t *testing.T) {

ctx := config.Ctx
if ctx == nil {
ctx = context.Background()
ctx = t.Context()
}
if len(config.PromptResponseMocks) > 0 {
ctx = interactive.InjectMockResponseToContext(ctx, config.PromptResponseMocks)
Expand Down
6 changes: 3 additions & 3 deletions core/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +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)
err := core.DefaultCommandValidateFunc()(t.Context(), testCase.command, testCase.parsedArguments, testCase.rawArgs)
assert.Equal(t, errors.New("arg validation called"), err)
}
}
Expand Down Expand Up @@ -198,15 +198,15 @@ 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)
err := core.DefaultCommandValidateFunc()(t.Context(), testCase.command, testCase.parsedArguments, testCase.rawArgs)
assert.NoError(t, err)
}
}

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)
err := core.DefaultCommandValidateFunc()(t.Context(), testCase.command, testCase.parsedArguments, testCase.rawArgs)
assert.Equal(t, core.MissingRequiredArgumentError(argName), err)
}
}
Expand Down
3 changes: 1 addition & 2 deletions internal/interactive/prompt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package interactive_test

import (
"bytes"
"context"
"testing"

"github.com/scaleway/scaleway-cli/v2/internal/interactive"
Expand All @@ -18,7 +17,7 @@ func TestPromptStringWithConfig(t *testing.T) {

interactive.SetOutputWriter(buffer)

ctx := context.Background()
ctx := t.Context()
ctx = interactive.InjectMockResponseToContext(ctx, []string{"mock1", "mock2"})

s, err := interactive.PromptStringWithConfig(&interactive.PromptStringConfig{
Expand Down
2 changes: 1 addition & 1 deletion internal/namespaces/login/webcallback/webcallback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestWebCallback(t *testing.T) {
assert.NoError(t, wb.Start())
assert.NoError(t, wb.Trigger("test-token", time.Second))

ctx, cancelFunc := context.WithTimeout(context.Background(), time.Second)
ctx, cancelFunc := context.WithTimeout(t.Context(), time.Second)
t.Cleanup(cancelFunc)

resp, err := wb.Wait(ctx)
Expand Down
6 changes: 3 additions & 3 deletions internal/tasks/tasks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestGeneric(t *testing.T) {
return int(i) / 4, nil
})

res, err := ts.Execute(context.Background(), 12)
res, err := ts.Execute(t.Context(), 12)
require.NoError(t, err)
assert.Equal(t, 3, res)
}
Expand Down Expand Up @@ -86,7 +86,7 @@ func TestCleanup(t *testing.T) {
return nil, errors.New("fail")
})

_, err := ts.Execute(context.Background(), nil)
_, err := ts.Execute(t.Context(), nil)
require.Error(t, err, "Execute should return error after cleanup")
assert.Equal(t, 3, clean, "3 task cleanup should have been executed")
}
Expand All @@ -98,7 +98,7 @@ func TestCleanupOnContext(t *testing.T) {
ts := tasks.Begin()

clean := 0
ctx := context.Background()
ctx := t.Context()

tasks.Add(ts, "TaskFunc 1", func(task *tasks.Task, _ interface{}) (nextArgs interface{}, err error) {
task.AddToCleanUp(func(_ context.Context) error {
Expand Down

0 comments on commit 220526c

Please sign in to comment.