test: migrate crate to test-containers code (#11165)
This commit is contained in:
parent
56eb914998
commit
94ad7f1bfa
|
|
@ -85,15 +85,3 @@ services:
|
||||||
ports:
|
ports:
|
||||||
- "389:389"
|
- "389:389"
|
||||||
- "636:636"
|
- "636:636"
|
||||||
crate:
|
|
||||||
image: crate/crate
|
|
||||||
ports:
|
|
||||||
- "4200:4200"
|
|
||||||
- "4230:4230"
|
|
||||||
- "6543:5432"
|
|
||||||
command:
|
|
||||||
- crate
|
|
||||||
- -Cnetwork.host=0.0.0.0
|
|
||||||
- -Ctransport.host=localhost
|
|
||||||
environment:
|
|
||||||
- CRATE_HEAP_SIZE=128m
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package cratedb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"os"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -12,25 +12,39 @@ import (
|
||||||
"github.com/influxdata/telegraf/metric"
|
"github.com/influxdata/telegraf/metric"
|
||||||
"github.com/influxdata/telegraf/testutil"
|
"github.com/influxdata/telegraf/testutil"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
"github.com/testcontainers/testcontainers-go/wait"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestConnectAndWriteIntegration(t *testing.T) {
|
func createTestContainer(t *testing.T) testutil.Container {
|
||||||
t.Skip("Skipping due to trust authentication failure")
|
container := testutil.Container{
|
||||||
|
Image: "crate",
|
||||||
|
ExposedPorts: []string{"5432"},
|
||||||
|
Entrypoint: []string{
|
||||||
|
"/docker-entrypoint.sh",
|
||||||
|
"-Cdiscovery.type=single-node",
|
||||||
|
},
|
||||||
|
WaitingFor: wait.ForListeningPort("5432/tcp"),
|
||||||
|
}
|
||||||
|
err := container.Start()
|
||||||
|
require.NoError(t, err, "failed to start container")
|
||||||
|
|
||||||
if os.Getenv("CIRCLE_PROJECT_REPONAME") != "" {
|
return container
|
||||||
t.Skip("Skipping test on CircleCI due to docker failures")
|
}
|
||||||
|
|
||||||
|
func TestConnectAndWriteIntegration(t *testing.T) {
|
||||||
|
if testing.Short() {
|
||||||
|
t.Skip("Skipping integration test in short mode")
|
||||||
}
|
}
|
||||||
|
|
||||||
url := testURL()
|
container := createTestContainer(t)
|
||||||
table := "test-1"
|
defer func() {
|
||||||
|
require.NoError(t, container.Terminate(), "terminating container failed")
|
||||||
|
}()
|
||||||
|
url := fmt.Sprintf("postgres://crate@%s:%s/test", container.Address, container.Port)
|
||||||
|
|
||||||
// dropSQL drops our table before each test. This simplifies changing the
|
table := "testing"
|
||||||
// schema during development :).
|
|
||||||
dropSQL := "DROP TABLE IF EXISTS " + escapeString(table, `"`)
|
|
||||||
db, err := sql.Open("pgx", url)
|
db, err := sql.Open("pgx", url)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
_, err = db.Exec(dropSQL)
|
|
||||||
require.NoError(t, err)
|
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
c := &CrateDB{
|
c := &CrateDB{
|
||||||
|
|
@ -129,13 +143,17 @@ func escapeValueTests() []escapeValueTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_escapeValueIntegration(t *testing.T) {
|
func Test_escapeValueIntegration(t *testing.T) {
|
||||||
t.Skip("Skipping due to trust authentication failure")
|
if testing.Short() {
|
||||||
|
t.Skip("Skipping integration test in short mode")
|
||||||
if os.Getenv("CIRCLE_PROJECT_REPONAME") != "" {
|
|
||||||
t.Skip("Skipping test on CircleCI due to docker failures")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
db, err := sql.Open("pgx", testURL())
|
container := createTestContainer(t)
|
||||||
|
defer func() {
|
||||||
|
require.NoError(t, container.Terminate(), "terminating container failed")
|
||||||
|
}()
|
||||||
|
url := fmt.Sprintf("postgres://crate@%s:%s/test", container.Address, container.Port)
|
||||||
|
|
||||||
|
db, err := sql.Open("pgx", url)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
|
|
@ -228,12 +246,3 @@ func Test_hashID(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:unused // Used in skipped tests
|
|
||||||
func testURL() string {
|
|
||||||
url := os.Getenv("CRATE_URL")
|
|
||||||
if url == "" {
|
|
||||||
return "postgres://" + testutil.GetLocalHost() + ":6543/test?sslmode=disable"
|
|
||||||
}
|
|
||||||
return url
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import (
|
||||||
|
|
||||||
type Container struct {
|
type Container struct {
|
||||||
Image string
|
Image string
|
||||||
|
Entrypoint []string
|
||||||
Env map[string]string
|
Env map[string]string
|
||||||
ExposedPorts []string
|
ExposedPorts []string
|
||||||
WaitingFor wait.Strategy
|
WaitingFor wait.Strategy
|
||||||
|
|
@ -34,6 +35,7 @@ func (c *Container) Start() error {
|
||||||
Env: c.Env,
|
Env: c.Env,
|
||||||
ExposedPorts: c.ExposedPorts,
|
ExposedPorts: c.ExposedPorts,
|
||||||
WaitingFor: c.WaitingFor,
|
WaitingFor: c.WaitingFor,
|
||||||
|
Entrypoint: c.Entrypoint,
|
||||||
},
|
},
|
||||||
Started: true,
|
Started: true,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue