Skip to content

Commit 448747a

Browse files
GabriFedi97gbartoliniNiccoloFeimnencia
authored
feat: e2e test as single task cmd (#81)
Provide e2e test execution for extensions as a single Taskfile command rather than having to chain multiple steps externally. Closes: #80 --------- Signed-off-by: Gabriele Fedi <gabriele.fedi@enterprisedb.com> Signed-off-by: Gabriele Bartolini <gabriele.bartolini@enterprisedb.com> Signed-off-by: Niccolò Fei <niccolo.fei@enterprisedb.com> Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com> Co-authored-by: Gabriele Bartolini <gabriele.bartolini@enterprisedb.com> Co-authored-by: Niccolò Fei <niccolo.fei@enterprisedb.com> Co-authored-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
1 parent 9d8ef22 commit 448747a

2 files changed

Lines changed: 80 additions & 50 deletions

File tree

BUILD.md

Lines changed: 41 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -94,96 +94,89 @@ cluster with CloudNativePG pre-installed.
9494
> **Pre-submission requirement:** You must successfully run local tests before
9595
> submitting a Pull Request for any extension.
9696
97+
### The Fast Path (Automated Testing)
98+
99+
End-to-end (E2E) tests are powered by [Chainsaw](https://github.com/kyverno/chainsaw).
100+
To simplify the workflow, use the `e2e:test:full` task.
101+
This single command automates environment setup, image building, and test
102+
execution:
103+
104+
```bash
105+
# Replace <extension> with the name of the extension (e.g., pgvector)
106+
task e2e:test:full TARGET="<extension>"
107+
```
108+
109+
Example for testing the `pgvector` extension:
110+
111+
```bash
112+
task e2e:test:full TARGET="pgvector"
113+
```
114+
115+
**When to use the step-by-step guide:** If the automated test fails during
116+
environment setup, image building, or test execution, the step-by-step guide
117+
below provides granular control for debugging each phase independently.
118+
119+
---
120+
121+
## E2E step-by-step Guide
122+
97123
### Initialize the environment
98124

99-
The `e2e:setup-env` utility automates the heavy lifting. It creates a Kind
100-
cluster, attaches a local Docker registry (available at `localhost:5000`), and
101-
installs the CloudNativePG operator.
125+
The `e2e:setup-env` utility creates a Kind cluster and attaches a local Docker
126+
registry (available at `localhost:5000`).
102127

103128
```bash
104129
task e2e:setup-env
105130
```
106131

107132
### Get access to the cluster
108133

109-
Even though the cluster is running, your local `kubectl` doesn't know how to
110-
talk to it yet. You need to "export" the credentials (the Kubeconfig).
111-
112-
If you want to run `kubectl get pods` from your own laptop's terminal, use the
113-
standard export:
134+
To interact with the cluster via `kubectl` from your local terminal:
114135

115136
```bash
116137
task e2e:export-kubeconfig KUBECONFIG_PATH=./kubeconfig
117138
export KUBECONFIG=$PWD/kubeconfig
118139
```
119140

120-
If you are running a test script that is also running inside a Docker container
121-
on the same network, like in the case of Kind, it needs the "internal" address
122-
to find the API server:
141+
To allow the test suite (running within the Docker network) to reach the API
142+
server:
123143

124144
```bash
125145
task e2e:export-kubeconfig KUBECONFIG_PATH=./kubeconfig INTERNAL=true
126146
```
127147

128148
### Build and push the extension (`bake`)
129149

130-
Before the cluster can use your extension, you must build the image and push it
131-
to the local registry (see ["Push images for a specific project" above](#6-push-images-for-a-specific-project)):
150+
Build the image and push it to the local registry. This command tags the image
151+
for `localhost:5000` automatically.
132152

133153
```bash
134154
task bake TARGET="<extension>" PUSH=true
135155
```
136156

137-
This command tags the image for `localhost:5000` and pushes it automatically.
138-
139-
> [!TIP]
140-
> You can change the default registry through the `registry` environment variable
141-
> (defined in the `docker/bake.hcl` file).
157+
> [!NOTE]
158+
> The destination registry is controlled by the `registry` variable defined within the `docker/bake.hcl` file.
142159
143160
### Prepare testing values
144161

145-
We use [Chainsaw](https://github.com/kyverno/chainsaw) for declarative
146-
end-to-end testing. Before running tests, you must generate specific
147-
configuration values for your extension image.
148-
149-
Run the following command to export these values into your extension's
150-
directory:
162+
Generate configuration values so Chainsaw knows which local image to target for
163+
the E2E tests:
151164

152165
```bash
153166
task e2e:generate-values TARGET="<extension>" EXTENSION_IMAGE="<my-local-image>"
154167
```
155168

156-
For example, to generate the values for the local test of the local image, you could run something similar to the following:
157-
158-
```bash
159-
# The actual name of the image might be different on your system
160-
task e2e:generate-values TARGET=pgvector EXTENSION_IMAGE="localhost:5000/pgvector-testing:0.8.1-18-trixie"
161-
```
162-
163169
### Execute End-to-End tests
164170

165-
The testing framework requires an internal Kubeconfig to communicate correctly
166-
within the Docker network.
167-
168-
First, export the internal configuration as shown above:
169-
170-
```bash
171-
task e2e:export-kubeconfig KUBECONFIG_PATH=./kubeconfig INTERNAL=true
172-
```
173-
174-
Then, run the `e2e:test` task. This executes both the generic tests (located in
175-
the global `/test` folder) and any extension-specific tests (located in the
176-
target's `/test` folder):
171+
Run the test suite using the internal Kubeconfig. This executes both the
172+
generic tests (global `/test` folder) and extension-specific tests (target
173+
`/test` folder).
177174

178175
```bash
179176
task e2e:test TARGET="<extension>" KUBECONFIG_PATH="./kubeconfig"
180177
```
181178

182-
You can test the `pgvector` extension with:
183-
184-
```bash
185-
task e2e:test TARGET="pgvector" KUBECONFIG_PATH="./kubeconfig"
186-
```
179+
---
187180

188181
### Tear down the local test environment
189182

Taskfile.yml

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,17 @@ tasks:
7575
vars:
7676
PUSH: '{{.PUSH | default "false"}}'
7777
DRY_RUN: '{{.DRY_RUN | default "false"}}'
78+
METADATA_FILE: '{{.METADATA_FILE | default ""}}'
7879
preconditions:
7980
- sh: test -f "{{.TARGET}}/metadata.hcl"
8081
msg: 'Not a valid target, metadata.hcl file is missing. Target: {{.TARGET}}'
8182
cmds:
8283
- echo -e "{{.BLUE}}Baking target {{.TARGET}} (push={{.PUSH}})...{{.NC}}"
8384
- |
8485
if [ "{{.DRY_RUN}}" = "true" ]; then
85-
echo -e "{{.GREEN}}[DRY RUN] docker buildx bake -f {{.TARGET}}/metadata.hcl -f docker-bake.hcl --push={{.PUSH}}{{.NC}}"
86+
echo -e "{{.GREEN}}[DRY RUN] docker buildx bake -f {{.TARGET}}/metadata.hcl -f docker-bake.hcl --metadata-file="{{.METADATA_FILE}}" --push={{.PUSH}}{{.NC}}"
8687
else
87-
docker buildx bake -f {{.TARGET}}/metadata.hcl -f docker-bake.hcl --push={{.PUSH}}
88+
docker buildx bake -f {{.TARGET}}/metadata.hcl -f docker-bake.hcl --metadata-file="{{.METADATA_FILE}}" --push={{.PUSH}}
8889
fi
8990
- echo -e "{{.GREEN}}--- Successfully baked {{.TARGET}} ---{{.NC}}"
9091
requires:
@@ -343,6 +344,42 @@ tasks:
343344
TARGET: "{{ .ITEM }}"
344345
task: e2e:test
345346

347+
e2e:test:full:
348+
desc: "Run full E2E tests: setup env, generate values, run tests"
349+
vars:
350+
METADATA_FILE: "{{ .TARGET }}/bake-metadata.json"
351+
KUBECONFIG_PATH: "./kubeconfig"
352+
DISTRO: '{{ .DISTRO | default "trixie" }}'
353+
cmds:
354+
- task: e2e:setup-env
355+
- task: bake
356+
vars:
357+
PUSH: "true"
358+
TARGET: "{{ .TARGET }}"
359+
METADATA_FILE: "{{ .METADATA_FILE }}"
360+
- defer: rm -f "{{ .METADATA_FILE }}"
361+
- task: e2e:generate-values
362+
vars:
363+
TARGET: "{{ .TARGET }}"
364+
EXTENSION_IMAGE:
365+
sh: >
366+
jq -r --arg distro "{{ .DISTRO }}"
367+
'to_entries | .[] | select(.key | endswith("-" + $distro)) | .value["image.name"] | split(",")[0]'
368+
"{{ .METADATA_FILE }}"
369+
- defer: rm -f "{{ .TARGET }}/values.yaml"
370+
- task: e2e:export-kubeconfig
371+
vars:
372+
KUBECONFIG_PATH: "{{ .KUBECONFIG_PATH }}"
373+
INTERNAL: "true"
374+
- defer: rm -f "{{ .KUBECONFIG_PATH }}"
375+
- task: e2e:test
376+
vars:
377+
TARGET: "{{ .TARGET }}"
378+
KUBECONFIG_PATH: "{{ .KUBECONFIG_PATH }}"
379+
requires:
380+
vars:
381+
- name: TARGET
382+
346383
e2e:cleanup:
347384
desc: Cleanup E2E resources
348385
deps:

0 commit comments

Comments
 (0)