-
-
Notifications
You must be signed in to change notification settings - Fork 216
168 lines (146 loc) · 5.09 KB
/
Copy pathgo.yml
File metadata and controls
168 lines (146 loc) · 5.09 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
name: Go
on:
push:
branches: [dev, main]
pull_request:
branches: [dev, main]
jobs:
unit-tests:
name: Unit Tests
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
cache: true
- name: Install dependencies
run: |
go mod download
go get github.com/DATA-DOG/go-sqlmock
- name: Run unit tests and generate coverage
run: |
# Create a test .env file
echo "PASETO_PRIVATE_KEY=UayDa4OMDpm3CvIT+iSC39iDyPlsui0pNQYDEZ1pbo1LsIrO4p/aVuCBWz6LiYvzj9pc+gn0gLwRd0CoHV+nxw==" >> .env.test
echo "PASETO_PUBLIC_KEY=S7CKzuKf2lbggVs+i4mL84/aXPoJ9IC8EXdAqB1fp8c=" >> .env.test
echo "ROOT_EMAIL=admin@example.com" >> .env.test
# Run unit tests (exclude integration tests)
go test -race -coverprofile=coverage-unit.txt -covermode=atomic $(go list ./... | grep -v '/tests/integration') -v
# Copy to repo root for codecov action
cp coverage-unit.txt ../
- name: Upload unit test coverage to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: Notifuse/notifuse
files: coverage-unit.txt
fail_ci_if_error: false
verbose: true
name: codecov-unit-tests
flags: unit
integration-tests:
name: Integration Tests
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./
services:
postgres:
image: postgres:15
env:
POSTGRES_USER: notifuse_test
POSTGRES_PASSWORD: test_password
POSTGRES_DB: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5433:5432
mailhog:
image: mailhog/mailhog:latest
env:
MH_STORAGE: memory
options: >-
--health-cmd "wget --quiet --tries=1 --spider http://localhost:8025/ || exit 1"
--health-interval 10s
--health-timeout 5s
--health-retries 3
ports:
- 1025:1025
- 8025:8025
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
cache: true
- name: Install dependencies
run: |
go mod download
go get github.com/DATA-DOG/go-sqlmock
- name: Run integration tests and generate coverage
env:
# Enable integration tests
INTEGRATION_TESTS: true
# Test database configuration
TEST_DB_HOST: localhost
TEST_DB_PORT: 5433
TEST_DB_USER: notifuse_test
TEST_DB_PASSWORD: test_password
ENVIRONMENT: test
# Set main database config to use test database
DB_HOST: localhost
DB_PORT: 5433
DB_USER: notifuse_test
DB_PASSWORD: test_password
DB_NAME: notifuse_test_integration
DB_PREFIX: notifuse_test
DB_SSLMODE: disable
run: |
# Create a test .env file for integration tests
echo "PASETO_PRIVATE_KEY=UayDa4OMDpm3CvIT+iSC39iDyPlsui0pNQYDEZ1pbo1LsIrO4p/aVuCBWz6LiYvzj9pc+gn0gLwRd0CoHV+nxw==" >> .env.test
echo "PASETO_PUBLIC_KEY=S7CKzuKf2lbggVs+i4mL84/aXPoJ9IC8EXdAqB1fp8c=" >> .env.test
echo "ROOT_EMAIL=admin@example.com" >> .env.test
echo "DB_HOST=localhost" >> .env.test
echo "DB_PORT=5433" >> .env.test
echo "DB_USER=notifuse_test" >> .env.test
echo "DB_PASSWORD=test_password" >> .env.test
echo "DB_NAME=notifuse_test_integration" >> .env.test
echo "DB_PREFIX=notifuse_test" >> .env.test
echo "DB_SSLMODE=disable" >> .env.test
# Wait for services to be ready
echo "Waiting for PostgreSQL to be ready..."
sleep 10
# Wait for Mailhog to be ready
echo "Waiting for Mailhog to be ready..."
for i in {1..30}; do
if curl -f http://localhost:8025/ > /dev/null 2>&1; then
echo "Mailhog is ready!"
break
fi
echo "Waiting for Mailhog... ($i/30)"
sleep 2
done
# Run integration tests only with more timeout
go test -race -coverprofile=coverage-integration.txt -covermode=atomic -timeout=15m ./tests/integration/... -v
# Copy to repo root for codecov action
cp coverage-integration.txt ../
# - name: Upload integration test coverage to Codecov
# uses: codecov/codecov-action@v3
# with:
# token: ${{ secrets.CODECOV_TOKEN }}
# slug: Notifuse/notifuse
# file: coverage-integration.txt
# fail_ci_if_error: true
# verbose: true
# name: codecov-integration-tests
# flags: integration