-
Notifications
You must be signed in to change notification settings - Fork 2
207 lines (180 loc) · 6.59 KB
/
tests.yml
File metadata and controls
207 lines (180 loc) · 6.59 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
name: Tests
on:
push:
branches:
- develop
jobs:
unit-tests:
name: Unit Tests (.NET ${{ matrix.dotnet-version }})
runs-on: ubuntu-latest
strategy:
matrix:
dotnet-version: [8.0.x]
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ matrix.dotnet-version }}
- name: Restore Dependencies
working-directory: src/OpenDDD.Tests
run: dotnet restore
- name: Build Project
working-directory: src/OpenDDD.Tests
run: dotnet build --no-restore --configuration Release /p:TreatWarningsAsErrors=false
- name: Run Unit Tests
working-directory: src/OpenDDD.Tests
run: dotnet test --no-build --configuration Release --filter "Category=Unit" --logger "trx;LogFileName=TestResults.trx" --results-directory TestResults
- name: Upload Unit Test Results
if: always()
uses: actions/upload-artifact@v4
with:
name: UnitTestResults
path: src/OpenDDD.Tests/TestResults/TestResults.trx
- name: Publish Unit Test Report
if: always()
uses: dorny/test-reporter@v1
with:
name: Unit Tests Report
path: src/OpenDDD.Tests/TestResults/TestResults.trx
reporter: dotnet-trx
integration-tests:
name: Integration Tests (.NET ${{ matrix.dotnet-version }})
runs-on: ubuntu-latest
strategy:
matrix:
dotnet-version: [8.0.x]
services:
zookeeper:
image: confluentinc/cp-zookeeper:latest
env:
ZOOKEEPER_CLIENT_PORT: 2181
ports:
- 2181:2181
kafka:
image: confluentinc/cp-kafka:latest
env:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
ports:
- 9092:9092
options: --network-alias kafka
rabbitmq:
image: rabbitmq:3-management
env:
RABBITMQ_DEFAULT_USER: guest
RABBITMQ_DEFAULT_PASS: guest
ports:
- 5672:5672
- 15672:15672
options: --health-cmd "rabbitmq-diagnostics check_port_connectivity" --health-interval 10s --health-timeout 5s --health-retries 5
postgres:
image: postgres:latest
env:
POSTGRES_DB: testdb
POSTGRES_USER: testuser
POSTGRES_PASSWORD: testpassword
ports:
- 5432:5432
options: --health-cmd "pg_isready -U testuser" --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ matrix.dotnet-version }}
- name: Restore Dependencies
working-directory: src/OpenDDD.Tests
run: dotnet restore
- name: Build Project
working-directory: src/OpenDDD.Tests
run: dotnet build --no-restore --configuration Release
- name: Log in to Azure
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Create Azure Service Bus namespace for Testing
run: |
NAMESPACE_NAME="test-servicebus-${{ github.run_id }}-${{ github.run_attempt }}"
echo "NAMESPACE_NAME=${NAMESPACE_NAME}" >> $GITHUB_ENV
az servicebus namespace create \
--resource-group opendddnet \
--name $NAMESPACE_NAME \
--location northeurope
CONNECTION_STRING=$(az servicebus namespace authorization-rule keys list \
--resource-group opendddnet \
--namespace-name $NAMESPACE_NAME \
--name RootManageSharedAccessKey \
--query primaryConnectionString \
-o tsv)
echo "AZURE_SERVICE_BUS_CONNECTION_STRING=${CONNECTION_STRING}" >> $GITHUB_ENV
- name: Wait for RabbitMQ to be Ready
run: |
for i in {1..10}; do
if curl -s -f http://localhost:15672 || nc -z localhost 5672; then
echo "RabbitMQ is up!"
exit 0
fi
echo "Waiting for RabbitMQ..."
sleep 5
done
echo "RabbitMQ did not start in time!" && exit 1
- name: Wait for Kafka to be Ready
run: |
for i in {1..10}; do
if nc -z localhost 9092; then
echo "Kafka is up!"
exit 0
fi
echo "Waiting for Kafka..."
sleep 5
done
echo "Kafka did not start in time!" && exit 1
- name: Wait for PostgreSQL to be Ready
run: |
for i in {1..10}; do
if PGPASSWORD=testpassword psql -h localhost -U testuser -d testdb -c "SELECT 1" &> /dev/null; then
echo "PostgreSQL is up!"
exit 0
fi
echo "Waiting for PostgreSQL..."
sleep 5
done
echo "PostgreSQL did not start in time!" && exit 1
- name: Run Integration Tests
working-directory: src/OpenDDD.Tests
env:
KAFKA_BOOTSTRAP_SERVERS: localhost:9092
RABBITMQ_HOST: localhost
RABBITMQ_PORT: 5672
RABBITMQ_USERNAME: guest
RABBITMQ_PASSWORD: guest
AZURE_SERVICE_BUS_CONNECTION_STRING: ${{ env.AZURE_SERVICE_BUS_CONNECTION_STRING }}
POSTGRES_TEST_CONNECTION_STRING: "Host=localhost;Port=5432;Database=testdb;Username=testuser;Password=testpassword"
run: dotnet test --no-build --configuration Release --filter "Category=Integration" --logger "trx;LogFileName=TestResults.trx" --results-directory TestResults
- name: Delete Azure Service Bus namespace After Tests
if: always()
run: |
if [[ -n "${NAMESPACE_NAME}" ]]; then
echo "Deleting namespace: $NAMESPACE_NAME"
az servicebus namespace delete --resource-group opendddnet --name $NAMESPACE_NAME
else
echo "No namespace found, skipping deletion."
fi
- name: Upload Integration Test Results
if: always()
uses: actions/upload-artifact@v4
with:
name: IntegrationTestResults
path: src/OpenDDD.Tests/TestResults/TestResults.trx
- name: Publish Integration Test Report
if: always()
uses: dorny/test-reporter@v1
with:
name: Integration Tests Report
path: src/OpenDDD.Tests/TestResults/TestResults.trx
reporter: dotnet-trx