Skip to content

Commit d50289c

Browse files
authored
chore: refactor test reasons (#106)
* chore: refactor test reasons; enable and fix external-resource test that was disabled Signed-off-by: Jonathan Ogilvie <[email protected]> * test formatting fixes Signed-off-by: Jonathan Ogilvie <[email protected]> --------- Signed-off-by: Jonathan Ogilvie <[email protected]>
1 parent 99a6ef9 commit d50289c

File tree

4 files changed

+85
-52
lines changed

4 files changed

+85
-52
lines changed

cmd/diff/diff_integration_test.go

Lines changed: 68 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const (
4040

4141
// IntegrationTestCase represents a common test case structure for both XR and composition diff tests.
4242
type IntegrationTestCase struct {
43+
reason string // Description of what this test validates
4344
setupFiles []string
4445
setupFilesWithOwnerRefs []HierarchicalOwnershipRelation
4546
inputFiles []string // Input files to diff (XR YAML files or Composition YAML files)
@@ -269,7 +270,8 @@ func TestDiffIntegration(t *testing.T) {
269270
scheme := createTestScheme()
270271

271272
tests := map[string]IntegrationTestCase{
272-
"New resource shows color diff": {
273+
"NewResourceDiff": {
274+
reason: "Shows color diff for new resources",
273275
inputFiles: []string{"testdata/diff/new-xr.yaml"},
274276
setupFiles: []string{
275277
// TODO: For v2, we need to upgrade the XRD apiversion to v2 + put the xr in a namespace.
@@ -310,7 +312,8 @@ func TestDiffIntegration(t *testing.T) {
310312
}, ""),
311313
expectedError: false,
312314
},
313-
"Automatic namespace propagation for namespaced managed resources": {
315+
"AutomaticNamespacePropagation": {
316+
reason: "Validates automatic namespace propagation for namespaced managed resources",
314317
inputFiles: []string{"testdata/diff/new-xr.yaml"},
315318
setupFiles: []string{
316319
"testdata/diff/resources/xrd.yaml",
@@ -347,7 +350,8 @@ func TestDiffIntegration(t *testing.T) {
347350
}, ""),
348351
expectedError: false,
349352
},
350-
"Modified resource shows color diff": {
353+
"ModifiedResourceDiff": {
354+
reason: "Shows color diff for modified resources",
351355
setupFiles: []string{
352356
"testdata/diff/resources/xrd.yaml",
353357
"testdata/diff/resources/composition.yaml",
@@ -391,7 +395,8 @@ func TestDiffIntegration(t *testing.T) {
391395
Summary: 2 modified`,
392396
expectedError: false,
393397
},
394-
"Modified XR that creates new downstream resource shows color diff": {
398+
"ModifiedXRCreatesDownstream": {
399+
reason: "Shows color diff when modified XR creates new downstream resource",
395400
setupFiles: []string{
396401
"testdata/diff/resources/xrd.yaml",
397402
"testdata/diff/resources/composition.yaml",
@@ -431,7 +436,8 @@ Summary: 2 modified`,
431436
Summary: 1 added, 1 modified`,
432437
expectedError: false,
433438
},
434-
"EnvironmentConfig (v1beta1) incorporation in diff": {
439+
"EnvironmentConfigIncorporation": {
440+
reason: "Validates EnvironmentConfig (v1beta1) incorporation in diff",
435441
setupFiles: []string{
436442
"testdata/diff/resources/xdownstreamenvresource-xrd.yaml",
437443
"testdata/diff/resources/env-xrd.yaml",
@@ -478,7 +484,8 @@ Summary: 1 added, 1 modified`,
478484
expectedError: false,
479485
noColor: true,
480486
},
481-
"Diff with external resource dependencies via fn-external-resources": {
487+
"ExternalResourceDependencies": {
488+
reason: "Validates diff with external resource dependencies via fn-external-resources",
482489
// this test does a weird thing where it changes the XR but all the downstream changes come from external
483490
// resources, including a field path from the XR itself.
484491
setupFiles: []string{
@@ -528,7 +535,8 @@ Summary: 1 added, 1 modified`,
528535
expectedError: false,
529536
noColor: true,
530537
},
531-
"Diff with templated ExtraResources embedded in go-templating function": {
538+
"TemplatedExtraResources": {
539+
reason: "Validates diff with templated ExtraResources embedded in go-templating function",
532540
setupFiles: []string{
533541
"testdata/diff/resources/xrd.yaml",
534542
"testdata/diff/resources/functions.yaml",
@@ -575,10 +583,8 @@ Summary: 1 added, 1 modified`,
575583
expectedError: false,
576584
noColor: true,
577585
},
578-
"Cross-namespace resource dependencies via fn-external-resources": {
579-
skip: true,
580-
// TODO: we have updated this function now so we can fix the test
581-
skipReason: "function-extra-resources does not yet support namespace field for cross-namespace resource access",
586+
"CrossNamespaceResourceDependencies": {
587+
reason: "Validates cross-namespace resource dependencies via fn-external-resources",
582588
setupFiles: []string{
583589
"testdata/diff/resources/xrd.yaml",
584590
"testdata/diff/resources/functions.yaml",
@@ -615,16 +621,17 @@ Summary: 1 added, 1 modified`,
615621
namespace: default
616622
spec:
617623
- coolField: existing-cross-ns-value
618-
+ coolField: modified-cross-ns-value
619624
- environment: staging
625+
+ coolField: modified-cross-ns-value
620626
+ environment: production
621627
622628
---
623629
`,
624630
expectedError: false,
625631
noColor: true,
626632
},
627-
"Resource removal detection with hierarchy (v1 style resourceRefs; cluster scoped downstreams)": {
633+
"ResourceRemovalHierarchyV1ClusterScoped": {
634+
reason: "Validates resource removal detection with hierarchy using v1 style resourceRefs and cluster scoped downstreams",
628635
xrdAPIVersion: V1,
629636
setupFilesWithOwnerRefs: []HierarchicalOwnershipRelation{
630637
{
@@ -710,7 +717,8 @@ Summary: 2 modified, 2 removed`,
710717
expectedError: false,
711718
noColor: true,
712719
},
713-
"Resource removal detection with hierarchy (v2 style resourceRefs; namespaced downstreams)": {
720+
"ResourceRemovalHierarchyV2Namespaced": {
721+
reason: "Validates resource removal detection with hierarchy using v2 style resourceRefs and namespaced downstreams",
714722
setupFilesWithOwnerRefs: []HierarchicalOwnershipRelation{
715723
{
716724
OwnerFile: "testdata/diff/resources/existing-xr.yaml",
@@ -798,7 +806,8 @@ Summary: 2 modified, 2 removed`,
798806
expectedError: false,
799807
noColor: true,
800808
},
801-
"Resource removal detection with hierarchy (v2 style resourceRefs; cluster scoped downstreams)": {
809+
"ResourceRemovalHierarchyV2ClusterScoped": {
810+
reason: "Validates resource removal detection with hierarchy using v2 style resourceRefs and cluster scoped downstreams",
802811
setupFilesWithOwnerRefs: []HierarchicalOwnershipRelation{
803812
{
804813
OwnerFile: "testdata/diff/resources/existing-cluster-xr.yaml",
@@ -882,7 +891,8 @@ Summary: 2 modified, 2 removed`,
882891
expectedError: false,
883892
noColor: true,
884893
},
885-
"Resource with generateName": {
894+
"ResourceWithGenerateName": {
895+
reason: "Validates handling of resources with generateName",
886896
setupFiles: []string{
887897
"testdata/diff/resources/xrd.yaml",
888898
"testdata/diff/resources/functions.yaml",
@@ -933,7 +943,8 @@ Summary: 2 modified, 2 removed`,
933943
expectedError: false,
934944
noColor: true,
935945
},
936-
"New XR with generateName": {
946+
"NewXRWithGenerateName": {
947+
reason: "Shows diff for new XR with generateName",
937948
setupFiles: []string{
938949
"testdata/diff/resources/xrd.yaml",
939950
"testdata/diff/resources/composition.yaml",
@@ -971,7 +982,8 @@ Summary: 2 modified, 2 removed`,
971982
expectedError: false,
972983
noColor: true,
973984
},
974-
"Multiple XRs": {
985+
"MultipleXRs": {
986+
reason: "Validates diff for multiple XRs",
975987
setupFiles: []string{
976988
"testdata/diff/resources/xrd.yaml",
977989
"testdata/diff/resources/composition.yaml",
@@ -1046,6 +1058,7 @@ Summary: 2 added, 2 modified
10461058
noColor: true,
10471059
},
10481060
"SelectCompositionByDirectReference": {
1061+
reason: "Validates composition selection by direct reference",
10491062
setupFiles: []string{
10501063
"testdata/diff/resources/xrd.yaml",
10511064
"testdata/diff/resources/functions.yaml",
@@ -1090,6 +1103,7 @@ Summary: 2 added, 2 modified
10901103
noColor: true,
10911104
},
10921105
"SelectCompositionByLabelSelector": {
1106+
reason: "Validates composition selection by label selector",
10931107
setupFiles: []string{
10941108
"testdata/diff/resources/xrd.yaml",
10951109
"testdata/diff/resources/functions.yaml",
@@ -1136,7 +1150,8 @@ Summary: 2 added, 2 modified
11361150
expectedError: false,
11371151
noColor: true,
11381152
},
1139-
"Error on ambiguous composition selection": {
1153+
"AmbiguousCompositionSelection": {
1154+
reason: "Validates error on ambiguous composition selection",
11401155
setupFiles: []string{
11411156
"testdata/diff/resources/xrd.yaml",
11421157
"testdata/diff/resources/functions.yaml",
@@ -1153,6 +1168,7 @@ Summary: 2 added, 2 modified
11531168
noColor: true,
11541169
},
11551170
"NewClaimShowsDiff": {
1171+
reason: "Shows diff for new claim",
11561172
setupFiles: []string{
11571173
"testdata/diff/resources/existing-namespace.yaml",
11581174
// Add the necessary CRDs and compositions for claim diffing
@@ -1197,6 +1213,7 @@ Summary: 2 added`,
11971213
noColor: true,
11981214
},
11991215
"ModifiedClaimShowsDiff": {
1216+
reason: "Shows diff for modified claim",
12001217
setupFiles: []string{
12011218
"testdata/diff/resources/existing-namespace.yaml",
12021219
// Add necessary CRDs and composition
@@ -1248,7 +1265,8 @@ Summary: 2 modified`,
12481265
expectedError: false,
12491266
noColor: true,
12501267
},
1251-
"XRD defaults should be applied to XR before rendering": {
1268+
"XRDDefaultsAppliedBeforeRendering": {
1269+
reason: "Validates that XRD defaults are applied to XR before rendering",
12521270
inputFiles: []string{"testdata/diff/xr-with-missing-defaults.yaml"},
12531271
setupFiles: []string{
12541272
"testdata/diff/resources/xrd-with-defaults.yaml",
@@ -1279,7 +1297,8 @@ Summary: 1 added`,
12791297
expectedError: false,
12801298
noColor: true,
12811299
},
1282-
"XRD defaults should not override user-specified values": {
1300+
"XRDDefaultsNoOverride": {
1301+
reason: "Validates that XRD defaults do not override user-specified values",
12831302
inputFiles: []string{"testdata/diff/xr-with-overridden-defaults.yaml"},
12841303
setupFiles: []string{
12851304
"testdata/diff/resources/xrd-with-defaults.yaml",
@@ -1311,7 +1330,8 @@ Summary: 1 added`,
13111330
expectedError: false,
13121331
noColor: true,
13131332
},
1314-
"Concurrent rendering with multiple functions and XRs from directory": {
1333+
"ConcurrentRenderingMultipleXRs": {
1334+
reason: "Validates concurrent rendering with multiple functions and XRs from directory",
13151335
// This test reproduces issue #59 - concurrent function startup failures
13161336
// when processing multiple XR files from a directory
13171337
inputFiles: []string{
@@ -1331,7 +1351,8 @@ Summary: 1 added`,
13311351
expectedError: false,
13321352
noColor: true,
13331353
},
1334-
"New nested XR creates child XR and downstream resources": {
1354+
"NewNestedXRCreatesChildren": {
1355+
reason: "Validates that new nested XR creates child XR and downstream resources",
13351356
setupFiles: []string{
13361357
// XRDs for parent and child
13371358
"testdata/diff/resources/nested/parent-xrd.yaml",
@@ -1389,7 +1410,8 @@ Summary: 3 added`,
13891410
expectedError: false,
13901411
noColor: true,
13911412
},
1392-
"Modified nested XR propagates changes through child XR to downstream resources": {
1413+
"ModifiedNestedXRPropagatesChanges": {
1414+
reason: "Validates that modified nested XR propagates changes through child XR to downstream resources",
13931415
setupFiles: []string{
13941416
// XRDs for parent and child
13951417
"testdata/diff/resources/nested/parent-xrd.yaml",
@@ -1460,7 +1482,8 @@ Summary: 3 modified`,
14601482
noColor: true,
14611483
},
14621484
// Composition Revision tests for v2 XRDs
1463-
"v2 XR with Manual update policy stays on pinned revision": {
1485+
"V2ManualPolicyPinnedRevision": {
1486+
reason: "Validates v2 XR with Manual update policy stays on pinned revision",
14641487
setupFiles: []string{
14651488
"testdata/diff/resources/xrd.yaml",
14661489
"testdata/diff/resources/composition-revision-v1.yaml",
@@ -1510,7 +1533,8 @@ Summary: 3 modified`,
15101533
expectedError: false,
15111534
noColor: true,
15121535
},
1513-
"v2 XR with Automatic update policy uses latest revision": {
1536+
"V2AutomaticPolicyLatestRevision": {
1537+
reason: "Validates v2 XR with Automatic update policy uses latest revision",
15141538
setupFiles: []string{
15151539
"testdata/diff/resources/xrd.yaml",
15161540
"testdata/diff/resources/composition-revision-v1.yaml",
@@ -1560,7 +1584,8 @@ Summary: 3 modified`,
15601584
expectedError: false,
15611585
noColor: true,
15621586
},
1563-
"v2 XR changing revision in Manual mode shows upgrade diff": {
1587+
"V2ManualRevisionUpgradeDiff": {
1588+
reason: "Validates v2 XR changing revision in Manual mode shows upgrade diff",
15641589
setupFiles: []string{
15651590
"testdata/diff/resources/xrd.yaml",
15661591
"testdata/diff/resources/composition-revision-v1.yaml",
@@ -1611,7 +1636,8 @@ Summary: 3 modified`,
16111636
expectedError: false,
16121637
noColor: true,
16131638
},
1614-
"v2 XR switching from Manual to Automatic mode uses latest revision": {
1639+
"V2SwitchManualToAutomatic": {
1640+
reason: "Validates v2 XR switching from Manual to Automatic mode uses latest revision",
16151641
setupFiles: []string{
16161642
"testdata/diff/resources/xrd.yaml",
16171643
"testdata/diff/resources/composition-revision-v1.yaml",
@@ -1662,7 +1688,8 @@ Summary: 3 modified`,
16621688
expectedError: false,
16631689
noColor: true,
16641690
},
1665-
"v2 Net new XR with Manual policy but no revision ref uses latest revision": {
1691+
"V2NetNewManualNoRevRef": {
1692+
reason: "Validates v2 net new XR with Manual policy but no revision ref uses latest revision",
16661693
setupFiles: []string{
16671694
"testdata/diff/resources/xrd.yaml",
16681695
"testdata/diff/resources/composition-revision-v1.yaml",
@@ -1707,7 +1734,8 @@ Summary: 2 added`,
17071734
noColor: true,
17081735
},
17091736
// Composition Revision tests for v1 XRDs (Crossplane 1.20 compatibility)
1710-
"v1 XR with Manual update policy changing revision shows upgrade diff": {
1737+
"V1ManualRevisionUpgradeDiff": {
1738+
reason: "Validates v1 XR with Manual update policy changing revision shows upgrade diff",
17111739
xrdAPIVersion: V1,
17121740
setupFiles: []string{
17131741
"testdata/diff/resources/legacy-xrd.yaml",
@@ -1779,7 +1807,8 @@ func TestCompDiffIntegration(t *testing.T) {
17791807
scheme := createTestScheme()
17801808

17811809
tests := map[string]IntegrationTestCase{
1782-
"Composition change impacts existing XRs": {
1810+
"CompositionChangeImpactsXRs": {
1811+
reason: "Validates composition change impacts existing XRs",
17831812
// Set up existing XRs that use the original composition
17841813
setupFiles: []string{
17851814
"testdata/comp/resources/xrd.yaml",
@@ -1888,7 +1917,8 @@ Summary: 2 modified`,
18881917
expectedError: false,
18891918
noColor: true,
18901919
},
1891-
"Composition diff with custom namespace": {
1920+
"CompositionDiffCustomNamespace": {
1921+
reason: "Validates composition diff with custom namespace",
18921922
// Set up existing XRs in both custom and default namespaces to validate filtering
18931923
setupFiles: []string{
18941924
"testdata/comp/resources/xrd.yaml",
@@ -1982,7 +2012,8 @@ Summary: 1 modified`,
19822012
expectedError: false,
19832013
noColor: true,
19842014
},
1985-
"Multiple composition diff shows impact on existing XRs": {
2015+
"MultipleCompositionDiffImpact": {
2016+
reason: "Validates multiple composition diff shows impact on existing XRs",
19862017
// Set up existing XRs that use both compositions
19872018
setupFiles: []string{
19882019
"testdata/comp/resources/xrd.yaml",
@@ -2103,7 +2134,8 @@ No XRs found using composition xnopresources-v2.diff.example.org`,
21032134
expectedError: false,
21042135
noColor: true,
21052136
},
2106-
"Composition diff filters Manual policy XRs by default": {
2137+
"CompositionDiffFiltersManualXRs": {
2138+
reason: "Validates composition diff filters Manual policy XRs by default",
21072139
// Set up existing XRs - one with Automatic policy and one with Manual policy
21082140
setupFiles: []string{
21092141
"testdata/comp/resources/xrd.yaml",
@@ -2195,7 +2227,8 @@ Summary: 1 modified`,
21952227
expectedError: false,
21962228
noColor: true,
21972229
},
2198-
"Net-new composition with no downstream impact": {
2230+
"NetNewCompositionNoImpact": {
2231+
reason: "Validates net-new composition with no downstream impact",
21992232
// Set up cluster with existing resources but no composition that matches the new one
22002233
setupFiles: []string{
22012234
"testdata/comp/resources/xrd.yaml",

0 commit comments

Comments
 (0)