-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathTaskfile.yml
More file actions
232 lines (205 loc) · 7.94 KB
/
Copy pathTaskfile.yml
File metadata and controls
232 lines (205 loc) · 7.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# Copyright AGNTCY Contributors (https://github.com/agntcy)
# SPDX-License-Identifier: Apache-2.0
version: "3"
includes:
# Import Taskfiles for each test environment. Each Taskfile defines
# "up" and "down" tasks to manage the lifecycle of its environment.
e2e:internal:testenv:client:kind:
taskfile: "./e2e/client/testenv/kind/Taskfile.testenv.yml"
internal: true
e2e:internal:testenv:client:local:
taskfile: "./e2e/client/testenv/local/Taskfile.testenv.yml"
internal: true
e2e:internal:testenv:daemon:default:
taskfile: "./e2e/daemon/testenv/default/Taskfile.testenv.yml"
internal: true
e2e:internal:testenv:daemon:external:
taskfile: "./e2e/daemon/testenv/external/Taskfile.testenv.yml"
internal: true
e2e:internal:testenv:local:kind:
taskfile: "./e2e/local/testenv/kind/Taskfile.testenv.yml"
internal: true
e2e:internal:testenv:local:local:
taskfile: "./e2e/local/testenv/local/Taskfile.testenv.yml"
internal: true
e2e:internal:testenv:network:kind:
taskfile: "./e2e/network/testenv/kind/Taskfile.testenv.yml"
internal: true
e2e:internal:testenv:network:local:
taskfile: "./e2e/network/testenv/local/Taskfile.testenv.yml"
internal: true
e2e:internal:testenv:integration-server:default:
taskfile: "./integration/server/testenv/Taskfile.testenv.yml"
internal: true
vars:
#
# Reusable test matrix defining test cases and their associated test environments.
# This allows us to easily add new test cases or environments without changing the
# core test execution logic.
#
# TEST_MATRIX:
# <test_case>:
# go_test_suite: <path to Go test package>
# envs:
# <env_name>: <testenv configuration>
#
# Extending matrix:
# - When adding a new test case, simply add a new entry under TEST_MATRIX
# with the appropriate testenv configurations.
# - When adding a new test environment for an existing test case,
# add a new entry under the "envs" section for that test case.
# - If your test environment requires specific setup/teardown logic,
# import the corresponding Taskfile with the necessary "up" and "down" tasks.
#
# Notes:
# - Each test case can have multiple environments, and the test execution logic will
# run the appropriate setup and tests based on user input.
TEST_MATRIX:
map:
client:
go_test_suite: "{{.ROOT_DIR}}/tests/e2e/client"
envs:
kind: "{{.ROOT_DIR}}/tests/e2e/client/testenv/kind/test-config.yaml"
local: "{{.ROOT_DIR}}/tests/e2e/client/testenv/local/test-config.yaml"
daemon:
go_test_suite: "{{.ROOT_DIR}}/tests/e2e/daemon"
envs:
default: "{{.ROOT_DIR}}/tests/e2e/daemon/testenv/default/test-config.yaml"
external: "{{.ROOT_DIR}}/tests/e2e/daemon/testenv/external/test-config.yaml"
local:
go_test_suite: "{{.ROOT_DIR}}/tests/e2e/local"
envs:
kind: "{{.ROOT_DIR}}/tests/e2e/local/testenv/kind/test-config.yaml"
local: "{{.ROOT_DIR}}/tests/e2e/local/testenv/local/test-config.yaml"
network:
go_test_suite: "{{.ROOT_DIR}}/tests/e2e/network"
envs:
kind: "{{.ROOT_DIR}}/tests/e2e/network/testenv/kind/test-config.yaml"
local: "{{.ROOT_DIR}}/tests/e2e/network/testenv/local/test-config.yaml"
integration-server:
go_test_suite: "{{.ROOT_DIR}}/tests/integration/server"
envs:
default: "{{.ROOT_DIR}}/tests/integration/server/testenv/test-config.yaml"
# Set GOCOVERDIR for supported testenv coverage collection.
# This relies on the convention that testenv tasks will pass
# this variable to the test process environment.
GOCOVERDIR: "{{.COVERAGE_DIR}}/e2e/.gocover"
tasks:
e2e:testenv:*:*:up:
desc: Create testenv for a test case
silent: true
vars:
TEST_CASE: '{{index .MATCH 0}}'
TEST_ENV: '{{index .MATCH 1}}'
SKIP_TESTENV: '{{.SKIP_TESTENV | default "false"}}'
if: '{{ eq .SKIP_TESTENV "false" }}'
cmds:
- task: 'e2e:internal:testenv:{{.TEST_CASE}}:{{.TEST_ENV}}:up'
e2e:testenv:*:*:down:
desc: Destroy testenv for a test case
silent: true
vars:
TEST_CASE: '{{index .MATCH 0}}'
TEST_ENV: '{{index .MATCH 1}}'
SKIP_TESTENV: '{{.SKIP_TESTENV | default "false"}}'
if: '{{ eq .SKIP_TESTENV "false" }}'
cmds:
- task: 'e2e:internal:testenv:{{.TEST_CASE}}:{{.TEST_ENV}}:down'
e2e:test:*:*:
desc: Run E2E test suite for a test environment (use SKIP_TESTENV=true to skip setup/teardown)
silent: true
vars:
# User input
TEST_CASE: '{{index .MATCH 0}}'
TEST_ENV: '{{index .MATCH 1}}'
SKIP_TESTENV: '{{.SKIP_TESTENV | default "false"}}'
# Task vars
SELECTED_CASE: { ref: 'get .TEST_MATRIX .TEST_CASE' }
SELECTED_ENV: { ref: 'get .SELECTED_CASE.envs .TEST_ENV' }
SELECTED_TESTENV_TASK: 'e2e:testenv:{{.TEST_CASE}}:{{.TEST_ENV}}'
deps:
- task: cli:compile
vars:
COVERAGE: "true"
TRY_SKIP_COMPILE: "true"
cmds:
# Print info
- |
echo -e "Test case: {{ toJson .SELECTED_CASE }}"
echo -e "Test testenv: {{ toJson .SELECTED_ENV }}"
# Create testenv
- defer: { task: '{{.SELECTED_TESTENV_TASK}}:down' }
- task: '{{.SELECTED_TESTENV_TASK}}:up'
# Run test suite
- |
mkdir -p {{ .COVERAGE_DIR }}/e2e
go test -C {{ .SELECTED_CASE.go_test_suite }} . \
-covermode=atomic \
-coverpkg={{.COVERAGE_PKGS}} \
-coverprofile={{.COVERAGE_DIR}}/e2e/{{.TEST_CASE}}-{{.TEST_ENV}}.out \
-v -failfast -test.v -test.paniconexit0 \
-timeout 2h -ginkgo.timeout 2h -ginkgo.v \
-test-config {{ .SELECTED_ENV }}
e2e:test:*:
desc: Run E2E test suite across all test environments
silent: true
vars:
# User input
TEST_CASE: '{{index .MATCH 0}}'
# Find selected test case from matrix
SELECTED_CASE: { ref: 'get .TEST_MATRIX .TEST_CASE' }
SELECTED_TESTENVS: { ref: '.SELECTED_CASE.envs' }
deps:
# Run in parallel across test environments assuming
# testenv setup is isolated per environment
- for: { var: SELECTED_TESTENVS }
task: 'e2e:test:{{ .TEST_CASE }}:{{ .KEY }}'
e2e:test:
desc: Run all E2E test suites
silent: true
cmds:
# Run serial across test cases
- for: { var: TEST_MATRIX }
task: 'e2e:test:{{ .KEY }}'
e2e:list:
desc: List available E2E test suites
silent: true
cmds:
- for: { var: TEST_MATRIX }
cmd: |
echo "e2e:test:{{.KEY}}"
{{ range $key, $item := .ITEM.envs }}
echo -e " Testenv: {{$key}}, Config: {{ $item }}"
{{ end }}
- |
echo -e "\nTo run a specific test suite, use: task e2e:test:<test_case>:<test_env>"
echo -e "Example: task e2e:test:client:kind"
# NOTE: this cannot be run under e2e:test task due to a transient
# issue of either closing/stopping daemon or flushing coverage data,
# both of which require the parent process (taskfile) to exit to
# complete and dump coverage files.
e2e:coverage:
desc: Generate combined coverage report for all E2E tests
vars:
# User input
COVERAGE_FILENAME: '{{ .COVERAGE_FILENAME | default "combined.out" }}'
# Task settings
MERGE_GOCOVERDIR: '{{ .COVERAGE_DIR }}/e2e/.gocover-merged'
TESTENV_COVERAGE_FILE: '{{ .COVERAGE_DIR }}/e2e/{{ .COVERAGE_FILENAME | replace " " "-" | lower }}'
cmds:
# Prepare fresh MERGE_GOCOVERDIR
- |
rm -rf {{.MERGE_GOCOVERDIR}}
mkdir -p {{.MERGE_GOCOVERDIR}}
# Merge coverage profiles
- |
go tool covdata merge \
-i={{.GOCOVERDIR}} \
-pkg={{.COVERAGE_PKGS}} \
-o={{.MERGE_GOCOVERDIR}} || exit 0
# Generate combined coverage report
- |
go tool covdata textfmt \
-i={{.MERGE_GOCOVERDIR}} \
-pkg={{.COVERAGE_PKGS}} \
-o={{.TESTENV_COVERAGE_FILE}}