Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: testcontainer hardening #11245

Merged
merged 1 commit into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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