-
Notifications
You must be signed in to change notification settings - Fork 0
208 lines (176 loc) · 6.52 KB
/
functional-tests.yml
File metadata and controls
208 lines (176 loc) · 6.52 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
name: Functional Tests
permissions:
contents: read
packages: read
on:
pull_request:
workflow_dispatch:
inputs:
version_tag:
description: "Optional release tag (e.g. 1.0.0 or 1.0.0-rc1)"
required: false
type: string
cbdc_version:
description: "Optional cbdinocluster version (e.g. v0.0.88)"
required: false
type: string
env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_NOLOGO: 1
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
functional-tests:
name: Functional Tests (ubuntu-22.04)
runs-on: ubuntu-22.04
timeout-minutes: 45
steps:
- name: Checkout (tag)
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.version_tag != '' }}
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: refs/tags/${{ github.event.inputs.version_tag }}
- name: Checkout (PR head)
if: ${{ github.event_name == 'pull_request' }}
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- name: Checkout (default)
if: ${{ github.event_name == 'workflow_dispatch' && (github.event.inputs.version_tag == '' || github.event.inputs.version_tag == null) }}
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
cache: false
- name: Install cbdinocluster
id: install-cbdc
run: |
mkdir -p "$HOME/bin"
CBDC_VER=${{ github.event.inputs.cbdc_version }}
if [ -z "$CBDC_VER" ]; then
CBDC_VER=v0.0.88
fi
echo "Installing cbdinocluster $CBDC_VER"
wget -nv -O $HOME/bin/cbdinocluster https://github.com/couchbaselabs/cbdinocluster/releases/download/${CBDC_VER}/cbdinocluster-linux-amd64
chmod +x $HOME/bin/cbdinocluster
echo "$HOME/bin" >> $GITHUB_PATH
- name: Initialize cbdinocluster
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cbdinocluster -v init --auto
- name: Start Couchbase Analytics cluster
id: start-cluster
env:
INPUT_TAG: ${{ github.event.inputs.version_tag }}
run: |
TAG=${INPUT_TAG}
EA_VERSION=2.0.1-1231
cat > cluster.yml <<'YAML'
columnar: true
nodes:
- count: 2
version: ${EA_VERSION}
docker:
load-balancer: true
use-dino-certs: true
YAML
# Substitute shell vars into YAML
eval "echo \"$(cat cluster.yml)\"" > cluster.resolved.yml
CBDINO_CLUSTER_ID=$(cbdinocluster -v alloc --def="$(cat cluster.resolved.yml)")
CBDINO_CONNSTR=$(cbdinocluster -v connstr --tls --analytics "$CBDINO_CLUSTER_ID")
echo "CBDINO_CLUSTER_ID=$CBDINO_CLUSTER_ID" >> "$GITHUB_ENV"
echo "CBDINO_CONNSTR=$CBDINO_CONNSTR" >> "$GITHUB_ENV"
echo "CBDINO_USER=Administrator" >> "$GITHUB_ENV"
echo "CBDINO_PASS=password" >> "$GITHUB_ENV"
- name: Prepare Functional Test settings.json
run: |
echo "Writing functional test settings.json with cluster connection string"
cat > tests/Couchbase.Analytics.FunctionalTests/settings.json <<EOF
{
"TestSettings": {
"ConnectionString": "${CBDINO_CONNSTR}",
"Username": "${CBDINO_USER}",
"Password": "${CBDINO_PASS}"
}
}
EOF
echo "settings.json written:" && cat tests/Couchbase.Analytics.FunctionalTests/settings.json
- name: Build and Run Functional Tests
run: |
dotnet test tests/Couchbase.Analytics.FunctionalTests/Couchbase.Analytics.FunctionalTests.csproj \
--configuration Release \
--logger "trx;LogFileName=functional-tests.trx" \
--results-directory "TestResults"
- name: Verify Functional Test Results
run: |
python3 - TestResults/functional-tests.trx <<'PY'
import sys
import xml.etree.ElementTree as ET
if len(sys.argv) != 2:
print(f"Usage: {sys.argv[0]} <results.trx>")
sys.exit(1)
path = sys.argv[1]
print(f"Parsing TRX: {path}")
try:
tree = ET.parse(path)
except Exception as e:
print(f"ERROR: Failed to parse TRX file: {e}")
sys.exit(1)
root = tree.getroot()
ns = {'ns': root.tag.split('}')[0].strip('{')} if root.tag.startswith('{') else {}
rs = root.find('.//ns:ResultSummary', ns)
if rs is None:
rs = root.find('.//ResultSummary')
if rs is None:
print('ERROR: ResultSummary not found in TRX')
sys.exit(1)
counters = rs.find('.//ns:Counters', ns)
if counters is None:
counters = rs.find('.//Counters')
if counters is None:
print('ERROR: Counters not found in TRX')
sys.exit(1)
def get_int(name: str) -> int:
v = counters.attrib.get(name)
try:
return int(v) if v is not None else 0
except ValueError:
return 0
total = get_int('total')
executed = get_int('executed')
passed = get_int('passed')
failed = (
get_int('failed') +
get_int('error') +
get_int('timeout') +
get_int('aborted')
)
print(f"Summary: total={total}, executed={executed}, passed={passed}, failed={failed}")
if total == 0 or executed == 0:
print('ERROR: No tests were run.')
sys.exit(1)
if failed > 0:
print(f'ERROR: {failed} tests failed.')
sys.exit(1)
if passed < executed:
print(f'ERROR: Not all executed tests passed (passed={passed}, executed={executed}).')
sys.exit(1)
print('All functional tests passed.')
PY
- name: Upload Functional Test Results
if: always()
uses: actions/upload-artifact@v4
with:
name: functional-test-results
path: TestResults
- name: Teardown cbdinocluster
if: always()
run: |
if [ -n "${CBDINO_CLUSTER_ID}" ]; then
cbdinocluster rm "$CBDINO_CLUSTER_ID" || true
fi