terraform-provider-stackitp.../stackit/internal/services/argus/credential/resource_test.go
Henrique Santos c7effac5c7
Update SDK dependency (#177)
* Update dependencies

* Update dependencies

* Update dependencies

* Update dependencies

---------

Co-authored-by: Henrique Santos <henrique.santos@freiheit.com>
2023-12-21 09:33:36 +00:00

77 lines
1.5 KiB
Go

package argus
import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/stackitcloud/stackit-sdk-go/core/utils"
"github.com/stackitcloud/stackit-sdk-go/services/argus"
)
func TestMapFields(t *testing.T) {
tests := []struct {
description string
input *argus.Credentials
expected Model
isValid bool
}{
{
"ok",
&argus.Credentials{
Username: utils.Ptr("username"),
Password: utils.Ptr("password"),
},
Model{
Id: types.StringValue("pid,iid,username"),
ProjectId: types.StringValue("pid"),
InstanceId: types.StringValue("iid"),
Username: types.StringValue("username"),
Password: types.StringValue("password"),
},
true,
},
{
"response_nil_fail",
nil,
Model{},
false,
},
{
"response_fields_nil_fail",
&argus.Credentials{
Password: nil,
Username: nil,
},
Model{},
false,
},
{
"no_resource_id",
&argus.Credentials{},
Model{},
false,
},
}
for _, tt := range tests {
t.Run(tt.description, func(t *testing.T) {
state := &Model{
ProjectId: tt.expected.ProjectId,
InstanceId: tt.expected.InstanceId,
}
err := mapFields(tt.input, 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(state, &tt.expected)
if diff != "" {
t.Fatalf("Data does not match: %s", diff)
}
}
})
}
}