Skip to content

Commit

Permalink
test: remove unecessary flag in sql input (#11115)
Browse files Browse the repository at this point in the history
  • Loading branch information
powersj authored and MyaLongmire committed Jul 6, 2022
1 parent 8dfb184 commit 4ebbaee
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 108 deletions.
195 changes: 93 additions & 102 deletions plugins/inputs/sql/sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package sql

import (
"context"
"flag"
"fmt"
"testing"
"time"
Expand Down Expand Up @@ -31,8 +30,6 @@ func pwgen(n int) string {
return string(buffer)
}

var spinup = flag.Bool("spinup", false, "Spin-up the required test containers")

func TestMariaDB(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration test in short mode")
Expand All @@ -45,46 +42,44 @@ func TestMariaDB(t *testing.T) {
passwd := ""
database := "foo"

if *spinup {
logger.Infof("Spinning up container...")
logger.Infof("Spinning up container...")

// Generate a random password
passwd = pwgen(32)
// Generate a random password
passwd = pwgen(32)

// Determine the test-data mountpoint
testdata, err := filepath.Abs("testdata/mariadb")
require.NoError(t, err, "determining absolute path of test-data failed")
// Determine the test-data mountpoint
testdata, err := filepath.Abs("testdata/mariadb")
require.NoError(t, err, "determining absolute path of test-data failed")

// Spin-up the container
ctx := context.Background()
req := testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Image: "mariadb",
Env: map[string]string{
"MYSQL_ROOT_PASSWORD": passwd,
"MYSQL_DATABASE": database,
},
BindMounts: map[string]string{
testdata: "/docker-entrypoint-initdb.d",
},
ExposedPorts: []string{"3306/tcp"},
WaitingFor: wait.ForListeningPort("3306/tcp"),
// Spin-up the container
ctx := context.Background()
req := testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Image: "mariadb",
Env: map[string]string{
"MYSQL_ROOT_PASSWORD": passwd,
"MYSQL_DATABASE": database,
},
Started: true,
}
container, err := testcontainers.GenericContainer(ctx, req)
require.NoError(t, err, "starting container failed")
defer func() {
require.NoError(t, container.Terminate(ctx), "terminating container failed")
}()

// Get the connection details from the container
addr, err = container.Host(ctx)
require.NoError(t, err, "getting container host address failed")
p, err := container.MappedPort(ctx, "3306/tcp")
require.NoError(t, err, "getting container host port failed")
port = p.Port()
BindMounts: map[string]string{
"/docker-entrypoint-initdb.d": testdata,
},
ExposedPorts: []string{"3306/tcp"},
WaitingFor: wait.ForListeningPort("3306/tcp"),
},
Started: true,
}
container, err := testcontainers.GenericContainer(ctx, req)
require.NoError(t, err, "starting container failed")
defer func() {
require.NoError(t, container.Terminate(ctx), "terminating container failed")
}()

// Get the connection details from the container
addr, err = container.Host(ctx)
require.NoError(t, err, "getting container host address failed")
p, err := container.MappedPort(ctx, "3306/tcp")
require.NoError(t, err, "getting container host port failed")
port = p.Port()

// Define the testset
var testset = []struct {
Expand Down Expand Up @@ -164,46 +159,44 @@ func TestPostgreSQL(t *testing.T) {
passwd := ""
database := "foo"

if *spinup {
logger.Infof("Spinning up container...")
logger.Infof("Spinning up container...")

// Generate a random password
passwd = pwgen(32)
// Generate a random password
passwd = pwgen(32)

// Determine the test-data mountpoint
testdata, err := filepath.Abs("testdata/postgres")
require.NoError(t, err, "determining absolute path of test-data failed")
// Determine the test-data mountpoint
testdata, err := filepath.Abs("testdata/postgres")
require.NoError(t, err, "determining absolute path of test-data failed")

// Spin-up the container
ctx := context.Background()
req := testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Image: "postgres",
Env: map[string]string{
"POSTGRES_PASSWORD": passwd,
"POSTGRES_DB": database,
},
BindMounts: map[string]string{
testdata: "/docker-entrypoint-initdb.d",
},
ExposedPorts: []string{"5432/tcp"},
WaitingFor: wait.ForListeningPort("5432/tcp"),
// Spin-up the container
ctx := context.Background()
req := testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Image: "postgres",
Env: map[string]string{
"POSTGRES_PASSWORD": passwd,
"POSTGRES_DB": database,
},
BindMounts: map[string]string{
"/docker-entrypoint-initdb.d": testdata,
},
Started: true,
}
container, err := testcontainers.GenericContainer(ctx, req)
require.NoError(t, err, "starting container failed")
defer func() {
require.NoError(t, container.Terminate(ctx), "terminating container failed")
}()

// Get the connection details from the container
addr, err = container.Host(ctx)
require.NoError(t, err, "getting container host address failed")
p, err := container.MappedPort(ctx, "5432/tcp")
require.NoError(t, err, "getting container host port failed")
port = p.Port()
ExposedPorts: []string{"5432/tcp"},
WaitingFor: wait.ForListeningPort("5432/tcp"),
},
Started: true,
}
container, err := testcontainers.GenericContainer(ctx, req)
require.NoError(t, err, "starting container failed")
defer func() {
require.NoError(t, container.Terminate(ctx), "terminating container failed")
}()

// Get the connection details from the container
addr, err = container.Host(ctx)
require.NoError(t, err, "getting container host address failed")
p, err := container.MappedPort(ctx, "5432/tcp")
require.NoError(t, err, "getting container host port failed")
port = p.Port()

// Define the testset
var testset = []struct {
Expand Down Expand Up @@ -282,39 +275,37 @@ func TestClickHouse(t *testing.T) {
port := "9000"
user := "default"

if *spinup {
logger.Infof("Spinning up container...")
logger.Infof("Spinning up container...")

// Determine the test-data mountpoint
testdata, err := filepath.Abs("testdata/clickhouse")
require.NoError(t, err, "determining absolute path of test-data failed")
// Determine the test-data mountpoint
testdata, err := filepath.Abs("testdata/clickhouse")
require.NoError(t, err, "determining absolute path of test-data failed")

// Spin-up the container
ctx := context.Background()
req := testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Image: "yandex/clickhouse-server",
BindMounts: map[string]string{
testdata: "/docker-entrypoint-initdb.d",
},
ExposedPorts: []string{"9000/tcp", "8123/tcp"},
WaitingFor: wait.NewHTTPStrategy("/").WithPort("8123/tcp"),
// Spin-up the container
ctx := context.Background()
req := testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
Image: "yandex/clickhouse-server",
BindMounts: map[string]string{
"/docker-entrypoint-initdb.d": testdata,
},
Started: true,
}
container, err := testcontainers.GenericContainer(ctx, req)
require.NoError(t, err, "starting container failed")
defer func() {
require.NoError(t, container.Terminate(ctx), "terminating container failed")
}()

// Get the connection details from the container
addr, err = container.Host(ctx)
require.NoError(t, err, "getting container host address failed")
p, err := container.MappedPort(ctx, "9000/tcp")
require.NoError(t, err, "getting container host port failed")
port = p.Port()
ExposedPorts: []string{"9000/tcp", "8123/tcp"},
WaitingFor: wait.NewHTTPStrategy("/").WithPort("8123/tcp"),
},
Started: true,
}
container, err := testcontainers.GenericContainer(ctx, req)
require.NoError(t, err, "starting container failed")
defer func() {
require.NoError(t, container.Terminate(ctx), "terminating container failed")
}()

// Get the connection details from the container
addr, err = container.Host(ctx)
require.NoError(t, err, "getting container host address failed")
p, err := container.MappedPort(ctx, "9000/tcp")
require.NoError(t, err, "getting container host port failed")
port = p.Port()

// Define the testset
var testset = []struct {
Expand Down
12 changes: 6 additions & 6 deletions plugins/outputs/sql/sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ func TestMysqlIntegration(t *testing.T) {
"MARIADB_ROOT_PASSWORD": password,
},
BindMounts: map[string]string{
initdb: "/docker-entrypoint-initdb.d",
outDir: "/out",
"/docker-entrypoint-initdb.d": initdb,
"/out": outDir,
},
ExposedPorts: []string{"3306/tcp"},
WaitingFor: wait.ForListeningPort("3306/tcp"),
Expand Down Expand Up @@ -267,8 +267,8 @@ func TestPostgresIntegration(t *testing.T) {
"POSTGRES_PASSWORD": password,
},
BindMounts: map[string]string{
initdb: "/docker-entrypoint-initdb.d",
outDir: "/out",
"/docker-entrypoint-initdb.d": initdb,
"/out": outDir,
},
ExposedPorts: []string{"5432/tcp"},
WaitingFor: wait.ForListeningPort("5432/tcp"),
Expand Down Expand Up @@ -364,8 +364,8 @@ func TestClickHouseIntegration(t *testing.T) {
ContainerRequest: testcontainers.ContainerRequest{
Image: "yandex/clickhouse-server",
BindMounts: map[string]string{
initdb: "/docker-entrypoint-initdb.d",
outDir: "/out",
"/docker-entrypoint-initdb.d": initdb,
"/out": outDir,
},
ExposedPorts: []string{"9000/tcp", "8123/tcp"},
WaitingFor: wait.NewHTTPStrategy("/").WithPort("8123/tcp"),
Expand Down

0 comments on commit 4ebbaee

Please sign in to comment.