Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(iam): prevent type assertion from crashing #4362

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion internal/namespaces/iam/v1alpha1/custom_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/scaleway/scaleway-cli/v2/core"
"github.com/scaleway/scaleway-cli/v2/internal/namespaces/account/v3"
iam "github.com/scaleway/scaleway-cli/v2/internal/namespaces/iam/v1alpha1"
"github.com/scaleway/scaleway-cli/v2/internal/testhelpers"
)

func Test_createRule(t *testing.T) {
Expand Down Expand Up @@ -49,7 +50,7 @@ func Test_deleteRule(t *testing.T) {
core.ExecStoreBeforeCmd("Policy", "scw iam policy get {{ .Policy.ID }}"),
func(ctx *core.BeforeFuncCtx) error {
// Get first Rule ID
policy := ctx.Meta["Policy"].(*iam.PolicyGetInterceptorResponse)
policy := testhelpers.MapValue[*iam.PolicyGetInterceptorResponse](t, ctx.Meta, "Policy")
if len(policy.Rules) != 2 {
return errors.New("expected two rules in policy")
}
Expand Down
5 changes: 4 additions & 1 deletion internal/namespaces/iam/v1alpha1/custom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/scaleway/scaleway-cli/v2/core"
iam "github.com/scaleway/scaleway-cli/v2/internal/namespaces/iam/v1alpha1"
"github.com/scaleway/scaleway-cli/v2/internal/testhelpers"
iamsdk "github.com/scaleway/scaleway-sdk-go/api/iam/v1alpha1"
)

Expand Down Expand Up @@ -52,8 +53,10 @@ func Test_SSHKeyCreateCommand(t *testing.T) {
),
AfterFunc: func(ctx *core.AfterFuncCtx) error {
api := iamsdk.NewAPI(ctx.Client)
key := testhelpers.Value[*iamsdk.SSHKey](t, ctx.CmdResult)

return api.DeleteSSHKey(&iamsdk.DeleteSSHKeyRequest{
SSHKeyID: ctx.CmdResult.(*iamsdk.SSHKey).ID,
SSHKeyID: key.ID,
})
},
}))
Expand Down
Loading