Skip to content

Commit

Permalink
Improve test a bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 committed Sep 6, 2024
1 parent 63f5e24 commit fb333ff
Showing 1 changed file with 41 additions and 44 deletions.
85 changes: 41 additions & 44 deletions controllers/set/infrastructure_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/yaml"
)

func Test_controller_updateInfrastructureStatus(t *testing.T) {
Expand All @@ -43,28 +42,28 @@ func Test_controller_updateInfrastructureStatus(t *testing.T) {
{
name: "infrastructure is present, egress cidrs were not yet set",
objs: func() []client.Object {
rawInfra := `
apiVersion: extensions.gardener.cloud/v1alpha1
kind: Infrastructure
metadata:
name: mycluster1
namespace: shoot--abcdef--mycluster1
spec:
providerConfig:
apiVersion: metal.provider.extensions.gardener.cloud/v1alpha1
firewall:
controllerVersion: auto
status:
phase: "foo"
`

var testInfraMapObj map[string]any
err := yaml.Unmarshal([]byte(rawInfra), &testInfraMapObj)
require.NoError(t, err)

return []client.Object{
&unstructured.Unstructured{
Object: testInfraMapObj,
Object: map[string]any{
"apiVersion": "extensions.gardener.cloud/v1alpha1",
"kind": "Infrastructure",
"metadata": map[string]any{
"name": "mycluster1",
"namespace": testNamespace,
"resourceVersion": "999",
},
"spec": map[string]any{
"providerConfig": map[string]any{
"apiVersion": "metal.provider.extensions.gardener.cloud/v1alpha1",
"firewall": map[string]any{
"controllerVersion": "auto",
},
},
},
"status": map[string]any{
"phase": "foo",
},
},
},
}
},
Expand Down Expand Up @@ -112,31 +111,29 @@ func Test_controller_updateInfrastructureStatus(t *testing.T) {
{
name: "infrastructure is present, egress cidrs have already been set",
objs: func() []client.Object {
rawInfra := `
apiVersion: extensions.gardener.cloud/v1alpha1
kind: Infrastructure
metadata:
name: mycluster1
namespace: shoot--abcdef--mycluster1
spec:
providerConfig:
apiVersion: metal.provider.extensions.gardener.cloud/v1alpha1
firewall:
controllerVersion: auto
status:
phase: "foo"
egressCIDRs:
- 5.6.7.8/32
- 1.2.3.4/32
`

var testInfraMapObj map[string]any
err := yaml.Unmarshal([]byte(rawInfra), &testInfraMapObj)
require.NoError(t, err)

return []client.Object{
&unstructured.Unstructured{
Object: testInfraMapObj,
Object: map[string]any{
"apiVersion": "extensions.gardener.cloud/v1alpha1",
"kind": "Infrastructure",
"metadata": map[string]any{
"name": "mycluster1",
"namespace": testNamespace,
"resourceVersion": "999",
},
"spec": map[string]any{
"providerConfig": map[string]any{
"apiVersion": "metal.provider.extensions.gardener.cloud/v1alpha1",
"firewall": map[string]any{
"controllerVersion": "auto",
},
},
},
"status": map[string]any{
"phase": "foo",
"egressCIDRs": []any{"1.2.3.4/32", "2.3.4.5/32"},
},
},
},
}
},
Expand Down

0 comments on commit fb333ff

Please sign in to comment.