Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vicentepinto98 committed Dec 12, 2023
1 parent 402b2fb commit 8af0fa7
Showing 1 changed file with 55 additions and 9 deletions.
64 changes: 55 additions & 9 deletions stackit/internal/services/resourcemanager/project/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,90 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/stackitcloud/stackit-sdk-go/core/utils"
"github.com/stackitcloud/stackit-sdk-go/services/resourcemanager"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
)

func TestMapFields(t *testing.T) {
testUUID := uuid.New().String()
tests := []struct {
description string
input *resourcemanager.ProjectResponseWithParents
expected Model
expectedLabels *map[string]string
isValid bool
description string
uuidContainerParentId bool
input *resourcemanager.ProjectResponseWithParents
expected Model
expectedLabels *map[string]string
isValid bool
}{
{
"default_ok",
false,
&resourcemanager.ProjectResponseWithParents{
ContainerId: utils.Ptr("cid"),
ProjectId: utils.Ptr("pid"),
},
Model{
Id: types.StringValue("cid"),
ContainerId: types.StringValue("cid"),
ProjectId: types.StringValue("pid"),
ContainerParentId: types.StringNull(),
Name: types.StringNull(),
},
nil,
true,
},
{
"values_ok",
"container_parent_id_ok",
false,
&resourcemanager.ProjectResponseWithParents{
ContainerId: utils.Ptr("cid"),
ProjectId: utils.Ptr("pid"),
Labels: &map[string]string{
"label1": "ref1",
"label2": "ref2",
},
Parent: &resourcemanager.Parent{
ContainerId: utils.Ptr("pid"),
ContainerId: utils.Ptr("parent_cid"),
Id: utils.Ptr("parent_pid"),
},
Name: utils.Ptr("name"),
},
Model{
Id: types.StringValue("cid"),
ContainerId: types.StringValue("cid"),
ContainerParentId: types.StringValue("pid"),
ProjectId: types.StringValue("pid"),
ContainerParentId: types.StringValue("parent_cid"),
Name: types.StringValue("name"),
},
&map[string]string{
"label1": "ref1",
"label2": "ref2",
},
true,
},
{
"uuid_parent_id_ok",
true,
&resourcemanager.ProjectResponseWithParents{
ContainerId: utils.Ptr("cid"),
ProjectId: utils.Ptr("pid"),
Labels: &map[string]string{
"label1": "ref1",
"label2": "ref2",
},
Parent: &resourcemanager.Parent{
ContainerId: utils.Ptr("parent_cid"),
Id: utils.Ptr(testUUID),
},
Name: utils.Ptr("name"),
},
Model{
Id: types.StringValue("cid"),
ContainerId: types.StringValue("cid"),
ProjectId: types.StringValue("pid"),
ContainerParentId: types.StringValue(testUUID),
Name: types.StringValue("name"),
},
&map[string]string{
Expand All @@ -60,13 +99,15 @@ func TestMapFields(t *testing.T) {
},
{
"response_nil_fail",
false,
nil,
Model{},
nil,
false,
},
{
"no_resource_id",
false,
&resourcemanager.ProjectResponseWithParents{},
Model{},
nil,
Expand All @@ -84,8 +125,13 @@ func TestMapFields(t *testing.T) {
}
tt.expected.Labels = convertedLabels
}
var containerParentId = types.StringNull()
if tt.uuidContainerParentId {
containerParentId = types.StringValue(testUUID)
}
state := &Model{
ContainerId: tt.expected.ContainerId,
ContainerId: tt.expected.ContainerId,
ContainerParentId: containerParentId,
}

err := mapFields(context.Background(), tt.input, state)
Expand Down

0 comments on commit 8af0fa7

Please sign in to comment.