-
Notifications
You must be signed in to change notification settings - Fork 6
124 lines (112 loc) · 3.07 KB
/
test.yaml
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
---
# @see https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions
# @see https://docs.github.com/en/actions/guides/creating-postgresql-service-containers
# @see https://github.com/actions/virtual-environments
# @see https://www.postgresql.jp/document/11/html/app-pgrestore.html
name: Test
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
unit:
name: Unit
timeout-minutes: 5
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
check-latest: true
cache: true
- name: Download modules
run: go mod download
- name: Lint
run: make lint
- name: Test
run: make test
feature:
name: Feature
timeout-minutes: 5
runs-on: ubuntu-latest
defaults:
run:
shell: bash
strategy:
fail-fast: false
matrix:
postgres:
- 10-alpine
- 11-alpine
- 12-alpine
- 13-alpine
- 14-alpine
- 15-alpine
- 16-alpine
services:
postgres:
image: postgres:${{ matrix.postgres }}
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
POSTGRES_PASSWORD: postgres
POSTGRES_INITDB_ARGS: '--auth-host=scram-sha-256'
env:
PGHOST: 127.0.0.1
PGPORT: 5432
PGDATABASE: postgres
steps:
- name: Install PostgreSQL clients
run: sudo apt update && sudo apt install -y --no-install-recommends postgresql-client
- name: Check out code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
check-latest: true
cache: true
- name: Download modules
run: go mod download
- name: Build
run: make
- name: Create role for test
run: |
echo -n "CREATE ROLE test WITH LOGIN PASSWORD " >> $SQL_FILE_PATH
echo -n "'" >> $SQL_FILE_PATH
./cmd/tool/encrypt test | tr -d '\n' >> $SQL_FILE_PATH
echo "';" >> $SQL_FILE_PATH
cat $SQL_FILE_PATH | tee /dev/stderr | psql
env:
SQL_FILE_PATH: /tmp/create_role.sql
PGUSER: postgres
PGPASSWORD: postgres
- name: Check roles out
run: psql -c 'SELECT usename, passwd FROM pg_catalog.pg_shadow'
env:
PGUSER: postgres
PGPASSWORD: postgres
- name: Test login success
run: psql -c 'SELECT user'
env:
PGUSER: test
PGPASSWORD: test
- name: Test login fail
run: psql -c 'SELECT user' || echo 'fail ok'
env:
PGUSER: test
PGPASSWORD: wrong