test: migrate pgbouncer to test-containers (#11186)

This commit is contained in:
Joshua Powers 2022-05-25 10:45:55 -06:00 committed by GitHub
parent 0935ae4a43
commit 22efc25daa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 10 deletions

View File

@ -27,13 +27,6 @@ services:
- xpack.security.enabled=false
ports:
- "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:
image: postgres:alpine
environment:

View File

@ -5,19 +5,52 @@ import (
"testing"
"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go/wait"
"github.com/influxdata/telegraf/plugins/inputs/postgresql"
"github.com/influxdata/telegraf/testutil"
)
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{
Service: postgresql.Service{
Address: fmt.Sprintf(
"host=%s user=pgbouncer password=pgbouncer dbname=pgbouncer port=6432 sslmode=disable",
testutil.GetLocalHost(),
"host=%s user=pgbouncer password=pgbouncer dbname=pgbouncer port=%s sslmode=disable",
container.Address,
container.Port,
),
IsPgBouncer: true,
},