Allow specifying network ID in SKE cluster (#368)

This commit is contained in:
João Palet 2024-05-21 11:27:23 +01:00 committed by GitHub
parent e2e5f19a29
commit ac0840fceb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 204 additions and 7 deletions

View file

@ -49,6 +49,7 @@ func TestMapFields(t *testing.T) {
AllowPrivilegedContainers: types.BoolNull(),
NodePools: types.ListNull(types.ObjectType{AttrTypes: nodePoolTypes}),
Maintenance: types.ObjectNull(maintenanceTypes),
Network: types.ObjectNull(networkTypes),
Hibernations: types.ListNull(types.ObjectType{AttrTypes: hibernationTypes}),
Extensions: types.ObjectNull(extensionsTypes),
KubeConfig: types.StringNull(),
@ -92,6 +93,9 @@ func TestMapFields(t *testing.T) {
End: utils.Ptr("0010-11-12T13:14:15Z"),
},
},
Network: &ske.V1Network{
Id: utils.Ptr("nid"),
},
Name: utils.Ptr("name"),
Nodepools: &[]ske.Nodepool{
{
@ -194,6 +198,9 @@ func TestMapFields(t *testing.T) {
"start": types.StringValue("03:04:05+06:00"),
"end": types.StringValue("13:14:15Z"),
}),
Network: types.ObjectValueMust(networkTypes, map[string]attr.Value{
"id": types.StringValue("nid"),
}),
Hibernations: types.ListValueMust(
types.ObjectType{AttrTypes: hibernationTypes},
[]attr.Value{
@ -223,6 +230,30 @@ func TestMapFields(t *testing.T) {
},
true,
},
{
"nil_network_id",
types.ObjectNull(extensionsTypes),
&ske.Cluster{
Name: utils.Ptr("name"),
Network: &ske.V1Network{},
},
Model{
Id: types.StringValue("pid,name"),
ProjectId: types.StringValue("pid"),
Name: types.StringValue("name"),
KubernetesVersion: types.StringNull(),
AllowPrivilegedContainers: types.BoolNull(),
NodePools: types.ListNull(types.ObjectType{AttrTypes: nodePoolTypes}),
Maintenance: types.ObjectNull(maintenanceTypes),
Network: types.ObjectValueMust(networkTypes, map[string]attr.Value{
"id": types.StringNull(),
}),
Hibernations: types.ListNull(types.ObjectType{AttrTypes: hibernationTypes}),
Extensions: types.ObjectNull(extensionsTypes),
KubeConfig: types.StringNull(),
},
true,
},
{
"extensions_mixed_values",
types.ObjectNull(extensionsTypes),
@ -1936,3 +1967,63 @@ func TestGetLatestSupportedMachineVersion(t *testing.T) {
})
}
}
func TestToNetworkPayload(t *testing.T) {
tests := []struct {
description string
model *Model
expected *ske.V1Network
isValid bool
}{
{
"base",
&Model{
ProjectId: types.StringValue("pid"),
Name: types.StringValue("name"),
Network: types.ObjectValueMust(networkTypes, map[string]attr.Value{
"id": types.StringValue("nid"),
}),
},
&ske.V1Network{
Id: utils.Ptr("nid"),
},
true,
},
{
"no_id",
&Model{
ProjectId: types.StringValue("pid"),
Name: types.StringValue("name"),
Network: types.ObjectValueMust(networkTypes, map[string]attr.Value{
"id": types.StringNull(),
}),
},
&ske.V1Network{},
true,
},
{
"no_network",
&Model{
ProjectId: types.StringValue("pid"),
Name: types.StringValue("name"),
Network: types.ObjectNull(networkTypes),
},
nil,
true,
},
}
for _, tt := range tests {
t.Run(tt.description, func(t *testing.T) {
payload, err := toNetworkPayload(context.Background(), tt.model)
if !tt.isValid && err == nil {
t.Fatalf("Should have failed")
}
if tt.isValid {
diff := cmp.Diff(payload, tt.expected)
if diff != "" {
t.Fatalf("Data does not match: %s", diff)
}
}
})
}
}