Skip to content

Commit 38a54e4

Browse files
committed
Split out testdata/init a bit
Everything in one directory was getting a bit unwieldy.
1 parent 92f8e4e commit 38a54e4

35 files changed

+73
-62
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ In addition, your `/etc/hosts` needs an entry:
260260
127.0.0.1 postgres postgres-invalid
261261

262262
Or you can use any other PostgreSQL instance; see
263-
`testdata/init/docker-entrypoint-initdb.d` for the required setup. You can use
263+
`testdata/postgres/docker-entrypoint-initdb.d` for the required setup. You can use
264264
the standard `PG*` environment variables to control the connection details; it
265265
uses the following defaults:
266266

compose.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ services:
66
image: 'cleanstart/pgbouncer:latest'
77
ports: ['127.0.0.1:6432:6432']
88
command: ['/init/pgbouncer.ini']
9-
volumes: ['./testdata/init:/init']
9+
volumes: ['./testdata/pgbouncer:/init', './testdata/ssl:/ssl']
1010
environment:
1111
'PGBOUNCER_DATABASE': 'pqgo'
1212

1313
pgpool:
1414
profiles: ['pgpool']
1515
image: 'pgpool/pgpool:4.4.3'
1616
ports: ['127.0.0.1:7432:7432']
17-
volumes: ['./testdata/init:/init']
18-
entrypoint: '/init/entry-pgpool.sh'
17+
volumes: ['./testdata/pgpool:/init', './testdata/ssl:/ssl']
18+
entrypoint: '/init/entry.sh'
1919
environment:
2020
'PGPOOL_PARAMS_PORT': '7432'
2121
'PGPOOL_PARAMS_BACKEND_HOSTNAME0': 'pg18'
@@ -24,7 +24,7 @@ services:
2424
image: 'postgres:18'
2525
ports: ['127.0.0.1:5432:5432']
2626
entrypoint: '/init/entry.sh'
27-
volumes: ['./testdata/init:/init']
27+
volumes: ['./testdata/postgres:/init', './testdata/ssl:/ssl']
2828
shm_size: '128mb'
2929
healthcheck: {test: ['CMD-SHELL', 'pg_isready', '-U', 'pqgo', '-d', 'pqgo'], start_period: '30s', start_interval: '1s'}
3030
environment:
@@ -36,7 +36,7 @@ services:
3636
image: 'postgres:17'
3737
ports: ['127.0.0.1:5432:5432']
3838
entrypoint: '/init/entry.sh'
39-
volumes: ['./testdata/init:/init']
39+
volumes: ['./testdata/postgres:/init', './testdata/ssl:/ssl']
4040
shm_size: '128mb'
4141
healthcheck: {test: ['CMD-SHELL', 'pg_isready', '-U', 'pqgo', '-d', 'pqgo'], start_period: '30s', start_interval: '1s'}
4242
environment:
@@ -48,7 +48,7 @@ services:
4848
image: 'postgres:16'
4949
ports: ['127.0.0.1:5432:5432']
5050
entrypoint: '/init/entry.sh'
51-
volumes: ['./testdata/init:/init']
51+
volumes: ['./testdata/postgres:/init', './testdata/ssl:/ssl']
5252
shm_size: '128mb'
5353
healthcheck: {test: ['CMD-SHELL', 'pg_isready', '-U', 'pqgo', '-d', 'pqgo'], start_period: '30s', start_interval: '1s'}
5454
environment:
@@ -60,7 +60,7 @@ services:
6060
image: 'postgres:15'
6161
ports: ['127.0.0.1:5432:5432']
6262
entrypoint: '/init/entry.sh'
63-
volumes: ['./testdata/init:/init']
63+
volumes: ['./testdata/postgres:/init', './testdata/ssl:/ssl']
6464
shm_size: '128mb'
6565
healthcheck: {test: ['CMD-SHELL', 'pg_isready', '-U', 'pqgo', '-d', 'pqgo'], start_period: '30s', start_interval: '1s'}
6666
environment:
@@ -72,7 +72,7 @@ services:
7272
image: 'postgres:14'
7373
ports: ['127.0.0.1:5432:5432']
7474
entrypoint: '/init/entry.sh'
75-
volumes: ['./testdata/init:/init']
75+
volumes: ['./testdata/postgres:/init', './testdata/ssl:/ssl']
7676
shm_size: '128mb'
7777
healthcheck: {test: ['CMD-SHELL', 'pg_isready', '-U', 'pqgo', '-d', 'pqgo'], start_period: '30s', start_interval: '1s'}
7878
environment:

example_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,15 +244,15 @@ func ExampleConnectorWithNoticeHandler() {
244244
}
245245

246246
func ExampleRegisterTLSConfig() {
247-
pem, err := os.ReadFile("testdata/init/root.crt")
247+
pem, err := os.ReadFile("testdata/ssl/root.crt")
248248
if err != nil {
249249
log.Fatal(err)
250250
}
251251

252252
root := x509.NewCertPool()
253253
root.AppendCertsFromPEM(pem)
254254

255-
certs, err := tls.LoadX509KeyPair("testdata/init/postgresql.crt", "testdata/init/postgresql.key")
255+
certs, err := tls.LoadX509KeyPair("testdata/ssl/postgresql.crt", "testdata/ssl/postgresql.key")
256256
if err != nil {
257257
log.Fatal(err)
258258
}

ssl_test.go

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,22 @@ func TestSSLMode(t *testing.T) {
6666
// sslmode=verify-ca: verify that the certificate was signed by a trusted CA
6767
{"host=postgres sslmode=verify-ca user=pqgossl", "invalid-cert"},
6868
{"host=postgres sslmode=verify-ca user=pqgossl sslrootcert=''", "invalid-cert"},
69-
{"sslrootcert=testdata/init/root.crt sslmode=verify-ca user=pqgossl host=127.0.0.1", ""},
70-
{"sslrootcert=testdata/init/root.crt sslmode=verify-ca user=pqgossl host=postgres-invalid", ""},
71-
{"sslrootcert=testdata/init/root.crt sslmode=verify-ca user=pqgossl host=postgres", ""},
69+
{"sslrootcert=testdata/ssl/root.crt sslmode=verify-ca user=pqgossl host=127.0.0.1", ""},
70+
{"sslrootcert=testdata/ssl/root.crt sslmode=verify-ca user=pqgossl host=postgres-invalid", ""},
71+
{"sslrootcert=testdata/ssl/root.crt sslmode=verify-ca user=pqgossl host=postgres", ""},
7272

7373
// sslmode=verify-full: verify that the certification was signed by a trusted CA and the host matches
7474
{"sslmode=verify-full user=pqgossl host=postgres", "invalid-cert"},
75-
{"sslrootcert=testdata/init/root.crt sslmode=verify-full user=pqgossl host=127.0.0.1", "invalid-cert"},
76-
{"sslrootcert=testdata/init/root.crt sslmode=verify-full user=pqgossl host=postgres-invalid", "invalid-cert"},
77-
{"sslrootcert=testdata/init/root.crt sslmode=verify-full user=pqgossl host=postgres", ""},
75+
{"sslrootcert=testdata/ssl/root.crt sslmode=verify-full user=pqgossl host=127.0.0.1", "invalid-cert"},
76+
{"sslrootcert=testdata/ssl/root.crt sslmode=verify-full user=pqgossl host=postgres-invalid", "invalid-cert"},
77+
{"sslrootcert=testdata/ssl/root.crt sslmode=verify-full user=pqgossl host=postgres", ""},
7878

7979
// With root cert
80-
{"sslrootcert=testdata/init/bogus_root.crt host=postgres sslmode=require user=pqgossl", "invalid-cert"},
81-
{"sslrootcert=testdata/init/non_existent.crt host=127.0.0.1 sslmode=require user=pqgossl", ""},
82-
{"sslrootcert=testdata/init/root.crt host=127.0.0.1 sslmode=require user=pqgossl", ""},
83-
{"sslrootcert=testdata/init/root.crt host=postgres sslmode=require user=pqgossl", ""},
84-
{"sslrootcert=testdata/init/root.crt host=postgres-invalid sslmode=require user=pqgossl", ""},
80+
{"sslrootcert=testdata/ssl/bogus_root.crt host=postgres sslmode=require user=pqgossl", "invalid-cert"},
81+
{"sslrootcert=testdata/ssl/non_existent.crt host=127.0.0.1 sslmode=require user=pqgossl", ""},
82+
{"sslrootcert=testdata/ssl/root.crt host=127.0.0.1 sslmode=require user=pqgossl", ""},
83+
{"sslrootcert=testdata/ssl/root.crt host=postgres sslmode=require user=pqgossl", ""},
84+
{"sslrootcert=testdata/ssl/root.crt host=postgres-invalid sslmode=require user=pqgossl", ""},
8585

8686
// sslmode=prefer
8787
{"sslmode=prefer user=pqgossl", ""},
@@ -138,7 +138,7 @@ func TestSSLClientCertificates(t *testing.T) {
138138
pqtest.SkipPgbouncer(t) // TODO: can't get it to work.
139139
t.Parallel()
140140
startSSLTest(t, "pqgosslcert")
141-
pqtest.Chmod(t, 0o600, "testdata/init/postgresql.key")
141+
pqtest.Chmod(t, 0o600, "testdata/ssl/postgresql.key")
142142

143143
tests := []struct {
144144
connect string
@@ -147,16 +147,16 @@ func TestSSLClientCertificates(t *testing.T) {
147147
{"sslmode=require user=pqgosslcert", "requires a valid client certificate (28000)"},
148148
{"sslmode=require user=pqgosslcert sslcert=''", "requires a valid client certificate (28000)"},
149149
{"sslmode=require user=pqgosslcert sslcert=/tmp/filedoesnotexist", "requires a valid client certificate (28000)"},
150-
{"sslmode=require user=pqgosslcert sslcert=testdata/init/postgresql.crt", "directory"},
151-
{"sslmode=require user=pqgosslcert sslcert=testdata/init/postgresql.crt sslkey=''", "directory"},
152-
{"sslmode=require user=pqgosslcert sslcert=testdata/init/postgresql.crt sslkey=/tmp/filedoesnotexist", "no such file or directory"},
153-
{"sslmode=require user=pqgosslcert sslcert=testdata/init/postgresql.crt sslkey=testdata/init/postgresql.crt", "has world access"},
150+
{"sslmode=require user=pqgosslcert sslcert=testdata/ssl/postgresql.crt", "directory"},
151+
{"sslmode=require user=pqgosslcert sslcert=testdata/ssl/postgresql.crt sslkey=''", "directory"},
152+
{"sslmode=require user=pqgosslcert sslcert=testdata/ssl/postgresql.crt sslkey=/tmp/filedoesnotexist", "no such file or directory"},
153+
{"sslmode=require user=pqgosslcert sslcert=testdata/ssl/postgresql.crt sslkey=testdata/ssl/postgresql.crt", "has world access"},
154154

155-
{"sslmode=require user=pqgosslcert sslcert=testdata/init/postgresql.crt sslkey=testdata/init/postgresql.key", ""},
155+
{"sslmode=require user=pqgosslcert sslcert=testdata/ssl/postgresql.crt sslkey=testdata/ssl/postgresql.key", ""},
156156

157157
{fmt.Sprintf("sslmode=require user=pqgosslcert sslinline=true sslcert='%s' sslkey='%s'",
158-
pqtest.Read(t, "testdata/init/postgresql.crt"),
159-
pqtest.Read(t, "testdata/init/postgresql.key")),
158+
pqtest.Read(t, "testdata/ssl/postgresql.crt"),
159+
pqtest.Read(t, "testdata/ssl/postgresql.key")),
160160
""},
161161
}
162162

@@ -187,7 +187,7 @@ func TestSSLClientCertificateIntermediate(t *testing.T) {
187187
pqtest.SkipPgbouncer(t) // TODO: can't get it to work.
188188
t.Parallel()
189189
startSSLTest(t, "pqgosslcert")
190-
pqtest.Chmod(t, 0o600, "testdata/init/client_intermediate.key")
190+
pqtest.Chmod(t, 0o600, "testdata/ssl/client_intermediate.key")
191191

192192
tests := []struct {
193193
name string
@@ -200,27 +200,27 @@ func TestSSLClientCertificateIntermediate(t *testing.T) {
200200
// so sslAppendIntermediates must send the intermediate in the TLS chain.
201201
name: "file certs",
202202
connect: "sslmode=require user=pqgosslcert " +
203-
"sslrootcert=testdata/init/root+intermediate.crt " +
204-
"sslcert=testdata/init/client_intermediate.crt " +
205-
"sslkey=testdata/init/client_intermediate.key",
203+
"sslrootcert=testdata/ssl/root+intermediate.crt " +
204+
"sslcert=testdata/ssl/client_intermediate.crt " +
205+
"sslkey=testdata/ssl/client_intermediate.key",
206206
},
207207
{
208208
name: "inline certs",
209209
connect: fmt.Sprintf(
210210
"sslmode=require user=pqgosslcert sslinline=true sslrootcert='%s' sslcert='%s' sslkey='%s'",
211-
pqtest.Read(t, "testdata/init/root+intermediate.crt"),
212-
pqtest.Read(t, "testdata/init/client_intermediate.crt"),
213-
pqtest.Read(t, "testdata/init/client_intermediate.key"),
211+
pqtest.Read(t, "testdata/ssl/root+intermediate.crt"),
212+
pqtest.Read(t, "testdata/ssl/client_intermediate.crt"),
213+
pqtest.Read(t, "testdata/ssl/client_intermediate.key"),
214214
),
215215
},
216216
{
217217
// Without the intermediate in sslrootcert, sslAppendIntermediates has
218218
// nothing to append, so the server can't verify the client cert chain.
219219
name: "fails without intermediate in sslrootcert",
220220
connect: "sslmode=require user=pqgosslcert " +
221-
"sslrootcert=testdata/init/root.crt " +
222-
"sslcert=testdata/init/client_intermediate.crt " +
223-
"sslkey=testdata/init/client_intermediate.key",
221+
"sslrootcert=testdata/ssl/root.crt " +
222+
"sslcert=testdata/ssl/client_intermediate.crt " +
223+
"sslkey=testdata/ssl/client_intermediate.key",
224224
wantErr: "unknown certificate authority",
225225
},
226226
}
@@ -376,11 +376,11 @@ func TestSSLDefaults(t *testing.T) {
376376

377377
pqtest.Write(t, []byte("invalid data"), pqutil.Home(true), tt.file)
378378
if tt.file == "postgresql.crt" {
379-
pqtest.Write(t, pqtest.Read(t, "testdata/init/postgresql.key"), pqutil.Home(true), "postgresql.key")
379+
pqtest.Write(t, pqtest.Read(t, "testdata/ssl/postgresql.key"), pqutil.Home(true), "postgresql.key")
380380
pqtest.Chmod(t, 0o600, pqutil.Home(true), "postgresql.key")
381381
}
382382
if tt.file == "postgresql.key" {
383-
pqtest.Write(t, pqtest.Read(t, "testdata/init/postgresql.crt"), pqutil.Home(true), "postgresql.crt")
383+
pqtest.Write(t, pqtest.Read(t, "testdata/ssl/postgresql.crt"), pqutil.Home(true), "postgresql.crt")
384384
pqtest.Chmod(t, 0o600, pqutil.Home(true), "postgresql.key")
385385
}
386386

@@ -393,9 +393,9 @@ func TestSSLDefaults(t *testing.T) {
393393

394394
t.Run("work with default paths", func(t *testing.T) {
395395
pqtest.Home(t)
396-
pqtest.Write(t, pqtest.Read(t, "testdata/init/root.crt"), pqutil.Home(true), "root.crt")
397-
pqtest.Write(t, pqtest.Read(t, "testdata/init/postgresql.crt"), pqutil.Home(true), "postgresql.crt")
398-
pqtest.Write(t, pqtest.Read(t, "testdata/init/postgresql.key"), pqutil.Home(true), "postgresql.key")
396+
pqtest.Write(t, pqtest.Read(t, "testdata/ssl/root.crt"), pqutil.Home(true), "root.crt")
397+
pqtest.Write(t, pqtest.Read(t, "testdata/ssl/postgresql.crt"), pqutil.Home(true), "postgresql.crt")
398+
pqtest.Write(t, pqtest.Read(t, "testdata/ssl/postgresql.key"), pqutil.Home(true), "postgresql.key")
399399
pqtest.Chmod(t, 0o600, pqutil.Home(true), "postgresql.key")
400400
_ = pqtest.MustDB(t, "host=postgres user=pqgosslcert sslmode=verify-ca")
401401
})
@@ -411,7 +411,7 @@ func TestSSLRootCA(t *testing.T) {
411411
testSystemRoots = nil
412412
})
413413
testSystemRoots = x509.NewCertPool()
414-
if !testSystemRoots.AppendCertsFromPEM(pqtest.Read(t, "testdata/init/root.crt")) {
414+
if !testSystemRoots.AppendCertsFromPEM(pqtest.Read(t, "testdata/ssl/root.crt")) {
415415
t.Fatal()
416416
}
417417

testdata/init/pool_passwd

Whitespace-only changes.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ log_stats = 0
1313
verbose = 0
1414

1515
client_tls_sslmode = allow
16-
client_tls_ca_file = /init/root.crt
17-
client_tls_cert_file = /init/server.crt
18-
client_tls_key_file = /init/server.key
16+
client_tls_ca_file = /ssl/root.crt
17+
client_tls_cert_file = /ssl/server.crt
18+
client_tls_key_file = /ssl/server.key

0 commit comments

Comments
 (0)