Skip to content

Commit 7f06641

Browse files
authored
chore: migrate test to their own package (testpackage linter) (#3709)
1 parent 230b1ef commit 7f06641

File tree

145 files changed

+1503
-1305
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+1503
-1305
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ linters:
3636
- staticcheck
3737
- stylecheck
3838
- tenv
39+
- testpackage
3940
- typecheck
4041
- unconvert
4142
- unparam

internal/alias/config_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
package alias
1+
package alias_test
22

33
import (
44
"fmt"
55
"testing"
66

7+
"github.com/scaleway/scaleway-cli/v2/internal/alias"
8+
79
"github.com/alecthomas/assert"
810
)
911

@@ -37,7 +39,7 @@ func TestConfig_ResolveAliases(t *testing.T) {
3739
}
3840
for i, tt := range tests {
3941
t.Run(fmt.Sprintf("Resolve_TestCase%d", i), func(t *testing.T) {
40-
config := &Config{Aliases: tt.Aliases}
42+
config := &alias.Config{Aliases: tt.Aliases}
4143
actual := config.ResolveAliases(tt.Command)
4244
assert.Equal(t, tt.Expected, actual)
4345
})

internal/args/args_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package args
1+
package args_test
22

33
import (
44
"fmt"
@@ -7,6 +7,8 @@ import (
77
"testing"
88
"time"
99

10+
"github.com/scaleway/scaleway-cli/v2/internal/args"
11+
1012
"github.com/alecthomas/assert"
1113
"github.com/scaleway/scaleway-sdk-go/scw"
1214
"github.com/stretchr/testify/require"
@@ -144,12 +146,12 @@ type SamePrefixArgName struct {
144146

145147
func TestRawArgs_GetAll(t *testing.T) {
146148
t.Run("Simple", func(t *testing.T) {
147-
a := RawArgs{"ssh-keys.0=foo", "ssh-keys.1=bar"}
149+
a := args.RawArgs{"ssh-keys.0=foo", "ssh-keys.1=bar"}
148150
assert.Equal(t, a.GetAll("ssh-keys.{index}"), []string{"foo", "bar"})
149151
})
150152

151153
t.Run("Insane", func(t *testing.T) {
152-
a := RawArgs{
154+
a := args.RawArgs{
153155
"countries.FR.cities.paris.street.vaugirard=pouet",
154156
"countries.FR.cities.paris.street.besbar=tati",
155157
"countries.FR.cities.nice.street.promenade=anglais",
@@ -169,7 +171,7 @@ func TestGetArgType(t *testing.T) {
169171

170172
run := func(tc *TestCase) func(*testing.T) {
171173
return func(t *testing.T) {
172-
res, err := GetArgType(tc.ArgType, tc.Name)
174+
res, err := args.GetArgType(tc.ArgType, tc.Name)
173175
if tc.expectedError == "" {
174176
require.NoError(t, err)
175177
assert.Equal(t, tc.ExpectedKind, res.Kind())

internal/args/marshal_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
package args
1+
package args_test
22

33
import (
44
"testing"
55
"time"
66

7+
"github.com/scaleway/scaleway-cli/v2/internal/args"
8+
79
"github.com/scaleway/scaleway-sdk-go/scw"
810
"github.com/stretchr/testify/assert"
911
)
@@ -20,7 +22,7 @@ func TestMarshal(t *testing.T) {
2022

2123
run := func(testCase TestCase) func(t *testing.T) {
2224
return func(t *testing.T) {
23-
args, err := MarshalStruct(testCase.data)
25+
args, err := args.MarshalStruct(testCase.data)
2426

2527
if testCase.error == "" {
2628
assert.NoError(t, err)
@@ -31,7 +33,7 @@ func TestMarshal(t *testing.T) {
3133
}
3234
}
3335

34-
RegisterMarshalFunc((*height)(nil), marshalHeight)
36+
args.RegisterMarshalFunc((*height)(nil), marshalHeight)
3537

3638
t.Run("basic", run(TestCase{
3739
data: &Basic{
@@ -198,7 +200,7 @@ func TestMarshal(t *testing.T) {
198200
}))
199201

200202
t.Run("data-is-raw-args", run(TestCase{
201-
data: &RawArgs{
203+
data: &args.RawArgs{
202204
"pro.access_key",
203205
"access_key",
204206
},
@@ -233,7 +235,7 @@ func TestMarshalValue(t *testing.T) {
233235

234236
run := func(testCase TestCase) func(t *testing.T) {
235237
return func(t *testing.T) {
236-
value, err := MarshalValue(testCase.data)
238+
value, err := args.MarshalValue(testCase.data)
237239

238240
if testCase.error == "" {
239241
assert.NoError(t, err)
@@ -244,7 +246,7 @@ func TestMarshalValue(t *testing.T) {
244246
}
245247
}
246248

247-
RegisterMarshalFunc((*height)(nil), marshalHeight)
249+
args.RegisterMarshalFunc((*height)(nil), marshalHeight)
248250

249251
t.Run("string", run(TestCase{
250252
data: "a simple string",

internal/args/unmarshal_test.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
package args
1+
package args_test
22

33
import (
44
"net"
55
"reflect"
66
"testing"
77
"time"
88

9+
"github.com/scaleway/scaleway-cli/v2/internal/args"
10+
911
"github.com/scaleway/scaleway-sdk-go/scw"
1012
"github.com/stretchr/testify/assert"
1113
)
1214

1315
func init() {
14-
TestForceNow = scw.TimePtr(time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC))
16+
args.TestForceNow = scw.TimePtr(time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC))
1517
}
1618

1719
func TestUnmarshalStruct(t *testing.T) {
@@ -30,7 +32,7 @@ func TestUnmarshalStruct(t *testing.T) {
3032
if testCase.data == nil {
3133
testCase.data = reflect.New(reflect.TypeOf(testCase.expected).Elem()).Interface()
3234
}
33-
err := UnmarshalStruct(testCase.args, testCase.data)
35+
err := args.UnmarshalStruct(testCase.args, testCase.data)
3436

3537
if testCase.error == "" {
3638
assert.NoError(t, err)
@@ -41,7 +43,7 @@ func TestUnmarshalStruct(t *testing.T) {
4143
}
4244
}
4345

44-
RegisterUnmarshalFunc((*height)(nil), unmarshalHeight)
46+
args.RegisterUnmarshalFunc((*height)(nil), unmarshalHeight)
4547

4648
t.Run("basic", run(TestCase{
4749
args: []string{
@@ -362,7 +364,7 @@ func TestUnmarshalStruct(t *testing.T) {
362364
"pro.access_key",
363365
"access_key",
364366
},
365-
expected: &RawArgs{
367+
expected: &args.RawArgs{
366368
"pro.access_key",
367369
"access_key",
368370
},
@@ -537,12 +539,12 @@ func TestIsUmarshalableValue(t *testing.T) {
537539

538540
run := func(testCase TestCase) func(t *testing.T) {
539541
return func(t *testing.T) {
540-
value := IsUmarshalableValue(testCase.data)
542+
value := args.IsUmarshalableValue(testCase.data)
541543
assert.Equal(t, testCase.expected, value)
542544
}
543545
}
544546

545-
RegisterUnmarshalFunc((*height)(nil), unmarshalHeight)
547+
args.RegisterUnmarshalFunc((*height)(nil), unmarshalHeight)
546548

547549
strPtr := "This is a pointer"
548550
heightPtr := height(42)

internal/core/alias_test.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
1-
package core
1+
package core_test
22

33
import (
44
"testing"
55

6+
"github.com/scaleway/scaleway-cli/v2/internal/core"
7+
68
"github.com/alecthomas/assert"
79
"github.com/scaleway/scaleway-cli/v2/internal/alias"
810
)
911

1012
func TestCommandMatchAlias(t *testing.T) {
11-
commandWithArg := &Command{
13+
commandWithArg := &core.Command{
1214
Namespace: "first",
1315
Resource: "command",
14-
ArgSpecs: ArgSpecs{
16+
ArgSpecs: core.ArgSpecs{
1517
{
1618
Name: "arg",
1719
},
1820
},
1921
}
20-
commandWithoutArg := &Command{
22+
commandWithoutArg := &core.Command{
2123
Namespace: "second",
2224
Resource: "command",
23-
ArgSpecs: ArgSpecs{
25+
ArgSpecs: core.ArgSpecs{
2426
{
2527
Name: "other-arg",
2628
},
@@ -32,28 +34,28 @@ func TestCommandMatchAlias(t *testing.T) {
3234
Command: []string{"command"},
3335
}
3436

35-
assert.True(t, commandWithArg.matchAlias(testAlias))
36-
assert.True(t, commandWithoutArg.matchAlias(testAlias))
37+
assert.True(t, commandWithArg.MatchAlias(testAlias))
38+
assert.True(t, commandWithoutArg.MatchAlias(testAlias))
3739

3840
testAliasWithArg := alias.Alias{
3941
Name: "alias",
4042
Command: []string{"command", "arg=value"},
4143
}
4244

43-
assert.True(t, commandWithArg.matchAlias(testAliasWithArg))
44-
assert.False(t, commandWithoutArg.matchAlias(testAliasWithArg))
45+
assert.True(t, commandWithArg.MatchAlias(testAliasWithArg))
46+
assert.False(t, commandWithoutArg.MatchAlias(testAliasWithArg))
4547
}
4648

4749
func TestAliasChildCommand(t *testing.T) {
48-
namespace := &Command{
50+
namespace := &core.Command{
4951
Namespace: "namespace",
5052
}
51-
resource := &Command{
53+
resource := &core.Command{
5254
Namespace: "namespace",
5355
Resource: "first",
5456
}
5557

56-
commands := NewCommands(
58+
commands := core.NewCommands(
5759
namespace,
5860
resource,
5961
)
@@ -63,12 +65,12 @@ func TestAliasChildCommand(t *testing.T) {
6365
Command: []string{"namespace", "first"},
6466
}
6567

66-
assert.True(t, commands.aliasIsValidCommandChild(namespace, validAlias))
68+
assert.True(t, commands.AliasIsValidCommandChild(namespace, validAlias))
6769

6870
invalidAlias := alias.Alias{
6971
Name: "alias",
7072
Command: []string{"namespace", "random"},
7173
}
7274

73-
assert.False(t, commands.aliasIsValidCommandChild(namespace, invalidAlias))
75+
assert.False(t, commands.AliasIsValidCommandChild(namespace, invalidAlias))
7476
}

internal/core/arg_specs_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
1-
package core
1+
package core_test
22

33
import (
44
"testing"
55

6+
"github.com/scaleway/scaleway-cli/v2/internal/core"
7+
68
"github.com/alecthomas/assert"
79
)
810

911
func TestOneOf(t *testing.T) {
10-
a := &ArgSpec{
12+
a := &core.ArgSpec{
1113
Name: "Argument A",
1214
OneOfGroup: "ab group",
1315
}
14-
b := &ArgSpec{
16+
b := &core.ArgSpec{
1517
Name: "Argument B",
1618
OneOfGroup: "ab group",
1719
}
18-
c := &ArgSpec{
20+
c := &core.ArgSpec{
1921
Name: "Argument C",
2022
OneOfGroup: "",
2123
}
22-
d := &ArgSpec{
24+
d := &core.ArgSpec{
2325
Name: "Argument D",
2426
OneOfGroup: "",
2527
}
26-
e := &ArgSpec{
28+
e := &core.ArgSpec{
2729
Name: "Argument E",
2830
}
2931
assert.True(t, a.ConflictWith(b))

0 commit comments

Comments
 (0)