Skip to content

Commit 7f42af5

Browse files
authored
Merge branch 'scaleway:master' into master
2 parents 814a190 + 005752b commit 7f42af5

10 files changed

+435
-506
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/scaleway/scaleway-cli/v2
33
go 1.25.0
44

55
require (
6-
github.com/aws/aws-sdk-go-v2 v1.39.3
6+
github.com/aws/aws-sdk-go-v2 v1.39.4
77
github.com/aws/aws-sdk-go-v2/service/s3 v1.88.6
88
github.com/buildpacks/pack v0.38.2
99
github.com/c-bata/go-prompt v0.2.6

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ github.com/aphistic/sweet v0.2.0/go.mod h1:fWDlIh/isSE9n6EPsRmC0det+whmX6dJid3st
6161
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
6262
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
6363
github.com/aws/aws-sdk-go v1.20.6/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
64-
github.com/aws/aws-sdk-go-v2 v1.39.3 h1:h7xSsanJ4EQJXG5iuW4UqgP7qBopLpj84mpkNx3wPjM=
65-
github.com/aws/aws-sdk-go-v2 v1.39.3/go.mod h1:yWSxrnioGUZ4WVv9TgMrNUeLV3PFESn/v+6T/Su8gnM=
64+
github.com/aws/aws-sdk-go-v2 v1.39.4 h1:qTsQKcdQPHnfGYBBs+Btl8QwxJeoWcOcPcixK90mRhg=
65+
github.com/aws/aws-sdk-go-v2 v1.39.4/go.mod h1:yWSxrnioGUZ4WVv9TgMrNUeLV3PFESn/v+6T/Su8gnM=
6666
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.2 h1:t9yYsydLYNBk9cJ73rgPhPWqOh/52fcWDQB5b1JsKSY=
6767
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.2/go.mod h1:IusfVNTmiSN3t4rhxWFaBAqn+mcNdwKtPcV16eYdgko=
6868
github.com/aws/aws-sdk-go-v2/config v1.31.6 h1:a1t8fXY4GT4xjyJExz4knbuoxSCacB5hT/WgtfPyLjo=

internal/namespaces/iam/v1alpha1/custom_iam_test.go

Lines changed: 91 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -31,103 +31,101 @@ func Test_iamAPIKeyGet(t *testing.T) {
3131
create a member API Key from the organization owner (no impersonation).
3232
*/
3333

34-
userResulter := func(result any) any {
35-
users := result.([]*iamSdk.User)
36-
if users == nil {
37-
panic("users is nil")
38-
}
39-
if len(users) == 0 {
40-
panic("no user found")
41-
}
42-
43-
return users[0].ID
44-
}
45-
46-
apiKeyResulter := func(result any) any {
47-
apiKeys := result.([]*iamSdk.APIKey)
48-
if apiKeys == nil {
49-
panic("apiKeys is nil")
50-
}
51-
if len(apiKeys) == 0 {
52-
panic("no api key found")
53-
}
54-
55-
return apiKeys[0].AccessKey
56-
}
57-
58-
applicationResulter := func(result any) any {
59-
applications := result.([]*iamSdk.Application)
60-
if applications == nil {
61-
panic("applications is nil")
62-
}
63-
if len(applications) == 0 {
64-
panic("no application found")
65-
}
66-
67-
return applications[0].ID
68-
}
69-
70-
t.Run("GetOwnerAPIKey", core.Test(&core.TestConfig{
71-
Commands: commands,
72-
BeforeFunc: core.BeforeFuncCombine(
73-
core.ExecStoreBeforeCmdWithResulter(
74-
"owner",
75-
"scw iam user list type=owner",
76-
userResulter,
34+
t.Run("GetOwnerAPIKey", func(t *testing.T) {
35+
userResulter := newSliceResulter(t, "*iamSdk.User", func(users []*iamSdk.User) any {
36+
return users[0].ID
37+
})
38+
39+
apiKeyResulter := newSliceResulter(t, "*iamSdk.APIKey", func(keys []*iamSdk.APIKey) any {
40+
return keys[0].AccessKey
41+
})
42+
43+
core.Test(&core.TestConfig{
44+
Commands: commands,
45+
BeforeFunc: core.BeforeFuncCombine(
46+
core.ExecStoreBeforeCmdWithResulter(
47+
"owner",
48+
"scw iam user list type=owner",
49+
userResulter,
50+
),
51+
52+
core.ExecStoreBeforeCmdWithResulter(
53+
"ownerAPIKey",
54+
"scw iam api-key list bearer-id={{ .owner }}",
55+
apiKeyResulter,
56+
),
7757
),
78-
79-
core.ExecStoreBeforeCmdWithResulter(
80-
"ownerAPIKey",
81-
"scw iam api-key list bearer-id={{ .owner }}",
82-
apiKeyResulter,
58+
Cmd: `scw iam api-key get {{ .ownerAPIKey }}`,
59+
Check: core.TestCheckCombine(
60+
core.TestCheckGolden(),
61+
core.TestCheckExitCode(0),
8362
),
84-
),
85-
Cmd: `scw iam api-key get {{ .ownerAPIKey }}`,
86-
Check: core.TestCheckCombine(
87-
core.TestCheckGolden(),
88-
core.TestCheckExitCode(0),
89-
),
90-
}))
91-
92-
t.Run("GetMemberAPIKey", core.Test(&core.TestConfig{
93-
Commands: commands,
94-
BeforeFunc: core.BeforeFuncCombine(
95-
core.ExecStoreBeforeCmdWithResulter(
96-
"member",
97-
"scw iam user list type=member",
98-
userResulter,
63+
})(t)
64+
})
65+
66+
t.Run("GetMemberAPIKey", func(t *testing.T) {
67+
userResulter := newSliceResulter(t, "*iamSdk.User", func(users []*iamSdk.User) any {
68+
return users[0].ID
69+
})
70+
71+
apiKeyResulter := newSliceResulter(t, "*iamSdk.APIKey", func(keys []*iamSdk.APIKey) any {
72+
return keys[0].AccessKey
73+
})
74+
75+
core.Test(&core.TestConfig{
76+
Commands: commands,
77+
BeforeFunc: core.BeforeFuncCombine(
78+
core.ExecStoreBeforeCmdWithResulter(
79+
"member",
80+
"scw iam user list type=member",
81+
userResulter,
82+
),
83+
core.ExecStoreBeforeCmdWithResulter(
84+
"memberAPIKey",
85+
"scw iam api-key list bearer-id={{ .member }}",
86+
apiKeyResulter,
87+
),
9988
),
100-
core.ExecStoreBeforeCmdWithResulter(
101-
"memberAPIKey",
102-
"scw iam api-key list bearer-id={{ .member }}",
103-
apiKeyResulter,
89+
Cmd: `scw iam api-key get {{ .memberAPIKey }}`,
90+
Check: core.TestCheckCombine(
91+
core.TestCheckGolden(),
92+
core.TestCheckExitCode(0),
10493
),
105-
),
106-
Cmd: `scw iam api-key get {{ .memberAPIKey }}`,
107-
Check: core.TestCheckCombine(
108-
core.TestCheckGolden(),
109-
core.TestCheckExitCode(0),
110-
),
111-
}))
112-
113-
t.Run("GetApplicationAPIKey", core.Test(&core.TestConfig{
114-
Commands: commands,
115-
BeforeFunc: core.BeforeFuncCombine(
116-
core.ExecStoreBeforeCmdWithResulter(
117-
"application",
118-
"scw iam application list",
119-
applicationResulter,
94+
})(t)
95+
})
96+
97+
t.Run("GetApplicationAPIKey", func(t *testing.T) {
98+
appResulter := newSliceResulter(
99+
t,
100+
"*iamSdk.Application",
101+
func(apps []*iamSdk.Application) any {
102+
return apps[0].ID
103+
},
104+
)
105+
106+
apiKeyResulter := newSliceResulter(t, "*iamSdk.APIKey", func(keys []*iamSdk.APIKey) any {
107+
return keys[0].AccessKey
108+
})
109+
110+
core.Test(&core.TestConfig{
111+
Commands: commands,
112+
BeforeFunc: core.BeforeFuncCombine(
113+
core.ExecStoreBeforeCmdWithResulter(
114+
"application",
115+
"scw iam application list",
116+
appResulter,
117+
),
118+
core.ExecStoreBeforeCmdWithResulter(
119+
"applicationAPIKey",
120+
"scw iam api-key list bearer-id={{ .application }}",
121+
apiKeyResulter,
122+
),
120123
),
121-
core.ExecStoreBeforeCmdWithResulter(
122-
"applicationAPIKey",
123-
"scw iam api-key list bearer-id={{ .application }}",
124-
apiKeyResulter,
124+
Cmd: `scw iam api-key get {{ .applicationAPIKey }}`,
125+
Check: core.TestCheckCombine(
126+
core.TestCheckGolden(),
127+
core.TestCheckExitCode(0),
125128
),
126-
),
127-
Cmd: `scw iam api-key get {{ .applicationAPIKey }}`,
128-
Check: core.TestCheckCombine(
129-
core.TestCheckGolden(),
130-
core.TestCheckExitCode(0),
131-
),
132-
}))
129+
})(t)
130+
})
133131
}

internal/namespaces/iam/v1alpha1/helpers_test.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package iam_test
22

3-
import "github.com/scaleway/scaleway-cli/v2/core"
3+
import (
4+
"testing"
5+
6+
"github.com/scaleway/scaleway-cli/v2/core"
7+
)
48

59
func addSSHKey(metaKey string, key string) core.BeforeFunc {
610
return func(ctx *core.BeforeFuncCtx) error {
@@ -11,3 +15,26 @@ func addSSHKey(metaKey string, key string) core.BeforeFunc {
1115
return nil
1216
}
1317
}
18+
19+
func newSliceResulter[T any](
20+
t *testing.T,
21+
sliceTypeName string,
22+
extractor func([]T) any,
23+
) func(any) any {
24+
t.Helper()
25+
26+
return func(result any) any {
27+
slice, ok := result.([]T)
28+
if !ok {
29+
t.Fatalf("expected []%s, got %T", sliceTypeName, result)
30+
}
31+
if slice == nil {
32+
t.Fatalf("%s slice is nil", sliceTypeName)
33+
}
34+
if len(slice) == 0 {
35+
t.Fatalf("no %s found", sliceTypeName)
36+
}
37+
38+
return extractor(slice)
39+
}
40+
}

0 commit comments

Comments
 (0)