Revert "Implement key pair resource (#578)" (#581)

This reverts commit 153947fd7b.
This commit is contained in:
João Palet 2024-11-06 14:21:17 +00:00 committed by GitHub
parent 153947fd7b
commit 600847a2ea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 113 additions and 1257 deletions

View file

@ -1,211 +0,0 @@
package keypair
import (
"context"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/stackitcloud/stackit-sdk-go/core/utils"
"github.com/stackitcloud/stackit-sdk-go/services/iaasalpha"
)
func TestMapFields(t *testing.T) {
tests := []struct {
description string
state Model
input *iaasalpha.Keypair
expected Model
isValid bool
}{
{
"default_values",
Model{
Name: types.StringValue("name"),
},
&iaasalpha.Keypair{
Name: utils.Ptr("name"),
},
Model{
Id: types.StringValue("name"),
Name: types.StringValue("name"),
PublicKey: types.StringNull(),
Fingerprint: types.StringNull(),
Labels: types.MapNull(types.StringType),
},
true,
},
{
"simple_values",
Model{
Name: types.StringValue("name"),
},
&iaasalpha.Keypair{
Name: utils.Ptr("name"),
PublicKey: utils.Ptr("public_key"),
Fingerprint: utils.Ptr("fingerprint"),
Labels: &map[string]interface{}{
"key": "value",
},
},
Model{
Id: types.StringValue("name"),
Name: types.StringValue("name"),
PublicKey: types.StringValue("public_key"),
Fingerprint: types.StringValue("fingerprint"),
Labels: types.MapValueMust(types.StringType, map[string]attr.Value{
"key": types.StringValue("value"),
}),
},
true,
},
{
"empty_labels",
Model{
Name: types.StringValue("name"),
},
&iaasalpha.Keypair{
Name: utils.Ptr("name"),
PublicKey: utils.Ptr("public_key"),
Fingerprint: utils.Ptr("fingerprint"),
Labels: &map[string]interface{}{},
},
Model{
Id: types.StringValue("name"),
Name: types.StringValue("name"),
PublicKey: types.StringValue("public_key"),
Fingerprint: types.StringValue("fingerprint"),
Labels: types.MapNull(types.StringType),
},
true,
},
{
"response_nil_fail",
Model{},
nil,
Model{},
false,
},
{
"no_resource_id",
Model{},
&iaasalpha.Keypair{
PublicKey: utils.Ptr("public_key"),
Fingerprint: utils.Ptr("fingerprint"),
Labels: &map[string]interface{}{},
},
Model{},
false,
},
}
for _, tt := range tests {
t.Run(tt.description, func(t *testing.T) {
err := mapFields(context.Background(), tt.input, &tt.state)
if !tt.isValid && err == nil {
t.Fatalf("Should have failed")
}
if tt.isValid && err != nil {
t.Fatalf("Should not have failed: %v", err)
}
if tt.isValid {
diff := cmp.Diff(tt.state, tt.expected)
if diff != "" {
t.Fatalf("Data does not match: %s", diff)
}
}
})
}
}
func TestToCreatePayload(t *testing.T) {
tests := []struct {
description string
input *Model
expected *iaasalpha.CreateKeyPairPayload
isValid bool
}{
{
"default_ok",
&Model{
Name: types.StringValue("name"),
PublicKey: types.StringValue("public_key"),
Labels: types.MapValueMust(types.StringType, map[string]attr.Value{
"key1": types.StringValue("value1"),
"key2": types.StringValue("value2"),
}),
},
&iaasalpha.CreateKeyPairPayload{
Name: utils.Ptr("name"),
PublicKey: utils.Ptr("public_key"),
Labels: &map[string]interface{}{
"key1": "value1",
"key2": "value2",
},
},
true,
},
}
for _, tt := range tests {
t.Run(tt.description, func(t *testing.T) {
output, err := toCreatePayload(context.Background(), tt.input)
if !tt.isValid && err == nil {
t.Fatalf("Should have failed")
}
if tt.isValid && err != nil {
t.Fatalf("Should not have failed: %v", err)
}
if tt.isValid {
diff := cmp.Diff(output, tt.expected, cmp.AllowUnexported(iaasalpha.NullableString{}))
if diff != "" {
t.Fatalf("Data does not match: %s", diff)
}
}
})
}
}
func TestToUpdatePayload(t *testing.T) {
tests := []struct {
description string
input *Model
expected *iaasalpha.UpdateKeyPairPayload
isValid bool
}{
{
"default_ok",
&Model{
Name: types.StringValue("name"),
PublicKey: types.StringValue("public_key"),
Labels: types.MapValueMust(types.StringType, map[string]attr.Value{
"key1": types.StringValue("value1"),
"key2": types.StringValue("value2"),
}),
},
&iaasalpha.UpdateKeyPairPayload{
Labels: &map[string]interface{}{
"key1": "value1",
"key2": "value2",
},
},
true,
},
}
for _, tt := range tests {
t.Run(tt.description, func(t *testing.T) {
output, err := toUpdatePayload(context.Background(), tt.input, types.MapNull(types.StringType))
if !tt.isValid && err == nil {
t.Fatalf("Should have failed")
}
if tt.isValid && err != nil {
t.Fatalf("Should not have failed: %v", err)
}
if tt.isValid {
diff := cmp.Diff(output, tt.expected, cmp.AllowUnexported(iaasalpha.NullableString{}))
if diff != "" {
t.Fatalf("Data does not match: %s", diff)
}
}
})
}
}