Skip to content

Commit 14a3c8c

Browse files
authored
test(iam): prevent type assertion from crashing (scaleway#4362)
1 parent 2285160 commit 14a3c8c

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

internal/namespaces/iam/v1alpha1/custom_rule_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/scaleway/scaleway-cli/v2/core"
99
"github.com/scaleway/scaleway-cli/v2/internal/namespaces/account/v3"
1010
iam "github.com/scaleway/scaleway-cli/v2/internal/namespaces/iam/v1alpha1"
11+
"github.com/scaleway/scaleway-cli/v2/internal/testhelpers"
1112
)
1213

1314
func Test_createRule(t *testing.T) {
@@ -49,7 +50,7 @@ func Test_deleteRule(t *testing.T) {
4950
core.ExecStoreBeforeCmd("Policy", "scw iam policy get {{ .Policy.ID }}"),
5051
func(ctx *core.BeforeFuncCtx) error {
5152
// Get first Rule ID
52-
policy := ctx.Meta["Policy"].(*iam.PolicyGetInterceptorResponse)
53+
policy := testhelpers.MapValue[*iam.PolicyGetInterceptorResponse](t, ctx.Meta, "Policy")
5354
if len(policy.Rules) != 2 {
5455
return errors.New("expected two rules in policy")
5556
}

internal/namespaces/iam/v1alpha1/custom_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/scaleway/scaleway-cli/v2/core"
99
iam "github.com/scaleway/scaleway-cli/v2/internal/namespaces/iam/v1alpha1"
10+
"github.com/scaleway/scaleway-cli/v2/internal/testhelpers"
1011
iamsdk "github.com/scaleway/scaleway-sdk-go/api/iam/v1alpha1"
1112
)
1213

@@ -52,8 +53,10 @@ func Test_SSHKeyCreateCommand(t *testing.T) {
5253
),
5354
AfterFunc: func(ctx *core.AfterFuncCtx) error {
5455
api := iamsdk.NewAPI(ctx.Client)
56+
key := testhelpers.Value[*iamsdk.SSHKey](t, ctx.CmdResult)
57+
5558
return api.DeleteSSHKey(&iamsdk.DeleteSSHKeyRequest{
56-
SSHKeyID: ctx.CmdResult.(*iamsdk.SSHKey).ID,
59+
SSHKeyID: key.ID,
5760
})
5861
},
5962
}))

0 commit comments

Comments
 (0)