Skip to content

Commit

Permalink
test: migrate pgbouncer to test-containers (#11186)
Browse files Browse the repository at this point in the history
  • Loading branch information
powersj authored May 25, 2022
1 parent 0935ae4 commit 22efc25
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
7 changes: 0 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
39 changes: 36 additions & 3 deletions plugins/inputs/pgbouncer/pgbouncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down

0 comments on commit 22efc25

Please sign in to comment.