parent
460c18c202
commit
53a3697850
124 changed files with 8342 additions and 6042 deletions
|
|
@ -11,52 +11,56 @@ import (
|
|||
)
|
||||
|
||||
func TestMapFields(t *testing.T) {
|
||||
type args struct {
|
||||
state Model
|
||||
input *iaas.AffinityGroup
|
||||
region string
|
||||
}
|
||||
tests := []struct {
|
||||
description string
|
||||
state Model
|
||||
input *iaas.AffinityGroup
|
||||
args args
|
||||
expected Model
|
||||
isValid bool
|
||||
}{
|
||||
{
|
||||
"default_values",
|
||||
Model{
|
||||
ProjectId: types.StringValue("pid"),
|
||||
AffinityGroupId: types.StringValue("aid"),
|
||||
description: "default_values",
|
||||
args: args{
|
||||
state: Model{
|
||||
ProjectId: types.StringValue("pid"),
|
||||
AffinityGroupId: types.StringValue("aid"),
|
||||
},
|
||||
input: &iaas.AffinityGroup{
|
||||
Id: utils.Ptr("aid"),
|
||||
},
|
||||
region: "eu01",
|
||||
},
|
||||
&iaas.AffinityGroup{
|
||||
Id: utils.Ptr("aid"),
|
||||
},
|
||||
Model{
|
||||
Id: types.StringValue("pid,aid"),
|
||||
expected: Model{
|
||||
Id: types.StringValue("pid,eu01,aid"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
AffinityGroupId: types.StringValue("aid"),
|
||||
Name: types.StringNull(),
|
||||
Policy: types.StringNull(),
|
||||
Members: types.ListNull(types.StringType),
|
||||
Region: types.StringValue("eu01"),
|
||||
},
|
||||
true,
|
||||
isValid: true,
|
||||
},
|
||||
{
|
||||
"response_nil_fail",
|
||||
Model{},
|
||||
nil,
|
||||
Model{},
|
||||
false,
|
||||
description: "response_nil_fail",
|
||||
},
|
||||
{
|
||||
"no_affinity_group_id",
|
||||
Model{
|
||||
ProjectId: types.StringValue("pid"),
|
||||
description: "no_affinity_group_id",
|
||||
args: args{
|
||||
state: Model{
|
||||
ProjectId: types.StringValue("pid"),
|
||||
},
|
||||
input: &iaas.AffinityGroup{},
|
||||
},
|
||||
&iaas.AffinityGroup{},
|
||||
Model{},
|
||||
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")
|
||||
}
|
||||
|
|
@ -64,7 +68,7 @@ func TestMapFields(t *testing.T) {
|
|||
t.Fatalf("Should not have failed")
|
||||
}
|
||||
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: %v", diff)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue