parent
460c18c202
commit
53a3697850
124 changed files with 8342 additions and 6042 deletions
|
|
@ -12,24 +12,31 @@ import (
|
|||
)
|
||||
|
||||
func TestMapFields(t *testing.T) {
|
||||
type args struct {
|
||||
state Model
|
||||
input *iaas.Volume
|
||||
region string
|
||||
}
|
||||
tests := []struct {
|
||||
description string
|
||||
state Model
|
||||
input *iaas.Volume
|
||||
args args
|
||||
expected Model
|
||||
isValid bool
|
||||
}{
|
||||
{
|
||||
"default_values",
|
||||
Model{
|
||||
ProjectId: types.StringValue("pid"),
|
||||
VolumeId: types.StringValue("nid"),
|
||||
description: "default_values",
|
||||
args: args{
|
||||
state: Model{
|
||||
ProjectId: types.StringValue("pid"),
|
||||
VolumeId: types.StringValue("nid"),
|
||||
},
|
||||
input: &iaas.Volume{
|
||||
Id: utils.Ptr("nid"),
|
||||
},
|
||||
region: "eu01",
|
||||
},
|
||||
&iaas.Volume{
|
||||
Id: utils.Ptr("nid"),
|
||||
},
|
||||
Model{
|
||||
Id: types.StringValue("pid,nid"),
|
||||
expected: Model{
|
||||
Id: types.StringValue("pid,eu01,nid"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
VolumeId: types.StringValue("nid"),
|
||||
Name: types.StringNull(),
|
||||
|
|
@ -40,30 +47,35 @@ func TestMapFields(t *testing.T) {
|
|||
ServerId: types.StringNull(),
|
||||
Size: types.Int64Null(),
|
||||
Source: types.ObjectNull(sourceTypes),
|
||||
Region: types.StringValue("eu01"),
|
||||
},
|
||||
true,
|
||||
isValid: true,
|
||||
},
|
||||
{
|
||||
"simple_values",
|
||||
Model{
|
||||
ProjectId: types.StringValue("pid"),
|
||||
VolumeId: types.StringValue("nid"),
|
||||
},
|
||||
&iaas.Volume{
|
||||
Id: utils.Ptr("nid"),
|
||||
Name: utils.Ptr("name"),
|
||||
AvailabilityZone: utils.Ptr("zone"),
|
||||
Labels: &map[string]interface{}{
|
||||
"key": "value",
|
||||
description: "simple_values",
|
||||
args: args{
|
||||
state: Model{
|
||||
ProjectId: types.StringValue("pid"),
|
||||
VolumeId: types.StringValue("nid"),
|
||||
Region: types.StringValue("eu01"),
|
||||
},
|
||||
Description: utils.Ptr("desc"),
|
||||
PerformanceClass: utils.Ptr("class"),
|
||||
ServerId: utils.Ptr("sid"),
|
||||
Size: utils.Ptr(int64(1)),
|
||||
Source: &iaas.VolumeSource{},
|
||||
input: &iaas.Volume{
|
||||
Id: utils.Ptr("nid"),
|
||||
Name: utils.Ptr("name"),
|
||||
AvailabilityZone: utils.Ptr("zone"),
|
||||
Labels: &map[string]interface{}{
|
||||
"key": "value",
|
||||
},
|
||||
Description: utils.Ptr("desc"),
|
||||
PerformanceClass: utils.Ptr("class"),
|
||||
ServerId: utils.Ptr("sid"),
|
||||
Size: utils.Ptr(int64(1)),
|
||||
Source: &iaas.VolumeSource{},
|
||||
},
|
||||
region: "eu02",
|
||||
},
|
||||
Model{
|
||||
Id: types.StringValue("pid,nid"),
|
||||
expected: Model{
|
||||
Id: types.StringValue("pid,eu02,nid"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
VolumeId: types.StringValue("nid"),
|
||||
Name: types.StringValue("name"),
|
||||
|
|
@ -79,21 +91,25 @@ func TestMapFields(t *testing.T) {
|
|||
"type": types.StringNull(),
|
||||
"id": types.StringNull(),
|
||||
}),
|
||||
Region: types.StringValue("eu02"),
|
||||
},
|
||||
true,
|
||||
isValid: true,
|
||||
},
|
||||
{
|
||||
"empty_labels",
|
||||
Model{
|
||||
ProjectId: types.StringValue("pid"),
|
||||
VolumeId: types.StringValue("nid"),
|
||||
Labels: types.MapValueMust(types.StringType, map[string]attr.Value{}),
|
||||
description: "empty_labels",
|
||||
args: args{
|
||||
state: Model{
|
||||
ProjectId: types.StringValue("pid"),
|
||||
VolumeId: types.StringValue("nid"),
|
||||
Labels: types.MapValueMust(types.StringType, map[string]attr.Value{}),
|
||||
},
|
||||
input: &iaas.Volume{
|
||||
Id: utils.Ptr("nid"),
|
||||
},
|
||||
region: "eu01",
|
||||
},
|
||||
&iaas.Volume{
|
||||
Id: utils.Ptr("nid"),
|
||||
},
|
||||
Model{
|
||||
Id: types.StringValue("pid,nid"),
|
||||
expected: Model{
|
||||
Id: types.StringValue("pid,eu01,nid"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
VolumeId: types.StringValue("nid"),
|
||||
Name: types.StringNull(),
|
||||
|
|
@ -104,29 +120,28 @@ func TestMapFields(t *testing.T) {
|
|||
ServerId: types.StringNull(),
|
||||
Size: types.Int64Null(),
|
||||
Source: types.ObjectNull(sourceTypes),
|
||||
Region: types.StringValue("eu01"),
|
||||
},
|
||||
true,
|
||||
isValid: true,
|
||||
},
|
||||
{
|
||||
"response_nil_fail",
|
||||
Model{},
|
||||
nil,
|
||||
Model{},
|
||||
false,
|
||||
description: "response_nil_fail",
|
||||
},
|
||||
{
|
||||
"no_resource_id",
|
||||
Model{
|
||||
ProjectId: types.StringValue("pid"),
|
||||
description: "no_resource_id",
|
||||
args: args{
|
||||
state: Model{
|
||||
ProjectId: types.StringValue("pid"),
|
||||
},
|
||||
input: &iaas.Volume{},
|
||||
},
|
||||
&iaas.Volume{},
|
||||
Model{},
|
||||
false,
|
||||
expected: Model{},
|
||||
isValid: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.description, func(t *testing.T) {
|
||||
err := mapFields(context.Background(), tt.input, &tt.state)
|
||||
err := mapFields(context.Background(), tt.args.input, &tt.args.state, tt.args.region)
|
||||
if !tt.isValid && err == nil {
|
||||
t.Fatalf("Should have failed")
|
||||
}
|
||||
|
|
@ -134,7 +149,7 @@ func TestMapFields(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