Skip to content

Commit df3f6e8

Browse files
authored
Merge pull request #7218 from killianmuldoon/test/use-upstream-matchers
🌱 Replace CAPI Matcher with Controller Runtime implementation
2 parents bf1e741 + 4225e09 commit df3f6e8

File tree

12 files changed

+13
-800
lines changed

12 files changed

+13
-800
lines changed

docs/book/src/developer/testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ easily readable, well documented and consistent across the code base.
7474
In light of continuing improving our practice around this ambitious goal, we are starting to introduce a shared set of:
7575

7676
- Builders (`sigs.k8s.io/cluster-api/internal/test/builder`), allowing to create test objects in a simple and consistent way.
77-
- Matchers (`sigs.k8s.io/cluster-api/internal/test/matchers`), improving how we write test assertions.
77+
- Matchers (`sigs.k8s.io/controller-runtime/pkg/envtest/komega`), improving how we write test assertions.
7878

7979
Each contribution in growing this set of utilities or their adoption across the codebase is more than welcome!
8080

internal/controllers/machine/machine_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2058,7 +2058,7 @@ func addConditionsToExternal(u *unstructured.Unstructured, newConditions cluster
20582058
}
20592059

20602060
// asserts the conditions set on the Getter object.
2061-
// TODO: replace this with util.condition.MatchConditions (or a new matcher in internal/matchers).
2061+
// TODO: replace this with util.condition.MatchConditions (or a new matcher in controller runtime komega).
20622062
func assertConditions(t *testing.T, from conditions.Getter, conditions ...*clusterv1.Condition) {
20632063
t.Helper()
20642064

internal/controllers/machinedeployment/machinedeployment_sync_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ func TestSyncDeploymentStatus(t *testing.T) {
496496
}
497497

498498
// asserts the conditions set on the Getter object.
499-
// TODO: replace this with util.condition.MatchConditions (or a new matcher in internal/matchers).
499+
// TODO: replace this with util.condition.MatchConditions (or a new matcher in controller runtime komega).
500500
func assertConditions(t *testing.T, from conditions.Getter, conditions ...*clusterv1.Condition) {
501501
t.Helper()
502502

internal/controllers/topology/cluster/blueprint_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ import (
2525
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2626
"sigs.k8s.io/controller-runtime/pkg/client"
2727
"sigs.k8s.io/controller-runtime/pkg/client/fake"
28+
. "sigs.k8s.io/controller-runtime/pkg/envtest/komega"
2829

2930
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3031
"sigs.k8s.io/cluster-api/internal/controllers/topology/cluster/scope"
3132
"sigs.k8s.io/cluster-api/internal/test/builder"
32-
. "sigs.k8s.io/cluster-api/internal/test/matchers"
3333
)
3434

3535
func TestGetBlueprint(t *testing.T) {

internal/controllers/topology/cluster/current_state_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ import (
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2727
"sigs.k8s.io/controller-runtime/pkg/client"
2828
"sigs.k8s.io/controller-runtime/pkg/client/fake"
29+
. "sigs.k8s.io/controller-runtime/pkg/envtest/komega"
2930

3031
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3132
"sigs.k8s.io/cluster-api/internal/controllers/topology/cluster/scope"
3233
"sigs.k8s.io/cluster-api/internal/test/builder"
33-
. "sigs.k8s.io/cluster-api/internal/test/matchers"
3434
)
3535

3636
func TestGetCurrentState(t *testing.T) {

internal/controllers/topology/cluster/patches/engine_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"k8s.io/apimachinery/pkg/types"
3131
utilfeature "k8s.io/component-base/featuregate/testing"
3232
"k8s.io/utils/pointer"
33+
. "sigs.k8s.io/controller-runtime/pkg/envtest/komega"
3334

3435
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3536
runtimecatalog "sigs.k8s.io/cluster-api/exp/runtime/catalog"
@@ -38,7 +39,6 @@ import (
3839
"sigs.k8s.io/cluster-api/internal/controllers/topology/cluster/scope"
3940
fakeruntimeclient "sigs.k8s.io/cluster-api/internal/runtime/client/fake"
4041
"sigs.k8s.io/cluster-api/internal/test/builder"
41-
. "sigs.k8s.io/cluster-api/internal/test/matchers"
4242
)
4343

4444
func TestApply(t *testing.T) {

internal/controllers/topology/cluster/reconcile_state_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"k8s.io/utils/pointer"
3636
"sigs.k8s.io/controller-runtime/pkg/client"
3737
"sigs.k8s.io/controller-runtime/pkg/client/fake"
38+
. "sigs.k8s.io/controller-runtime/pkg/envtest/komega"
3839

3940
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
4041
runtimev1 "sigs.k8s.io/cluster-api/exp/runtime/api/v1alpha1"
@@ -46,12 +47,11 @@ import (
4647
"sigs.k8s.io/cluster-api/internal/hooks"
4748
fakeruntimeclient "sigs.k8s.io/cluster-api/internal/runtime/client/fake"
4849
"sigs.k8s.io/cluster-api/internal/test/builder"
49-
. "sigs.k8s.io/cluster-api/internal/test/matchers"
5050
)
5151

5252
var (
5353
IgnoreNameGenerated = IgnorePaths{
54-
{"metadata", "name"},
54+
"metadata.name",
5555
}
5656
)
5757

@@ -1580,7 +1580,7 @@ func TestReconcileControlPlaneMachineHealthCheck(t *testing.T) {
15801580
}
15811581

15821582
g.Expect(err).ToNot(HaveOccurred())
1583-
g.Expect(gotMHC).To(EqualObject(tt.want, IgnoreAutogeneratedMetadata, IgnorePaths{{"kind"}, {"apiVersion"}}))
1583+
g.Expect(gotMHC).To(EqualObject(tt.want, IgnoreAutogeneratedMetadata, IgnorePaths{".kind", ".apiVersion"}))
15841584
})
15851585
}
15861586
}
@@ -2718,7 +2718,7 @@ func TestReconciler_reconcileMachineHealthCheck(t *testing.T) {
27182718
}
27192719
}
27202720

2721-
g.Expect(got).To(EqualObject(tt.want, IgnoreAutogeneratedMetadata, IgnorePaths{{"kind"}, {"apiVersion"}}))
2721+
g.Expect(got).To(EqualObject(tt.want, IgnoreAutogeneratedMetadata, IgnorePaths{".kind", ".apiVersion"}))
27222722
})
27232723
}
27242724
}

internal/controllers/topology/cluster/util_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ import (
2525
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2626
"sigs.k8s.io/controller-runtime/pkg/client"
2727
"sigs.k8s.io/controller-runtime/pkg/client/fake"
28+
. "sigs.k8s.io/controller-runtime/pkg/envtest/komega"
2829

2930
"sigs.k8s.io/cluster-api/internal/contract"
3031
"sigs.k8s.io/cluster-api/internal/test/builder"
31-
. "sigs.k8s.io/cluster-api/internal/test/matchers"
3232
)
3333

3434
func TestGetReference(t *testing.T) {

internal/test/matchers/doc.go

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)