From 43558bb5211f5a015106a932e0a29792d845220a Mon Sep 17 00:00:00 2001 From: Chuan-Yen Chiang Date: Fri, 10 Apr 2026 22:54:13 +0200 Subject: [PATCH] Add e2e Signed-off-by: Chuan-Yen Chiang --- Makefile | 14 ++++-- build | 2 +- test/e2e/00-lifecycle.yaml | 16 ++++++ test/e2e/hooks/post-assert-lifecycle.sh | 65 +++++++++++++++++++++++++ test/e2e/hooks/pre-delete-lifecycle.sh | 25 ++++++++++ test/setup.sh | 62 +++++++++++++++++++++++ 6 files changed, 180 insertions(+), 4 deletions(-) create mode 100644 test/e2e/00-lifecycle.yaml create mode 100755 test/e2e/hooks/post-assert-lifecycle.sh create mode 100755 test/e2e/hooks/pre-delete-lifecycle.sh create mode 100755 test/setup.sh diff --git a/Makefile b/Makefile index 01874de..c8b09e9 100644 --- a/Makefile +++ b/Makefile @@ -44,6 +44,17 @@ XPKG_REG_ORGS_NO_PROMOTE ?= xpkg.upbound.io/crossplane XPKGS = provider-template -include build/makelib/xpkg.mk +# ==================================================================================== +# Setup Uptest + +CROSSPLANE_VERSION ?= 2.2.0 +-include build/makelib/local.xpkg.mk +-include build/makelib/controlplane.mk + +UPTEST_LOCAL_DEPLOY_TARGET = local.xpkg.deploy.provider.$(PROJECT_NAME) +UPTEST_INPUT_MANIFESTS = test/e2e/00-lifecycle.yaml +-include build/makelib/uptest.mk + # NOTE(hasheddan): we force image building to happen prior to xpkg build so that # we ensure image is present in daemon. xpkg.build.provider-template: do.build.images @@ -52,9 +63,6 @@ fallthrough: submodules @echo Initial setup complete. Running make again . . . @make -# integration tests -e2e.run: test-integration - # Run integration tests. test-integration: $(KIND) $(KUBECTL) $(CROSSPLANE_CLI) $(HELM3) @$(INFO) running integration tests using kind $(KIND_VERSION) diff --git a/build b/build index b964dbe..65819b0 160000 --- a/build +++ b/build @@ -1 +1 @@ -Subproject commit b964dbe0ff0856a762f1a06fe554c647d22af7f0 +Subproject commit 65819b05239a0b22f1a98c3698a14acd22bc3cc0 diff --git a/test/e2e/00-lifecycle.yaml b/test/e2e/00-lifecycle.yaml new file mode 100644 index 0000000..404b2a6 --- /dev/null +++ b/test/e2e/00-lifecycle.yaml @@ -0,0 +1,16 @@ +apiVersion: sample.template.crossplane.io/v1alpha1 +kind: MyType +metadata: + name: e2e-lifecycle-test + namespace: default + annotations: + uptest.upbound.io/timeout: "120" + uptest.upbound.io/conditions: "Ready" + uptest.upbound.io/post-assert-hook: "hooks/post-assert-lifecycle.sh" + uptest.upbound.io/pre-delete-hook: "hooks/pre-delete-lifecycle.sh" +spec: + forProvider: + configurableField: "initial-value" + providerConfigRef: + name: example + kind: ProviderConfig diff --git a/test/e2e/hooks/post-assert-lifecycle.sh b/test/e2e/hooks/post-assert-lifecycle.sh new file mode 100755 index 0000000..a78bb78 --- /dev/null +++ b/test/e2e/hooks/post-assert-lifecycle.sh @@ -0,0 +1,65 @@ +#!/usr/bin/env bash +set -euo pipefail + +RESOURCE_NAME="e2e-lifecycle-test" +NAMESPACE="default" + +# Verify status and external-name are set +CONFIGURED=$(${KUBECTL} get mytype "${RESOURCE_NAME}" -n "${NAMESPACE}" \ + -o jsonpath='{.status.atProvider.configurableField}') + +if [[ -z "${CONFIGURED}" ]]; then + echo "FAIL: status.atProvider.configurableField is empty" + exit 1 +fi +echo "PASS: status.atProvider.configurableField = ${CONFIGURED}" + +EXTERNAL_NAME=$(${KUBECTL} get mytype "${RESOURCE_NAME}" -n "${NAMESPACE}" \ + -o jsonpath='{.metadata.annotations.crossplane\.io/external-name}') + +if [[ -z "${EXTERNAL_NAME}" ]]; then + echo "FAIL: external-name annotation is not set" + exit 1 +fi +echo "PASS: external-name = ${EXTERNAL_NAME}" + +# ---- Error case: MyType with non-existent ProviderConfig ---- +echo "" +echo "Testing error case: MyType with missing ProviderConfig..." + +ERROR_RESOURCE="e2e-error-no-config" + +# Ensure cleanup on any exit, preserving the original exit code +trap 'rc=$?; ${KUBECTL} delete mytype "${ERROR_RESOURCE}" -n "${NAMESPACE}" --ignore-not-found || true; exit $rc' EXIT + +cat <