Skip to content

Commit 0a927f0

Browse files
committed
test: Add more matcher cases
1 parent 696d047 commit 0a927f0

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

common/pkg/capi/clustertopology/patches/matchers/match_test.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
1515

1616
"github.com/d2iq-labs/capi-runtime-extensions/common/pkg/capi/clustertopology/patches/matchers"
17+
"github.com/d2iq-labs/capi-runtime-extensions/common/pkg/capi/clustertopology/patches/selectors"
1718
)
1819

1920
func TestMatchesSelector(t *testing.T) {
@@ -478,6 +479,74 @@ func TestMatchesSelector(t *testing.T) {
478479
},
479480
},
480481
match: false,
482+
}, {
483+
name: "Match InfrastructureWorkerMachineTemplates",
484+
obj: &unstructured.Unstructured{
485+
Object: map[string]interface{}{
486+
"apiVersion": "infrastructure.cluster.x-k8s.io/v1beta1",
487+
"kind": "DockerMachineTemplate",
488+
},
489+
},
490+
holderRef: &runtimehooksv1.HolderReference{
491+
APIVersion: "cluster.x-k8s.io/v1beta1",
492+
Kind: "MachineDeployment",
493+
Name: "docker-quick-start-md-0",
494+
Namespace: "default",
495+
FieldPath: "spec.template.spec.infrastructureRef",
496+
},
497+
selector: selectors.InfrastructureWorkerMachineTemplates("v1beta1", "DockerMachineTemplate"),
498+
match: true,
499+
}, {
500+
name: "Match InfrastructureControlPlaneMachines",
501+
obj: &unstructured.Unstructured{
502+
Object: map[string]interface{}{
503+
"apiVersion": "infrastructure.cluster.x-k8s.io/v1beta1",
504+
"kind": "DockerMachineTemplate",
505+
},
506+
},
507+
holderRef: &runtimehooksv1.HolderReference{
508+
APIVersion: "controlplane.cluster.x-k8s.io/v1beta1",
509+
Kind: "KubeadmControlPlane",
510+
Name: "docker-quick-start",
511+
Namespace: "default",
512+
FieldPath: "spec.machineTemplate.infrastructureRef",
513+
},
514+
selector: selectors.InfrastructureControlPlaneMachines("v1beta1", "DockerMachineTemplate"),
515+
match: true,
516+
}, {
517+
name: "Don't match InfrastructureControlPlaneMachines for a MachineDeployment holderRef",
518+
obj: &unstructured.Unstructured{
519+
Object: map[string]interface{}{
520+
"apiVersion": "infrastructure.cluster.x-k8s.io/v1beta1",
521+
"kind": "DockerMachineTemplate",
522+
},
523+
},
524+
holderRef: &runtimehooksv1.HolderReference{
525+
APIVersion: "cluster.x-k8s.io/v1beta1",
526+
Kind: "MachineDeployment",
527+
Name: "docker-quick-start-md-0",
528+
Namespace: "default",
529+
FieldPath: "spec.template.spec.infrastructureRef",
530+
},
531+
selector: selectors.InfrastructureControlPlaneMachines("v1beta1", "DockerMachineTemplate"),
532+
match: false,
533+
}, {
534+
name: "Don't match InfrastructureWorkerMachineTemplates for a KubeadmControlPlane holderRef",
535+
obj: &unstructured.Unstructured{
536+
Object: map[string]interface{}{
537+
"apiVersion": "infrastructure.cluster.x-k8s.io/v1beta1",
538+
"kind": "DockerMachineTemplate",
539+
},
540+
},
541+
holderRef: &runtimehooksv1.HolderReference{
542+
APIVersion: "controlplane.cluster.x-k8s.io/v1beta1",
543+
Kind: "KubeadmControlPlane",
544+
Name: "docker-quick-start",
545+
Namespace: "default",
546+
FieldPath: "spec.machineTemplate.infrastructureRef",
547+
},
548+
selector: selectors.InfrastructureWorkerMachineTemplates("v1beta1", "DockerMachineTemplate"),
549+
match: false,
481550
}}
482551
for idx := range tests {
483552
tt := tests[idx]

0 commit comments

Comments
 (0)