Browse Source

indexer: skip Docker tests when Docker is not available (#7814)

To simplify local testing, do not report failures for tests that require Docker
when Docker is not avaliable. Instead, log a warning and skip the tests.
This has no effect in CI, where Docker is installed.
pull/7820/head
M. J. Fromberger 3 years ago
committed by GitHub
parent
commit
73f605af3f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions
  1. +3
    -0
      internal/state/indexer/indexer_service_test.go
  2. +8
    -1
      internal/state/indexer/sink/psql/psql_test.go

+ 3
- 0
internal/state/indexer/indexer_service_test.go View File

@ -137,6 +137,9 @@ func setupDB(t *testing.T) (*dockertest.Pool, error) {
t.Helper() t.Helper()
pool, err := dockertest.NewPool(os.Getenv("DOCKER_URL")) pool, err := dockertest.NewPool(os.Getenv("DOCKER_URL"))
assert.NoError(t, err) assert.NoError(t, err)
if _, err := pool.Client.Info(); err != nil {
t.Skipf("WARNING: Docker is not available: %v [skipping this test]", err)
}
resource, err = pool.RunWithOptions(&dockertest.RunOptions{ resource, err = pool.RunWithOptions(&dockertest.RunOptions{
Repository: "postgres", Repository: "postgres",


+ 8
- 1
internal/state/indexer/sink/psql/psql_test.go View File

@ -52,12 +52,19 @@ const (
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
flag.Parse() flag.Parse()
// Set up docker and start a container running PostgreSQL.
// Set up docker.
pool, err := dockertest.NewPool(os.Getenv("DOCKER_URL")) pool, err := dockertest.NewPool(os.Getenv("DOCKER_URL"))
if err != nil { if err != nil {
log.Fatalf("Creating docker pool: %v", err) log.Fatalf("Creating docker pool: %v", err)
} }
// If docker is unavailable, log and exit without reporting failure.
if _, err := pool.Client.Info(); err != nil {
log.Printf("WARNING: Docker is not available: %v [skipping this test]", err)
return
}
// Start a container running PostgreSQL.
resource, err := pool.RunWithOptions(&dockertest.RunOptions{ resource, err := pool.RunWithOptions(&dockertest.RunOptions{
Repository: "postgres", Repository: "postgres",
Tag: "13", Tag: "13",


Loading…
Cancel
Save