Skip to content

Commit

Permalink
test: harden running of testcontainer integration tests (#11245)
Browse files Browse the repository at this point in the history
  • Loading branch information
powersj authored and MyaLongmire committed Jul 6, 2022
1 parent 27d96ff commit 524054a
Show file tree
Hide file tree
Showing 9 changed files with 234 additions and 289 deletions.
14 changes: 7 additions & 7 deletions plugins/inputs/elasticsearch_query/elasticsearch_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ var testEsAggregationData = []esAggregationQueryTest{
},
}

func setupIntegrationTest(t *testing.T) (testutil.Container, error) {
func setupIntegrationTest(t *testing.T) (*testutil.Container, error) {
type nginxlog struct {
IPaddress string `json:"IP"`
Timestamp time.Time `json:"@timestamp"`
Expand Down Expand Up @@ -542,15 +542,15 @@ func setupIntegrationTest(t *testing.T) (testutil.Container, error) {

err = e.connectToES()
if err != nil {
return container, err
return &container, err
}

bulkRequest := e.esClient.Bulk()

// populate elasticsearch with nginx_logs test data file
file, err := os.Open("testdata/nginx_logs")
if err != nil {
return container, err
return &container, err
}

defer file.Close()
Expand Down Expand Up @@ -579,22 +579,22 @@ func setupIntegrationTest(t *testing.T) (testutil.Container, error) {
Doc(logline))
}
if scanner.Err() != nil {
return container, err
return &container, err
}

_, err = bulkRequest.Do(context.Background())
if err != nil {
return container, err
return &container, err
}

// force elastic to refresh indexes to get new batch data
ctx := context.Background()
_, err = e.esClient.Refresh().Do(ctx)
if err != nil {
return container, err
return &container, err
}

return container, nil
return &container, nil
}

func TestElasticsearchQuery(t *testing.T) {
Expand Down
10 changes: 8 additions & 2 deletions plugins/inputs/mysql/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ func TestMysqlDefaultsToLocalIntegration(t *testing.T) {
"MYSQL_ALLOW_EMPTY_PASSWORD": "yes",
},
ExposedPorts: []string{servicePort},
WaitingFor: wait.ForListeningPort(nat.Port(servicePort)),
WaitingFor: wait.ForAll(
wait.ForLog("/usr/sbin/mysqld: ready for connections"),
wait.ForListeningPort(nat.Port(servicePort)),
),
}

err := container.Start()
Expand Down Expand Up @@ -59,7 +62,10 @@ func TestMysqlMultipleInstancesIntegration(t *testing.T) {
"MYSQL_ALLOW_EMPTY_PASSWORD": "yes",
},
ExposedPorts: []string{servicePort},
WaitingFor: wait.ForListeningPort(nat.Port(servicePort)),
WaitingFor: wait.ForAll(
wait.ForLog("/usr/sbin/mysqld: ready for connections"),
wait.ForListeningPort(nat.Port(servicePort)),
),
}

err := container.Start()
Expand Down
12 changes: 6 additions & 6 deletions plugins/inputs/openldap/openldap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestOpenldapGeneratesMetricsIntegration(t *testing.T) {
"LDAP_ADMIN_PASSWORD": "secret",
},
WaitingFor: wait.ForAll(
wait.ForLog("Starting slapd"),
wait.ForLog("slapd starting"),
wait.ForListeningPort(nat.Port(servicePort)),
),
}
Expand Down Expand Up @@ -128,7 +128,7 @@ func TestOpenldapStartTLSIntegration(t *testing.T) {
"/server.key": tlsKey,
},
WaitingFor: wait.ForAll(
wait.ForLog("Starting slapd"),
wait.ForLog("slapd starting"),
wait.ForListeningPort(nat.Port(servicePort)),
),
}
Expand Down Expand Up @@ -191,7 +191,7 @@ func TestOpenldapLDAPSIntegration(t *testing.T) {
"/server.key": tlsKey,
},
WaitingFor: wait.ForAll(
wait.ForLog("Starting slapd"),
wait.ForLog("slapd starting"),
wait.ForListeningPort(nat.Port(servicePortSecure)),
),
}
Expand Down Expand Up @@ -249,7 +249,7 @@ func TestOpenldapInvalidSSLIntegration(t *testing.T) {
"/server.key": tlsKey,
},
WaitingFor: wait.ForAll(
wait.ForLog("Starting slapd"),
wait.ForLog("slapd starting"),
wait.ForListeningPort(nat.Port(servicePortSecure)),
),
}
Expand Down Expand Up @@ -289,7 +289,7 @@ func TestOpenldapBindIntegration(t *testing.T) {
"LDAP_ADMIN_PASSWORD": "secret",
},
WaitingFor: wait.ForAll(
wait.ForLog("Starting slapd"),
wait.ForLog("slapd starting"),
wait.ForListeningPort(nat.Port(servicePort)),
),
}
Expand Down Expand Up @@ -341,7 +341,7 @@ func TestOpenldapReverseMetricsIntegration(t *testing.T) {
"LDAP_ADMIN_PASSWORD": "secret",
},
WaitingFor: wait.ForAll(
wait.ForLog("Starting slapd"),
wait.ForLog("slapd starting"),
wait.ForListeningPort(nat.Port(servicePort)),
),
}
Expand Down
5 changes: 4 additions & 1 deletion plugins/inputs/pgbouncer/pgbouncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ func TestPgBouncerGeneratesMetricsIntegration(t *testing.T) {
"PG_ENV_POSTGRESQL_USER": "pgbouncer",
"PG_ENV_POSTGRESQL_PASS": "pgbouncer",
},
WaitingFor: wait.ForListeningPort(nat.Port(pgBouncerServicePort)),
WaitingFor: wait.ForAll(
wait.ForListeningPort(nat.Port(pgBouncerServicePort)),
wait.ForLog("LOG process up"),
),
}
err = container.Start()
require.NoError(t, err, "failed to start container")
Expand Down
Loading

0 comments on commit 524054a

Please sign in to comment.