test: migrate pgbouncer to test-containers (#11186)
This commit is contained in:
parent
0935ae4a43
commit
22efc25daa
|
|
@ -27,13 +27,6 @@ services:
|
||||||
- xpack.security.enabled=false
|
- xpack.security.enabled=false
|
||||||
ports:
|
ports:
|
||||||
- "9200:9200"
|
- "9200:9200"
|
||||||
pgbouncer:
|
|
||||||
image: z9pascal/pgbouncer-container:1.15-latest
|
|
||||||
environment:
|
|
||||||
- PG_ENV_POSTGRESQL_USER=pgbouncer
|
|
||||||
- PG_ENV_POSTGRESQL_PASS=pgbouncer
|
|
||||||
ports:
|
|
||||||
- "6432:6432"
|
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:alpine
|
image: postgres:alpine
|
||||||
environment:
|
environment:
|
||||||
|
|
|
||||||
|
|
@ -5,19 +5,52 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
"github.com/testcontainers/testcontainers-go/wait"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf/plugins/inputs/postgresql"
|
"github.com/influxdata/telegraf/plugins/inputs/postgresql"
|
||||||
"github.com/influxdata/telegraf/testutil"
|
"github.com/influxdata/telegraf/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPgBouncerGeneratesMetricsIntegration(t *testing.T) {
|
func TestPgBouncerGeneratesMetricsIntegration(t *testing.T) {
|
||||||
t.Skip("Skipping test, connection refused")
|
if testing.Short() {
|
||||||
|
t.Skip("Skipping integration test in short mode")
|
||||||
|
}
|
||||||
|
|
||||||
|
backend := testutil.Container{
|
||||||
|
Image: "postgres:alpine",
|
||||||
|
ExposedPorts: []string{"5432"},
|
||||||
|
Env: map[string]string{
|
||||||
|
"POSTGRES_HOST_AUTH_METHOD": "trust",
|
||||||
|
},
|
||||||
|
WaitingFor: wait.ForLog("database system is ready to accept connections"),
|
||||||
|
}
|
||||||
|
err := backend.Start()
|
||||||
|
require.NoError(t, err, "failed to start container")
|
||||||
|
defer func() {
|
||||||
|
require.NoError(t, backend.Terminate(), "terminating container failed")
|
||||||
|
}()
|
||||||
|
|
||||||
|
container := testutil.Container{
|
||||||
|
Image: "z9pascal/pgbouncer-container:1.17.0-latest",
|
||||||
|
ExposedPorts: []string{"6432"},
|
||||||
|
Env: map[string]string{
|
||||||
|
"PG_ENV_POSTGRESQL_USER": "pgbouncer",
|
||||||
|
"PG_ENV_POSTGRESQL_PASS": "pgbouncer",
|
||||||
|
},
|
||||||
|
WaitingFor: wait.ForListeningPort("6432"),
|
||||||
|
}
|
||||||
|
err = container.Start()
|
||||||
|
require.NoError(t, err, "failed to start container")
|
||||||
|
defer func() {
|
||||||
|
require.NoError(t, container.Terminate(), "terminating container failed")
|
||||||
|
}()
|
||||||
|
|
||||||
p := &PgBouncer{
|
p := &PgBouncer{
|
||||||
Service: postgresql.Service{
|
Service: postgresql.Service{
|
||||||
Address: fmt.Sprintf(
|
Address: fmt.Sprintf(
|
||||||
"host=%s user=pgbouncer password=pgbouncer dbname=pgbouncer port=6432 sslmode=disable",
|
"host=%s user=pgbouncer password=pgbouncer dbname=pgbouncer port=%s sslmode=disable",
|
||||||
testutil.GetLocalHost(),
|
container.Address,
|
||||||
|
container.Port,
|
||||||
),
|
),
|
||||||
IsPgBouncer: true,
|
IsPgBouncer: true,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue