Skip to content

Commit 0e55b04

Browse files
committed
feat: add custom upgrade testing functionality.
1 parent 9cb21b5 commit 0e55b04

File tree

5 files changed

+519
-123
lines changed

5 files changed

+519
-123
lines changed

Makefile

Lines changed: 90 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,15 @@ test-acceptance: $(KIND) $(HELM3) build
182182
# Upgrade test directory
183183
UPGRADE_TEST_DIR := test/upgrade
184184
UPGRADE_TEST_CRS_DIR := $(UPGRADE_TEST_DIR)/testdata/baseCrs
185+
UPGRADE_TEST_CUSTOM_CRS_DIR := $(UPGRADE_TEST_DIR)/testdata/customCRs
185186
UPGRADE_TEST_OUTPUT_LOG := test-upgrade-output.log
186187

187188
# If UPGRADE_TEST_CRS_TAG is not set, use UPGRADE_TEST_FROM_TAG as default
188189
UPGRADE_TEST_CRS_TAG ?= $(UPGRADE_TEST_FROM_TAG)
189190

191+
# Test filter for running specific tests
192+
UPGRADE_TEST_FILTER ?= .
193+
190194
.PHONY: check-upgrade-test-vars
191195
check-upgrade-test-vars: ## Verify required upgrade test environment variables
192196
@test -n "$(UPGRADE_TEST_FROM_TAG)" || { echo "❌ Set UPGRADE_TEST_FROM_TAG"; exit 1; }
@@ -208,9 +212,47 @@ test-upgrade-compile: ## Verify upgrade tests compile
208212
@cd $(UPGRADE_TEST_DIR) && go test -c -tags=upgrade -o /dev/null
209213
@$(OK) upgrade tests compile successfully
210214

211-
.PHONY: test-upgrade
212-
test-upgrade: $(KIND) check-upgrade-test-vars build-upgrade-test-images ## Run upgrade tests
215+
# ====================================================================================
216+
# Base Upgrade Tests (Standard Resource Verification)
217+
# ====================================================================================
218+
219+
220+
.PHONY: test-upgrade-base
221+
test-upgrade-base: $(KIND) check-upgrade-test-vars build-upgrade-test-images ## Run upgrade tests (standard resource verification )
213222
@$(INFO) running upgrade tests from $(UPGRADE_TEST_FROM_TAG) to $(UPGRADE_TEST_TO_TAG)
223+
@cd $(UPGRADE_TEST_DIR) && go test -v -tags=upgrade -timeout=45m -run TestUpgradeProvider ./... 2>&1 | tee ../../$(UPGRADE_TEST_OUTPUT_LOG)
224+
@echo "==========Base Upgrade Test Summary =========="
225+
@grep -E "PASS|FAIL|ok " $(UPGRADE_TEST_OUTPUT_LOG) | tail -5
226+
@case `tail -n 1 $(UPGRADE_TEST_OUTPUT_LOG)` in \
227+
*FAIL*) echo "❌ Upgrade test failed"; exit 1 ;; \
228+
*ok*) echo "✅ Upgrade tests passed"; $(OK) upgrade tests passed ;; \
229+
*) echo "⚠️ Could not determine test result"; exit 1 ;; \
230+
esac
231+
232+
# ====================================================================================
233+
# Custom Upgrade Tests (External-Name Validation, etc.)
234+
# ====================================================================================
235+
236+
.PHONY: test-upgrade-custom
237+
test-upgrade-custom: $(KIND) check-upgrade-test-vars build-upgrade-test-images ## Run custom upgrade tests (external-name validation, etc.)
238+
@$(INFO) running custom upgrade tests from $(UPGRADE_TEST_FROM_TAG) to $(UPGRADE_TEST_TO_TAG)
239+
@$(INFO) test filter: $(UPGRADE_TEST_FILTER)
240+
@cd $(UPGRADE_TEST_DIR) && go test -v -tags=upgrade -timeout=45m -run '$(UPGRADE_TEST_FILTER)' ./... 2>&1 | tee ../../$(UPGRADE_TEST_OUTPUT_LOG)
241+
@echo "========== Custom Upgrade Test Summary =========="
242+
@grep -E "PASS|FAIL|ok " $(UPGRADE_TEST_OUTPUT_LOG) | tail -5
243+
@case `tail -n 1 $(UPGRADE_TEST_OUTPUT_LOG)` in \
244+
*FAIL*) echo "❌ Custom upgrade test failed"; exit 1 ;; \
245+
*ok*) echo "✅ Custom upgrade tests passed"; $(OK) custom upgrade tests passed ;; \
246+
*) echo "⚠️ Could not determine test result"; exit 1 ;; \
247+
esac
248+
249+
# ====================================================================================
250+
# Combined: Run All Upgrade Tests
251+
# ====================================================================================
252+
253+
.PHONY: test-upgrade
254+
test-upgrade: $(KIND) check-upgrade-test-vars build-upgrade-test-images ## Run ALL upgrade tests (base + custom)
255+
@$(INFO) running all upgrade tests from $(UPGRADE_TEST_FROM_TAG) to $(UPGRADE_TEST_TO_TAG)
214256
@cd $(UPGRADE_TEST_DIR) && go test -v -tags=upgrade -timeout=45m ./... 2>&1 | tee ../../$(UPGRADE_TEST_OUTPUT_LOG)
215257
@echo "========== Upgrade Test Summary =========="
216258
@grep -E "PASS|FAIL|ok " $(UPGRADE_TEST_OUTPUT_LOG) | tail -5
@@ -220,6 +262,11 @@ test-upgrade: $(KIND) check-upgrade-test-vars build-upgrade-test-images ## Run u
220262
*) echo "⚠️ Could not determine test result"; exit 1 ;; \
221263
esac
222264

265+
266+
# ====================================================================================
267+
# CR Preparation
268+
# ====================================================================================
269+
223270
.PHONY: test-upgrade-prepare-crs
224271
test-upgrade-prepare-crs: ## Prepare CRs from CRS_TAG version
225272
@$(INFO) preparing CRs from $(UPGRADE_TEST_CRS_TAG)
@@ -232,7 +279,7 @@ test-upgrade-prepare-crs: ## Prepare CRs from CRS_TAG version
232279
mkdir -p $(UPGRADE_TEST_CRS_DIR); \
233280
if git ls-tree -r $(UPGRADE_TEST_CRS_TAG) --name-only | grep -q "^$(UPGRADE_TEST_CRS_DIR)/"; then \
234281
$(INFO) "✅ Found $(UPGRADE_TEST_CRS_DIR)/ in $(UPGRADE_TEST_CRS_TAG)"; \
235-
git archive $(UPGRADE_TEST_CRS_TAG) $(UPGRADE_TEST_CRS_DIR)/ | tar -x --strip-components=2 -C $(UPGRADE_TEST_CRS_DIR)/; \
282+
git archive $(UPGRADE_TEST_CRS_TAG) $(UPGRADE_TEST_CRS_DIR)/ | tar -x --strip-components=4 -C $(UPGRADE_TEST_CRS_DIR)/; \
236283
$(OK) "Copied all CRs from $(UPGRADE_TEST_CRS_DIR)/"; \
237284
else \
238285
$(INFO) "⚠️ $(UPGRADE_TEST_CRS_DIR)/ not found, using hardcoded e2e paths"; \
@@ -243,6 +290,10 @@ test-upgrade-prepare-crs: ## Prepare CRs from CRS_TAG version
243290
$(OK) "Copied e2e CRs to $(UPGRADE_TEST_CRS_DIR)/"; \
244291
fi; \
245292
fi
293+
294+
# ====================================================================================
295+
# Upgrade Tests with Version-Specific CRs
296+
# ====================================================================================
246297

247298
.PHONY: test-upgrade-with-version-crs
248299
test-upgrade-with-version-crs: $(KIND) check-upgrade-test-vars build-upgrade-test-images test-upgrade-prepare-crs ## Run upgrade tests with FROM version CRs
@@ -256,13 +307,22 @@ test-upgrade-with-version-crs: $(KIND) check-upgrade-test-vars build-upgrade-tes
256307
*) echo "⚠️ Could not determine test result"; exit 1; ;; \
257308
esac
258309

310+
# ====================================================================================
311+
# Debugging Support
312+
# ====================================================================================
313+
314+
# TODO: Add test-upgrade-debug-base and test-upgrade-debug-custom variants
315+
259316
.PHONY: test-upgrade-debug
260317
test-upgrade-debug: $(KIND) check-upgrade-test-vars build-upgrade-test-images test-upgrade-prepare-crs ## Run upgrade tests with debugger
261318
@$(INFO) running upgrade tests with debugger
262319
@cd $(UPGRADE_TEST_DIR) && dlv test -tags=upgrade . --listen=:2345 --headless=true --api-version=2 --build-flags="-tags=upgrade" -- -test.v -test.timeout 45m 2>&1 | tee ../../$(UPGRADE_TEST_OUTPUT_LOG)
263320
@echo "========== Upgrade Test Summary =========="
264321
@grep -E "PASS|FAIL|ok " $(UPGRADE_TEST_OUTPUT_LOG) | tail -5
265322

323+
# ====================================================================================
324+
# Utility Targets
325+
# ====================================================================================
266326

267327
.PHONY: test-upgrade-restore-crs
268328
test-upgrade-restore-crs: ## Restore $(UPGRADE_TEST_CRS_DIR)/ to current version
@@ -284,49 +344,51 @@ test-upgrade-help: ## Show upgrade test usage examples
284344
@$(INFO) "Upgrade Test Examples:"
285345
@$(INFO) "======================"
286346
@$(INFO) ""
287-
@$(INFO) " 1. Test between two releases:"
347+
@$(INFO) " 1. Run ALL upgrade tests (base + custom):"
288348
@$(INFO) " export UPGRADE_TEST_FROM_TAG=v0.3.2"
289349
@$(INFO) " export UPGRADE_TEST_TO_TAG=v0.4.0"
290350
@$(INFO) " make test-upgrade"
291351
@$(INFO) ""
292-
@$(INFO) " 2. Test local changes (v0.3.2 -> your code):"
352+
@$(INFO) " 2. Run ONLY base upgrade tests:"
293353
@$(INFO) " export UPGRADE_TEST_FROM_TAG=v0.3.2"
294-
@$(INFO) " export UPGRADE_TEST_TO_TAG=local"
295-
@$(INFO) " make test-upgrade"
354+
@$(INFO) " export UPGRADE_TEST_TO_TAG=v0.4.0"
355+
@$(INFO) " make test-upgrade-base"
356+
@$(INFO) ""
357+
@$(INFO) " 3. Run ONLY custom upgrade tests:"
358+
@$(INFO) " export UPGRADE_TEST_FROM_TAG=v0.3.2"
359+
@$(INFO) " export UPGRADE_TEST_TO_TAG=v0.4.0"
360+
@$(INFO) " make test-upgrade-custom"
296361
@$(INFO) ""
297-
@$(INFO) " 3. Manual upgrade test (no CR checkout):"
362+
@$(INFO) " 4. Run specific custom test:"
298363
@$(INFO) " export UPGRADE_TEST_FROM_TAG=v0.3.2"
299364
@$(INFO) " export UPGRADE_TEST_TO_TAG=v0.4.0"
365+
@$(INFO) " export UPGRADE_TEST_FILTER='Test_Space_External_Name'"
366+
@$(INFO) " make test-upgrade-custom"
367+
@$(INFO) ""
368+
@$(INFO) " 5. Test local changes (v0.3.2 -> your code):"
369+
@$(INFO) " export UPGRADE_TEST_FROM_TAG=v0.3.2"
370+
@$(INFO) " export UPGRADE_TEST_TO_TAG=local"
300371
@$(INFO) " make test-upgrade"
301-
@$(INFO) " Note: Uses current $(UPGRADE_TEST_CRS_DIR) (may fail if incompatible)"
302372
@$(INFO) ""
303-
@$(INFO) " 4. Clean up test artifacts:"
373+
@$(INFO) " 6. Clean up test artifacts:"
304374
@$(INFO) " make test-upgrade-clean"
305375
@$(INFO) ""
306-
@$(INFO) " 5. Restore CRs after version checkout:"
376+
@$(INFO) " 7. Restore CRs after version checkout:"
307377
@$(INFO) " make test-upgrade-restore-crs"
308378
@$(INFO) ""
309379
@$(INFO) "Required Environment Variables:"
310380
@$(INFO) " CF_EMAIL, CF_USERNAME, CF_PASSWORD, CF_ENDPOINT"
311381
@$(INFO) " UPGRADE_TEST_FROM_TAG, UPGRADE_TEST_TO_TAG"
312382
@$(INFO) ""
313383
@$(INFO) "Optional Environment Variables:"
314-
@$(INFO) " UPGRADE_TEST_CRS_PATH (default: $(UPGRADE_TEST_CRS_DIR))"
315-
@$(INFO) " UPGRADE_TEST_VERIFY_TIMEOUT (default: 30 minutes)"
316-
@$(INFO) " UPGRADE_TEST_WAIT_FOR_PAUSE (default: 1 minute)"
384+
@$(INFO) " UPGRADE_TEST_FILTER (default: '.' - runs all tests)"
385+
@$(INFO) " UPGRADE_TEST_CRS_TAG (default: UPGRADE_TEST_FROM_TAG)"
317386
@$(INFO) ""
318-
@$(INFO) "How CRS Checkout Works (test-upgrade-with-version-crs):"
319-
@$(INFO) "========================================================"
320-
@$(INFO) " 1. If FROM_TAG is 'local': Uses current $(UPGRADE_TEST_CRS_DIR)/"
321-
@$(INFO) " 2. If FROM_TAG has $(UPGRADE_TEST_CRS_DIR)/: Copies entire directory"
387+
@$(INFO) "Test Types:"
388+
@$(INFO) "==========="
389+
@$(INFO) " Base Tests: Standard resource verification (TestUpgradeProvider)"
390+
@$(INFO) " Custom Tests: External-name validation (Test_Space_External_Name, etc.)"
322391
@$(INFO) ""
323-
@$(INFO) ""
324-
@$(INFO) "⚠️ IMPORTANT NOTES:"
325-
@$(INFO) " - test-upgrade-with-version-crs OVERWRITES $(UPGRADE_TEST_CRS_DIR)/"
326-
@$(INFO) " - test-upgrade-restore-crs will to restore your files"
327-
@$(INFO) " - E2E CRs (fallback) may have complex dependencies - test might fail"
328-
@$(INFO) ""
329-
330392

331393
# ====================================================================================
332394
# Special Targets
@@ -338,7 +400,9 @@ Crossplane Targets:
338400
run Run crossplane locally, out-of-cluster. Useful for development.
339401

340402
Upgrade Testing:
341-
test-upgrade Run upgrade tests (requires env vars)
403+
test-upgrade Run ALL upgrade tests (requires env vars, base + custom)
404+
test-upgrade-base Run base upgrade tests only
405+
test-upgrade-custom Run custom upgrade tests only (external-name validation, etc.)
342406
test-upgrade-with-version-crs Run upgrade tests with auto CR checkout
343407
test-upgrade-compile Verify upgrade tests compile
344408
test-upgrade-debug Run upgrade tests with debugger

test/test_utils.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"fmt"
77
"os"
8+
"regexp"
89
"testing"
910

1011
"github.com/crossplane-contrib/xp-testing/pkg/envvar"
@@ -38,6 +39,7 @@ var (
3839
UUT_IMAGES_KEY = "UUT_IMAGES"
3940
UUT_CONFIG_KEY = "crossplane/provider-cloudfoundry"
4041
UUT_CONTROLLER_KEY = "crossplane/provider-cloudfoundry-controller"
42+
UUIDRegex = regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$`)
4143
)
4244

4345
type mockList struct {

0 commit comments

Comments
 (0)