From 3ce600ea73f4d914bc6c1f728ceb0189ae917324 Mon Sep 17 00:00:00 2001 From: Christopher Haar Date: Sun, 9 Feb 2025 14:19:14 +0100 Subject: [PATCH 1/2] feat(compositiontest): add composition tests Signed-off-by: Christopher Haar --- apis/xstoragebuckets/definition.yaml | 1 + examples/storagebucket/providerconfig.yaml | 11 -- .../example.yaml | 4 +- tests/test-xstoragebucket-default/kcl.mod | 6 + .../test-xstoragebucket-default/kcl.mod.lock | 12 ++ tests/test-xstoragebucket-default/main.k | 17 +++ tests/test-xstoragebucket-default/model | 1 + tests/test-xstoragebucket-versioning/kcl.mod | 6 + .../kcl.mod.lock | 12 ++ tests/test-xstoragebucket-versioning/main.k | 97 ++++++++++++++++ tests/test-xstoragebucket-versioning/model | 1 + tests/test-xstoragebucket/kcl.mod | 6 + tests/test-xstoragebucket/kcl.mod.lock | 12 ++ tests/test-xstoragebucket/main.k | 104 ++++++++++++++++++ tests/test-xstoragebucket/model | 1 + 15 files changed, 277 insertions(+), 14 deletions(-) delete mode 100644 examples/storagebucket/providerconfig.yaml rename examples/{storagebucket => xstoragebuckets}/example.yaml (67%) create mode 100644 tests/test-xstoragebucket-default/kcl.mod create mode 100644 tests/test-xstoragebucket-default/kcl.mod.lock create mode 100644 tests/test-xstoragebucket-default/main.k create mode 120000 tests/test-xstoragebucket-default/model create mode 100644 tests/test-xstoragebucket-versioning/kcl.mod create mode 100644 tests/test-xstoragebucket-versioning/kcl.mod.lock create mode 100644 tests/test-xstoragebucket-versioning/main.k create mode 120000 tests/test-xstoragebucket-versioning/model create mode 100644 tests/test-xstoragebucket/kcl.mod create mode 100644 tests/test-xstoragebucket/kcl.mod.lock create mode 100644 tests/test-xstoragebucket/main.k create mode 120000 tests/test-xstoragebucket/model diff --git a/apis/xstoragebuckets/definition.yaml b/apis/xstoragebuckets/definition.yaml index 1361b8f..66283a3 100644 --- a/apis/xstoragebuckets/definition.yaml +++ b/apis/xstoragebuckets/definition.yaml @@ -28,6 +28,7 @@ spec: type: string region: type: string + default: "us-west-1" versioning: type: boolean type: object diff --git a/examples/storagebucket/providerconfig.yaml b/examples/storagebucket/providerconfig.yaml deleted file mode 100644 index 1351275..0000000 --- a/examples/storagebucket/providerconfig.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: aws.upbound.io/v1beta1 -kind: ProviderConfig -metadata: - name: default -spec: - credentials: - source: Secret - secretRef: - namespace: crossplane-system - name: aws-secret - key: my-aws-secret diff --git a/examples/storagebucket/example.yaml b/examples/xstoragebuckets/example.yaml similarity index 67% rename from examples/storagebucket/example.yaml rename to examples/xstoragebuckets/example.yaml index fdd8545..67e14b6 100644 --- a/examples/storagebucket/example.yaml +++ b/examples/xstoragebuckets/example.yaml @@ -1,10 +1,8 @@ apiVersion: platform.example.com/v1alpha1 -kind: StorageBucket +kind: XStorageBucket metadata: name: example - namespace: default spec: parameters: - region: us-west-1 versioning: true acl: public-read diff --git a/tests/test-xstoragebucket-default/kcl.mod b/tests/test-xstoragebucket-default/kcl.mod new file mode 100644 index 0000000..03d12bf --- /dev/null +++ b/tests/test-xstoragebucket-default/kcl.mod @@ -0,0 +1,6 @@ +[package] +name = "test-xstoragebucket" +version = "0.0.1" + +[dependencies] +models = { path = "./model" } \ No newline at end of file diff --git a/tests/test-xstoragebucket-default/kcl.mod.lock b/tests/test-xstoragebucket-default/kcl.mod.lock new file mode 100644 index 0000000..7756095 --- /dev/null +++ b/tests/test-xstoragebucket-default/kcl.mod.lock @@ -0,0 +1,12 @@ +[dependencies] + [dependencies.model] + name = "model" + full_name = "models_0.0.1" + version = "0.0.1" + reg = "ghcr.io" + repo = "kcl-lang/model" + oci_tag = "0.0.1" + [dependencies.models] + name = "models" + full_name = "models_0.0.1" + version = "0.0.1" diff --git a/tests/test-xstoragebucket-default/main.k b/tests/test-xstoragebucket-default/main.k new file mode 100644 index 0000000..28ba8b4 --- /dev/null +++ b/tests/test-xstoragebucket-default/main.k @@ -0,0 +1,17 @@ + +import models.io.upbound.dev.meta.v1alpha1 as metav1alpha1 + +_items = [ + metav1alpha1.CompositionTest{ + metadata.name="test-xstoragebucket-default" + spec= { + assert: [] + compositionPath: "apis/xstoragebuckets/composition.yaml" + xrPath: "examples/xstoragebuckets/example.yaml" + xrdPath: "apis/xstoragebuckets/definition.yaml" + timeoutSeconds: 120 + validate: False + } + } +] +items = _items diff --git a/tests/test-xstoragebucket-default/model b/tests/test-xstoragebucket-default/model new file mode 120000 index 0000000..faff6e4 --- /dev/null +++ b/tests/test-xstoragebucket-default/model @@ -0,0 +1 @@ +../../.up/kcl/models \ No newline at end of file diff --git a/tests/test-xstoragebucket-versioning/kcl.mod b/tests/test-xstoragebucket-versioning/kcl.mod new file mode 100644 index 0000000..03d12bf --- /dev/null +++ b/tests/test-xstoragebucket-versioning/kcl.mod @@ -0,0 +1,6 @@ +[package] +name = "test-xstoragebucket" +version = "0.0.1" + +[dependencies] +models = { path = "./model" } \ No newline at end of file diff --git a/tests/test-xstoragebucket-versioning/kcl.mod.lock b/tests/test-xstoragebucket-versioning/kcl.mod.lock new file mode 100644 index 0000000..7756095 --- /dev/null +++ b/tests/test-xstoragebucket-versioning/kcl.mod.lock @@ -0,0 +1,12 @@ +[dependencies] + [dependencies.model] + name = "model" + full_name = "models_0.0.1" + version = "0.0.1" + reg = "ghcr.io" + repo = "kcl-lang/model" + oci_tag = "0.0.1" + [dependencies.models] + name = "models" + full_name = "models_0.0.1" + version = "0.0.1" diff --git a/tests/test-xstoragebucket-versioning/main.k b/tests/test-xstoragebucket-versioning/main.k new file mode 100644 index 0000000..d385a6e --- /dev/null +++ b/tests/test-xstoragebucket-versioning/main.k @@ -0,0 +1,97 @@ + +import models.com.example.platform.v1alpha1 as platformv1alpha1 +import models.io.upbound.aws.s3.v1beta1 as s3v1beta1 +import models.io.upbound.dev.meta.v1alpha1 as metav1alpha1 + +_items = [ + metav1alpha1.CompositionTest{ + metadata.name="test-xstoragebucket" + spec= { + assert: [ + platformv1alpha1.XStorageBucket{ + metadata.name: "example" + spec.parameters: { + acl: "public-read" + region: "eu-central-1" + versioning: False + } + } + s3v1beta1.BucketACL{ + metadata.name: "example-acl" + spec.forProvider:{ + acl: "public-read" + bucketRef: { + name: "example-bucket" + } + region: "eu-central-1" + } + } + s3v1beta1.BucketOwnershipControls{ + metadata.name: "example-boc" + spec.forProvider: { + bucketRef: { + name: "example-bucket" + } + region: "eu-central-1" + rule: [ + { + objectOwnership: "BucketOwnerPreferred" + } + ] + } + } + s3v1beta1.Bucket{ + metadata.name: "example-bucket" + spec.forProvider: { + region: "eu-central-1" + } + } + s3v1beta1.BucketServerSideEncryptionConfiguration{ + metadata.name: "example-encryption" + spec.forProvider: { + bucketRef: { + name: "example-bucket" + } + region: "eu-central-1" + rule: [ + { + applyServerSideEncryptionByDefault: [ + { + sseAlgorithm: "AES256" + } + ] + bucketKeyEnabled: True + } + ] + } + } + s3v1beta1.BucketPublicAccessBlock{ + metadata.name: "example-pab" + spec.forProvider: { + blockPublicAcls: False + blockPublicPolicy: False + bucketRef: { + name: "example-bucket" + } + ignorePublicAcls: False + region: "eu-central-1" + restrictPublicBuckets: False + } + } + ] + compositionPath: "apis/xstoragebuckets/composition.yaml" + xr: platformv1alpha1.XStorageBucket{ + metadata.name: "example" + spec.parameters: { + versioning: False + acl: "public-read" + region: "eu-central-1" + } + } + xrdPath: "apis/xstoragebuckets/definition.yaml" + timeoutSeconds: 120 + validate: False + } + } +] +items = _items diff --git a/tests/test-xstoragebucket-versioning/model b/tests/test-xstoragebucket-versioning/model new file mode 120000 index 0000000..faff6e4 --- /dev/null +++ b/tests/test-xstoragebucket-versioning/model @@ -0,0 +1 @@ +../../.up/kcl/models \ No newline at end of file diff --git a/tests/test-xstoragebucket/kcl.mod b/tests/test-xstoragebucket/kcl.mod new file mode 100644 index 0000000..03d12bf --- /dev/null +++ b/tests/test-xstoragebucket/kcl.mod @@ -0,0 +1,6 @@ +[package] +name = "test-xstoragebucket" +version = "0.0.1" + +[dependencies] +models = { path = "./model" } \ No newline at end of file diff --git a/tests/test-xstoragebucket/kcl.mod.lock b/tests/test-xstoragebucket/kcl.mod.lock new file mode 100644 index 0000000..7756095 --- /dev/null +++ b/tests/test-xstoragebucket/kcl.mod.lock @@ -0,0 +1,12 @@ +[dependencies] + [dependencies.model] + name = "model" + full_name = "models_0.0.1" + version = "0.0.1" + reg = "ghcr.io" + repo = "kcl-lang/model" + oci_tag = "0.0.1" + [dependencies.models] + name = "models" + full_name = "models_0.0.1" + version = "0.0.1" diff --git a/tests/test-xstoragebucket/main.k b/tests/test-xstoragebucket/main.k new file mode 100644 index 0000000..41fa37b --- /dev/null +++ b/tests/test-xstoragebucket/main.k @@ -0,0 +1,104 @@ + +import models.com.example.platform.v1alpha1 as platformv1alpha1 +import models.io.upbound.aws.s3.v1beta1 as s3v1beta1 +import models.io.upbound.dev.meta.v1alpha1 as metav1alpha1 + +_items = [ + metav1alpha1.CompositionTest{ + metadata.name="test-xstoragebucket" + spec= { + assert: [ + platformv1alpha1.XStorageBucket{ + metadata.name: "example" + spec.parameters: { + acl: "public-read" + region: "us-west-1" + versioning: True + } + } + s3v1beta1.BucketACL{ + metadata.name: "example-acl" + spec.forProvider:{ + acl: "public-read" + bucketRef: { + name: "example-bucket" + } + region: "us-west-1" + } + } + s3v1beta1.BucketOwnershipControls{ + metadata.name: "example-boc" + spec.forProvider: { + bucketRef: { + name: "example-bucket" + } + region: "us-west-1" + rule: [ + { + objectOwnership: "BucketOwnerPreferred" + } + ] + } + } + s3v1beta1.Bucket{ + metadata.name: "example-bucket" + spec.forProvider: { + region: "us-west-1" + } + } + s3v1beta1.BucketServerSideEncryptionConfiguration{ + metadata.name: "example-encryption" + spec.forProvider: { + bucketRef: { + name: "example-bucket" + } + region: "us-west-1" + rule: [ + { + applyServerSideEncryptionByDefault: [ + { + sseAlgorithm: "AES256" + } + ] + bucketKeyEnabled: True + } + ] + } + } + s3v1beta1.BucketPublicAccessBlock{ + metadata.name: "example-pab" + spec.forProvider: { + blockPublicAcls: False + blockPublicPolicy: False + bucketRef: { + name: "example-bucket" + } + ignorePublicAcls: False + region: "us-west-1" + restrictPublicBuckets: False + } + } + s3v1beta1.BucketVersioning{ + metadata.name: "example-versioning" + spec.forProvider: { + bucketRef: { + name: "example-bucket" + } + region: "us-west-1" + versioningConfiguration: [ + { + status: "Enabled" + }, + ] + } + } + ] + compositionPath: "apis/xstoragebuckets/composition.yaml" + xrPath: "examples/xstoragebuckets/example.yaml" + xrdPath: "apis/xstoragebuckets/definition.yaml" + timeoutSeconds: 120 + validate: False + } + } +] +items = _items diff --git a/tests/test-xstoragebucket/model b/tests/test-xstoragebucket/model new file mode 120000 index 0000000..faff6e4 --- /dev/null +++ b/tests/test-xstoragebucket/model @@ -0,0 +1 @@ +../../.up/kcl/models \ No newline at end of file From e995a8101f01e4b4734424ac26eee12ebf12e06f Mon Sep 17 00:00:00 2001 From: Christopher Haar Date: Tue, 11 Feb 2025 12:59:57 +0100 Subject: [PATCH 2/2] feat(change): change spec.assert to spec.asserResources Signed-off-by: Christopher Haar --- tests/test-xstoragebucket-default/main.k | 2 +- tests/test-xstoragebucket-versioning/main.k | 2 +- tests/test-xstoragebucket/main.k | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test-xstoragebucket-default/main.k b/tests/test-xstoragebucket-default/main.k index 28ba8b4..187ae5f 100644 --- a/tests/test-xstoragebucket-default/main.k +++ b/tests/test-xstoragebucket-default/main.k @@ -5,7 +5,7 @@ _items = [ metav1alpha1.CompositionTest{ metadata.name="test-xstoragebucket-default" spec= { - assert: [] + assertResources: [] compositionPath: "apis/xstoragebuckets/composition.yaml" xrPath: "examples/xstoragebuckets/example.yaml" xrdPath: "apis/xstoragebuckets/definition.yaml" diff --git a/tests/test-xstoragebucket-versioning/main.k b/tests/test-xstoragebucket-versioning/main.k index d385a6e..5db8849 100644 --- a/tests/test-xstoragebucket-versioning/main.k +++ b/tests/test-xstoragebucket-versioning/main.k @@ -7,7 +7,7 @@ _items = [ metav1alpha1.CompositionTest{ metadata.name="test-xstoragebucket" spec= { - assert: [ + assertResources: [ platformv1alpha1.XStorageBucket{ metadata.name: "example" spec.parameters: { diff --git a/tests/test-xstoragebucket/main.k b/tests/test-xstoragebucket/main.k index 41fa37b..024c0a7 100644 --- a/tests/test-xstoragebucket/main.k +++ b/tests/test-xstoragebucket/main.k @@ -7,7 +7,7 @@ _items = [ metav1alpha1.CompositionTest{ metadata.name="test-xstoragebucket" spec= { - assert: [ + assertResources: [ platformv1alpha1.XStorageBucket{ metadata.name: "example" spec.parameters: {