terraform-provider-stackitp.../stackit/internal/conversion/conversion_test.go
Diogo Ferrão a35b887315
Onboard Argus alert configs (#449)
* Onboard Argus alert config receivers (#439)

* initial schema and to payload

* finish receiver resource implementation (schema, topayload and mapfields)

* fix toUpdate payload lists

* fix resource and datasource on alert config attr removal, add testing

* fix linting and testing

* initial test map fields

* improve testing, remove logging

* rename vars in acc testing

* refactor mapAlertConfig

* improve mock alert config, fix testing

* make the mock alert config receivers match the default

* generate docs

* Onboard Argus Alert Config global configuration (#446)

* initial implementation

* initial map fields

* extend datasource, finish resource impl and extend acc testing

* remove unmapped fields

* add all attributes back

* remove commented inhibit rules

* generate docs, fix testing

* address PR comments

* Onboard Alert Config route (#447)

* Initial implementation

* add schema to datasource, improve acc testing

* fix linting, generate docs

* address PR comments

* fix and improve acceptance tests

* update test titles (comments)

* address acceptance comments (#452)

* Onboard Argus Alert Config child routes in Route (#463)

* initial schema and map fields implementation

* initial working solution

* improve implementation, generate docs

* fix description, add more unit testing

* address PR comments

* add unit and acc testing, fix datasource schema, fix plan_id mapping

* add checks to acceptance testing

* update acceptance tests
2024-07-18 15:05:35 +01:00

82 lines
1.9 KiB
Go

package conversion
import (
"context"
"reflect"
"testing"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
)
func TestFromTerraformStringMapToInterfaceMap(t *testing.T) {
type args struct {
ctx context.Context
m basetypes.MapValue
}
tests := []struct {
name string
args args
want map[string]interface{}
wantErr bool
}{
{
name: "base",
args: args{
ctx: context.Background(),
m: types.MapValueMust(types.StringType, map[string]attr.Value{
"key": types.StringValue("value"),
"key2": types.StringValue("value2"),
"key3": types.StringValue("value3"),
}),
},
want: map[string]interface{}{
"key": "value",
"key2": "value2",
"key3": "value3",
},
wantErr: false,
},
{
name: "empty",
args: args{
ctx: context.Background(),
m: types.MapValueMust(types.StringType, map[string]attr.Value{}),
},
want: map[string]interface{}{},
wantErr: false,
},
{
name: "nil",
args: args{
ctx: context.Background(),
m: types.MapNull(types.StringType),
},
want: map[string]interface{}{},
wantErr: false,
},
{
name: "invalid type map (non-string)",
args: args{
ctx: context.Background(),
m: types.MapValueMust(types.Int64Type, map[string]attr.Value{
"key": types.Int64Value(1),
}),
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := ToStringInterfaceMap(tt.args.ctx, tt.args.m)
if (err != nil) != tt.wantErr {
t.Errorf("FromTerraformStringMapToInterfaceMap() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("FromTerraformStringMapToInterfaceMap() = %v, want %v", got, tt.want)
}
})
}
}