parent
460c18c202
commit
53a3697850
124 changed files with 8342 additions and 6042 deletions
|
|
@ -12,69 +12,81 @@ import (
|
|||
)
|
||||
|
||||
func TestMapDataSourceFields(t *testing.T) {
|
||||
type args struct {
|
||||
state DataSourceModel
|
||||
input *iaas.Image
|
||||
region string
|
||||
}
|
||||
tests := []struct {
|
||||
description string
|
||||
state DataSourceModel
|
||||
input *iaas.Image
|
||||
args args
|
||||
expected DataSourceModel
|
||||
isValid bool
|
||||
}{
|
||||
{
|
||||
"default_values",
|
||||
DataSourceModel{
|
||||
ProjectId: types.StringValue("pid"),
|
||||
ImageId: types.StringValue("iid"),
|
||||
description: "default_values",
|
||||
args: args{
|
||||
state: DataSourceModel{
|
||||
ProjectId: types.StringValue("pid"),
|
||||
ImageId: types.StringValue("iid"),
|
||||
},
|
||||
input: &iaas.Image{
|
||||
Id: utils.Ptr("iid"),
|
||||
},
|
||||
region: "eu01",
|
||||
},
|
||||
&iaas.Image{
|
||||
Id: utils.Ptr("iid"),
|
||||
},
|
||||
DataSourceModel{
|
||||
Id: types.StringValue("pid,iid"),
|
||||
expected: DataSourceModel{
|
||||
Id: types.StringValue("pid,eu01,iid"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
ImageId: types.StringValue("iid"),
|
||||
Labels: types.MapNull(types.StringType),
|
||||
Region: types.StringValue("eu01"),
|
||||
},
|
||||
true,
|
||||
isValid: true,
|
||||
},
|
||||
{
|
||||
"simple_values",
|
||||
DataSourceModel{
|
||||
ProjectId: types.StringValue("pid"),
|
||||
ImageId: types.StringValue("iid"),
|
||||
description: "simple_values",
|
||||
args: args{
|
||||
state: DataSourceModel{
|
||||
ProjectId: types.StringValue("pid"),
|
||||
ImageId: types.StringValue("iid"),
|
||||
Region: types.StringValue("eu01"),
|
||||
},
|
||||
input: &iaas.Image{
|
||||
Id: utils.Ptr("iid"),
|
||||
Name: utils.Ptr("name"),
|
||||
DiskFormat: utils.Ptr("format"),
|
||||
MinDiskSize: utils.Ptr(int64(1)),
|
||||
MinRam: utils.Ptr(int64(1)),
|
||||
Protected: utils.Ptr(true),
|
||||
Scope: utils.Ptr("scope"),
|
||||
Config: &iaas.ImageConfig{
|
||||
BootMenu: utils.Ptr(true),
|
||||
CdromBus: iaas.NewNullableString(utils.Ptr("cdrom_bus")),
|
||||
DiskBus: iaas.NewNullableString(utils.Ptr("disk_bus")),
|
||||
NicModel: iaas.NewNullableString(utils.Ptr("model")),
|
||||
OperatingSystem: utils.Ptr("os"),
|
||||
OperatingSystemDistro: iaas.NewNullableString(utils.Ptr("os_distro")),
|
||||
OperatingSystemVersion: iaas.NewNullableString(utils.Ptr("os_version")),
|
||||
RescueBus: iaas.NewNullableString(utils.Ptr("rescue_bus")),
|
||||
RescueDevice: iaas.NewNullableString(utils.Ptr("rescue_device")),
|
||||
SecureBoot: utils.Ptr(true),
|
||||
Uefi: utils.Ptr(true),
|
||||
VideoModel: iaas.NewNullableString(utils.Ptr("model")),
|
||||
VirtioScsi: utils.Ptr(true),
|
||||
},
|
||||
Checksum: &iaas.ImageChecksum{
|
||||
Algorithm: utils.Ptr("algorithm"),
|
||||
Digest: utils.Ptr("digest"),
|
||||
},
|
||||
Labels: &map[string]interface{}{
|
||||
"key": "value",
|
||||
},
|
||||
},
|
||||
region: "eu02",
|
||||
},
|
||||
&iaas.Image{
|
||||
Id: utils.Ptr("iid"),
|
||||
Name: utils.Ptr("name"),
|
||||
DiskFormat: utils.Ptr("format"),
|
||||
MinDiskSize: utils.Ptr(int64(1)),
|
||||
MinRam: utils.Ptr(int64(1)),
|
||||
Protected: utils.Ptr(true),
|
||||
Scope: utils.Ptr("scope"),
|
||||
Config: &iaas.ImageConfig{
|
||||
BootMenu: utils.Ptr(true),
|
||||
CdromBus: iaas.NewNullableString(utils.Ptr("cdrom_bus")),
|
||||
DiskBus: iaas.NewNullableString(utils.Ptr("disk_bus")),
|
||||
NicModel: iaas.NewNullableString(utils.Ptr("model")),
|
||||
OperatingSystem: utils.Ptr("os"),
|
||||
OperatingSystemDistro: iaas.NewNullableString(utils.Ptr("os_distro")),
|
||||
OperatingSystemVersion: iaas.NewNullableString(utils.Ptr("os_version")),
|
||||
RescueBus: iaas.NewNullableString(utils.Ptr("rescue_bus")),
|
||||
RescueDevice: iaas.NewNullableString(utils.Ptr("rescue_device")),
|
||||
SecureBoot: utils.Ptr(true),
|
||||
Uefi: utils.Ptr(true),
|
||||
VideoModel: iaas.NewNullableString(utils.Ptr("model")),
|
||||
VirtioScsi: utils.Ptr(true),
|
||||
},
|
||||
Checksum: &iaas.ImageChecksum{
|
||||
Algorithm: utils.Ptr("algorithm"),
|
||||
Digest: utils.Ptr("digest"),
|
||||
},
|
||||
Labels: &map[string]interface{}{
|
||||
"key": "value",
|
||||
},
|
||||
},
|
||||
DataSourceModel{
|
||||
Id: types.StringValue("pid,iid"),
|
||||
expected: DataSourceModel{
|
||||
Id: types.StringValue("pid,eu02,iid"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
ImageId: types.StringValue("iid"),
|
||||
Name: types.StringValue("name"),
|
||||
|
|
@ -105,47 +117,48 @@ func TestMapDataSourceFields(t *testing.T) {
|
|||
Labels: types.MapValueMust(types.StringType, map[string]attr.Value{
|
||||
"key": types.StringValue("value"),
|
||||
}),
|
||||
Region: types.StringValue("eu02"),
|
||||
},
|
||||
true,
|
||||
isValid: true,
|
||||
},
|
||||
{
|
||||
"empty_labels",
|
||||
DataSourceModel{
|
||||
description: "empty_labels",
|
||||
args: args{
|
||||
state: DataSourceModel{
|
||||
ProjectId: types.StringValue("pid"),
|
||||
ImageId: types.StringValue("iid"),
|
||||
Labels: types.MapValueMust(types.StringType, map[string]attr.Value{}),
|
||||
},
|
||||
input: &iaas.Image{
|
||||
Id: utils.Ptr("iid"),
|
||||
},
|
||||
region: "eu01",
|
||||
},
|
||||
expected: DataSourceModel{
|
||||
Id: types.StringValue("pid,eu01,iid"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
ImageId: types.StringValue("iid"),
|
||||
Labels: types.MapValueMust(types.StringType, map[string]attr.Value{}),
|
||||
Region: types.StringValue("eu01"),
|
||||
},
|
||||
&iaas.Image{
|
||||
Id: utils.Ptr("iid"),
|
||||
},
|
||||
DataSourceModel{
|
||||
Id: types.StringValue("pid,iid"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
ImageId: types.StringValue("iid"),
|
||||
Labels: types.MapValueMust(types.StringType, map[string]attr.Value{}),
|
||||
},
|
||||
true,
|
||||
isValid: true,
|
||||
},
|
||||
{
|
||||
"response_nil_fail",
|
||||
DataSourceModel{},
|
||||
nil,
|
||||
DataSourceModel{},
|
||||
false,
|
||||
description: "response_nil_fail",
|
||||
},
|
||||
{
|
||||
"no_resource_id",
|
||||
DataSourceModel{
|
||||
ProjectId: types.StringValue("pid"),
|
||||
description: "no_resource_id",
|
||||
args: args{
|
||||
state: DataSourceModel{
|
||||
ProjectId: types.StringValue("pid"),
|
||||
},
|
||||
input: &iaas.Image{},
|
||||
},
|
||||
&iaas.Image{},
|
||||
DataSourceModel{},
|
||||
false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.description, func(t *testing.T) {
|
||||
err := mapDataSourceFields(context.Background(), tt.input, &tt.state)
|
||||
err := mapDataSourceFields(context.Background(), tt.args.input, &tt.args.state, tt.args.region)
|
||||
if !tt.isValid && err == nil {
|
||||
t.Fatalf("Should have failed")
|
||||
}
|
||||
|
|
@ -153,7 +166,7 @@ func TestMapDataSourceFields(t *testing.T) {
|
|||
t.Fatalf("Should not have failed: %v", err)
|
||||
}
|
||||
if tt.isValid {
|
||||
diff := cmp.Diff(tt.state, tt.expected)
|
||||
diff := cmp.Diff(tt.args.state, tt.expected)
|
||||
if diff != "" {
|
||||
t.Fatalf("Data does not match: %s", diff)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue