chore(iaas): extract mapping of labels into util func (#867)
This commit is contained in:
parent
ad24ebe52d
commit
281d31f615
15 changed files with 156 additions and 171 deletions
|
|
@ -6,6 +6,10 @@ import (
|
|||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/attr"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
sdkClients "github.com/stackitcloud/stackit-sdk-go/core/clients"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
||||
|
|
@ -92,3 +96,84 @@ func TestConfigureClient(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMapLabels(t *testing.T) {
|
||||
type args struct {
|
||||
responseLabels *map[string]interface{}
|
||||
currentLabels types.Map
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want basetypes.MapValue
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "response labels is set",
|
||||
args: args{
|
||||
responseLabels: &map[string]interface{}{
|
||||
"foo1": "bar1",
|
||||
"foo2": "bar2",
|
||||
},
|
||||
currentLabels: types.MapUnknown(types.StringType),
|
||||
},
|
||||
wantErr: false,
|
||||
want: types.MapValueMust(types.StringType, map[string]attr.Value{
|
||||
"foo1": types.StringValue("bar1"),
|
||||
"foo2": types.StringValue("bar2"),
|
||||
}),
|
||||
},
|
||||
{
|
||||
name: "response labels is set but empty",
|
||||
args: args{
|
||||
responseLabels: &map[string]interface{}{},
|
||||
currentLabels: types.MapUnknown(types.StringType),
|
||||
},
|
||||
wantErr: false,
|
||||
want: types.MapValueMust(types.StringType, map[string]attr.Value{}),
|
||||
},
|
||||
{
|
||||
name: "response labels is nil and model labels is nil",
|
||||
args: args{
|
||||
responseLabels: nil,
|
||||
currentLabels: types.MapNull(types.StringType),
|
||||
},
|
||||
wantErr: false,
|
||||
want: types.MapNull(types.StringType),
|
||||
},
|
||||
{
|
||||
name: "response labels is nil and model labels is set",
|
||||
args: args{
|
||||
responseLabels: nil,
|
||||
currentLabels: types.MapValueMust(types.StringType, map[string]attr.Value{
|
||||
"foo1": types.StringValue("bar1"),
|
||||
"foo2": types.StringValue("bar2"),
|
||||
}),
|
||||
},
|
||||
wantErr: false,
|
||||
want: types.MapValueMust(types.StringType, map[string]attr.Value{}),
|
||||
},
|
||||
{
|
||||
name: "response labels is nil and model labels is set but empty",
|
||||
args: args{
|
||||
responseLabels: nil,
|
||||
currentLabels: types.MapValueMust(types.StringType, map[string]attr.Value{}),
|
||||
},
|
||||
wantErr: false,
|
||||
want: types.MapValueMust(types.StringType, map[string]attr.Value{}),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
got, err := MapLabels(ctx, tt.args.responseLabels, tt.args.currentLabels)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("MapLabels() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("MapLabels() got = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue