diff --git a/.github/settings.yml b/.github/settings.yml index 82898f8762..b1e3ed8e12 100644 --- a/.github/settings.yml +++ b/.github/settings.yml @@ -183,7 +183,7 @@ branches: # Required. Require branches to be up to date before merging. strict: true # Required. The list of status checks to require in order to merge into this branch - contexts: ["static-analysis", "test (1.x, ubuntu-latest) / ./ubuntu-latest/1.x"] + contexts: ["test (1.x, ubuntu-latest) / ./ubuntu-latest/1.x"] # Required. Enforce all configured restrictions for administrators. Set to true to enforce required status checks for repository administrators. Set to null to disable. enforce_admins: false # Prevent merge commits from being pushed to matching branches diff --git a/.github/workflows/ci-test-go.yml b/.github/workflows/ci-test-go.yml index 5f2a91588a..4748634ee0 100644 --- a/.github/workflows/ci-test-go.yml +++ b/.github/workflows/ci-test-go.yml @@ -33,6 +33,11 @@ on: default: false description: "Disable the ryuk container for the test." +permissions: + contents: read + # Optional: allow read access to pull request. Use with `only-new-issues` option. + # pull-requests: read + jobs: test-go-project: name: "${{ inputs.project-directory }}/${{ inputs.platform }}/${{ inputs.go-version }}" @@ -48,14 +53,30 @@ jobs: if: ${{ inputs.rootless-docker }} run: sudo rm -rf /var/run/docker.sock + - name: Check out code into the Go module directory + uses: actions/checkout@v3 + - name: Set up Go uses: actions/setup-go@v4 with: - go-version: ${{ inputs.go-version }} + go-version: '${{ inputs.go-version }}' + cache-dependency-path: '${{ inputs.project-directory }}/go.sum' id: go - - name: Check out code into the Go module directory - uses: actions/checkout@v3 + - name: golangci-lint + # TODO: Remove each example/module once it passes the golangci-lint + if: ${{ inputs.platform == 'ubuntu-latest' && inputs.go-version == '1.20.x' && !contains(fromJSON('["examples/cockroachdb", "examples/spanner", "examples/toxiproxy", "modules/compose", "modules/pulsar", "modules/redis"]'), inputs.project-directory) }} + uses: golangci/golangci-lint-action@v3 + with: + # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version + version: v1.54.1 + # Optional: working directory, useful for monorepos + working-directory: ${{ inputs.project-directory }} + # Optional: golangci-lint command line arguments. + args: --verbose + # Optional: if set to true then the all caching functionality will be complete disabled, + # takes precedence over all other caching options. + skip-cache: true - name: modVerify working-directory: ./${{ inputs.project-directory }} diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml deleted file mode 100644 index 813df6f282..0000000000 --- a/.github/workflows/golangci-lint.yml +++ /dev/null @@ -1,51 +0,0 @@ -name: golangci-lint / static-analysis -on: - push: - tags: - - v* - branches: - - main - pull_request: - -concurrency: - group: "${{ github.workflow }}-${{ github.head_ref || github.sha }}" - cancel-in-progress: true - -permissions: - contents: read - # Optional: allow read access to pull request. Use with `only-new-issues` option. - # pull-requests: read - -jobs: - static-analysis: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v4 - with: - go-version-file: go.mod - - name: golangci-lint - uses: golangci/golangci-lint-action@v3 - with: - # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version - version: v1.54.1 - - # Optional: working directory, useful for monorepos - # working-directory: somedir - - # Optional: golangci-lint command line arguments. - # args: --issues-exit-code=0 - args: --verbose - - # Optional: show only new issues if it's a pull request. The default value is `false`. - # only-new-issues: true - - # Optional: if set to true then the all caching functionality will be complete disabled, - # takes precedence over all other caching options. - # skip-cache: true - - # Optional: if set to true then the action don't cache or restore ~/go/pkg. - # skip-pkg-cache: true - - # Optional: if set to true then the action don't cache or restore ~/.cache/go-build. - # skip-build-cache: true diff --git a/.golangci.yml b/.golangci.yml index 6d4d77a746..8c02d880c6 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,16 +1,15 @@ linters: enable: - gci - - gofmt + - gofumpt - misspell - linters-settings: gci: sections: - - standard - - default - - prefix(github.com/testcontainters) + - standard + - default + - prefix(github.com/testcontainers) run: timeout: 5m diff --git a/config_test.go b/config_test.go index bf4ce23adc..e2c803b904 100644 --- a/config_test.go +++ b/config_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/testcontainers/testcontainers-go/internal/config" ) diff --git a/container.go b/container.go index ec2351ea20..7dbd544ff2 100644 --- a/container.go +++ b/container.go @@ -14,6 +14,7 @@ import ( "github.com/docker/docker/api/types/registry" "github.com/docker/docker/pkg/archive" "github.com/docker/go-connections/nat" + tcexec "github.com/testcontainers/testcontainers-go/exec" "github.com/testcontainers/testcontainers-go/internal/testcontainersdocker" "github.com/testcontainers/testcontainers-go/wait" diff --git a/container_test.go b/container_test.go index 37bd04a373..b417822986 100644 --- a/container_test.go +++ b/container_test.go @@ -12,11 +12,11 @@ import ( "time" "github.com/stretchr/testify/assert" + "github.com/testcontainers/testcontainers-go/wait" ) func Test_ContainerValidation(t *testing.T) { - type ContainerValidationTestCase struct { Name string ExpectedError error @@ -71,13 +71,14 @@ func Test_ContainerValidation(t *testing.T) { for _, testCase := range testTable { t.Run(testCase.Name, func(t *testing.T) { err := testCase.ContainerRequest.Validate() - if err == nil && testCase.ExpectedError == nil { + switch { + case err == nil && testCase.ExpectedError == nil: return - } else if err == nil && testCase.ExpectedError != nil { + case err == nil && testCase.ExpectedError != nil: t.Errorf("did not receive expected error: %s", testCase.ExpectedError.Error()) - } else if err != nil && testCase.ExpectedError == nil { + case err != nil && testCase.ExpectedError == nil: t.Errorf("received unexpected error: %s", err.Error()) - } else if err.Error() != testCase.ExpectedError.Error() { + case err.Error() != testCase.ExpectedError.Error(): t.Errorf("errors mismatch: %s != %s", err.Error(), testCase.ExpectedError.Error()) } }) @@ -155,7 +156,7 @@ func Test_BuildImageWithContexts(t *testing.T) { for _, f := range files { header := tar.Header{ Name: f.Name, - Mode: 0777, + Mode: 0o777, Size: int64(len(f.Contents)), Typeflag: tar.TypeReg, Format: tar.FormatGNU, @@ -271,13 +272,14 @@ func Test_BuildImageWithContexts(t *testing.T) { ContainerRequest: req, Started: true, }) - if testCase.ExpectedError != nil && err != nil { + switch { + case testCase.ExpectedError != nil && err != nil: if testCase.ExpectedError.Error() != err.Error() { t.Fatalf("unexpected error: %s, was expecting %s", err.Error(), testCase.ExpectedError.Error()) } - } else if err != nil { + case err != nil: t.Fatal(err) - } else { + default: terminateContainerOnEnd(t, ctx, c) } }) diff --git a/docker.go b/docker.go index 4e6574ce36..51b7c562f9 100644 --- a/docker.go +++ b/docker.go @@ -31,6 +31,7 @@ import ( "github.com/google/uuid" "github.com/moby/term" specs "github.com/opencontainers/image-spec/specs-go/v1" + tcexec "github.com/testcontainers/testcontainers-go/exec" "github.com/testcontainers/testcontainers-go/internal" "github.com/testcontainers/testcontainers-go/internal/testcontainersdocker" @@ -316,7 +317,6 @@ func (c *DockerContainer) inspectContainer(ctx context.Context) (*types.Containe // Logs will fetch both STDOUT and STDERR from the current container. Returns a // ReadCloser and leaves it up to the caller to extract what it wants. func (c *DockerContainer) Logs(ctx context.Context) (io.ReadCloser, error) { - const streamHeaderSize = 8 options := types.ContainerLogsOptions{ @@ -334,7 +334,7 @@ func (c *DockerContainer) Logs(ctx context.Context) (io.ReadCloser, error) { r := bufio.NewReader(rc) go func() { - var lineStarted = true + lineStarted := true for err == nil { line, isPrefix, err := r.ReadLine() diff --git a/docker_auth.go b/docker_auth.go index 5a5c40ad84..db678a3981 100644 --- a/docker_auth.go +++ b/docker_auth.go @@ -8,6 +8,7 @@ import ( "github.com/cpuguy83/dockercfg" "github.com/docker/docker/api/types/registry" + "github.com/testcontainers/testcontainers-go/internal/testcontainersdocker" ) diff --git a/docker_auth_test.go b/docker_auth_test.go index 77d6cb3cd5..87c32d4e55 100644 --- a/docker_auth_test.go +++ b/docker_auth_test.go @@ -12,6 +12,7 @@ import ( "github.com/docker/docker/client" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/testcontainers/testcontainers-go/internal/testcontainersdocker" "github.com/testcontainers/testcontainers-go/wait" ) diff --git a/docker_exec_test.go b/docker_exec_test.go index a31b1eeb01..e925fc0f1f 100644 --- a/docker_exec_test.go +++ b/docker_exec_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/stretchr/testify/require" + tcexec "github.com/testcontainers/testcontainers-go/exec" ) diff --git a/docker_mounts.go b/docker_mounts.go index bb63dc0479..fa3e825c4b 100644 --- a/docker_mounts.go +++ b/docker_mounts.go @@ -2,14 +2,12 @@ package testcontainers import "github.com/docker/docker/api/types/mount" -var ( - mountTypeMapping = map[MountType]mount.Type{ - MountTypeBind: mount.TypeBind, - MountTypeVolume: mount.TypeVolume, - MountTypeTmpfs: mount.TypeTmpfs, - MountTypePipe: mount.TypeNamedPipe, - } -) +var mountTypeMapping = map[MountType]mount.Type{ + MountTypeBind: mount.TypeBind, + MountTypeVolume: mount.TypeVolume, + MountTypeTmpfs: mount.TypeTmpfs, + MountTypePipe: mount.TypeNamedPipe, +} // BindMounter can optionally be implemented by mount sources // to support advanced scenarios based on mount.BindOptions diff --git a/docker_test.go b/docker_test.go index b3a05af2aa..d0527223dd 100644 --- a/docker_test.go +++ b/docker_test.go @@ -24,6 +24,7 @@ import ( "github.com/docker/go-units" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/testcontainers/testcontainers-go/internal/config" "github.com/testcontainers/testcontainers-go/internal/testcontainersdocker" "github.com/testcontainers/testcontainers-go/wait" @@ -2190,7 +2191,7 @@ func TestNetworkModeWithContainerReference(t *testing.T) { // creates a temporary dir in which the files will be extracted. Then it will compare the bytes of each file in the source with the bytes from the copied-from-container file func assertExtractedFiles(t *testing.T, ctx context.Context, container Container, hostFilePath string, containerFilePath string) { // create all copied files into a temporary dir - tmpDir := filepath.Join(t.TempDir()) + tmpDir := t.TempDir() // compare the bytes of each file in the source with the bytes from the copied-from-container file srcFiles, err := os.ReadDir(hostFilePath) diff --git a/examples/bigtable/bigtable.go b/examples/bigtable/bigtable.go index f6c32bac7d..7ff43b78c5 100644 --- a/examples/bigtable/bigtable.go +++ b/examples/bigtable/bigtable.go @@ -4,9 +4,8 @@ import ( "context" "fmt" - "github.com/testcontainers/testcontainers-go/wait" - "github.com/testcontainers/testcontainers-go" + "github.com/testcontainers/testcontainers-go/wait" ) // bigtableContainer represents the bigtable container type used in the module diff --git a/examples/bigtable/bigtable_test.go b/examples/bigtable/bigtable_test.go index f724ee8585..7d6c6dc94f 100644 --- a/examples/bigtable/bigtable_test.go +++ b/examples/bigtable/bigtable_test.go @@ -1,12 +1,13 @@ package bigtable import ( - "cloud.google.com/go/bigtable" "context" + "testing" + + "cloud.google.com/go/bigtable" "google.golang.org/api/option" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" - "testing" ) const ( diff --git a/examples/cockroachdb/cockroachdb.go b/examples/cockroachdb/cockroachdb.go index 176c1a371d..08b05a440b 100644 --- a/examples/cockroachdb/cockroachdb.go +++ b/examples/cockroachdb/cockroachdb.go @@ -5,6 +5,7 @@ import ( "fmt" _ "github.com/jackc/pgx/v4/stdlib" + "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/wait" ) diff --git a/examples/datastore/datastore_test.go b/examples/datastore/datastore_test.go index f8a45ee828..3bf5007463 100644 --- a/examples/datastore/datastore_test.go +++ b/examples/datastore/datastore_test.go @@ -1,12 +1,13 @@ package datastore import ( - "cloud.google.com/go/datastore" "context" + "testing" + + "cloud.google.com/go/datastore" "google.golang.org/api/option" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" - "testing" ) type Task struct { diff --git a/examples/firestore/firestore.go b/examples/firestore/firestore.go index 4e0ef27d06..63ba9cae26 100644 --- a/examples/firestore/firestore.go +++ b/examples/firestore/firestore.go @@ -4,9 +4,8 @@ import ( "context" "fmt" - "github.com/testcontainers/testcontainers-go/wait" - "github.com/testcontainers/testcontainers-go" + "github.com/testcontainers/testcontainers-go/wait" ) // firestoreContainer represents the firestore container type used in the module diff --git a/examples/firestore/firestore_test.go b/examples/firestore/firestore_test.go index 398fdac767..e20de884de 100644 --- a/examples/firestore/firestore_test.go +++ b/examples/firestore/firestore_test.go @@ -1,12 +1,13 @@ package firestore import ( - "cloud.google.com/go/firestore" "context" + "testing" + + "cloud.google.com/go/firestore" "google.golang.org/api/option" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" - "testing" ) type Person struct { @@ -14,12 +15,12 @@ type Person struct { Lastname string `json:"lastname"` } -type emulatorCreds struct { -} +type emulatorCreds struct{} func (ec emulatorCreds) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) { return map[string]string{"authorization": "Bearer owner"}, nil } + func (ec emulatorCreds) RequireTransportSecurity() bool { return false } diff --git a/examples/nats/nats.go b/examples/nats/nats.go index 4ce61a7713..517414938f 100644 --- a/examples/nats/nats.go +++ b/examples/nats/nats.go @@ -47,7 +47,7 @@ func runContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize return nil, err } - uri:= fmt.Sprintf("nats://%s:%s", hostIP, mappedPort.Port()) + uri := fmt.Sprintf("nats://%s:%s", hostIP, mappedPort.Port()) return &natsContainer{Container: container, URI: uri}, nil } diff --git a/examples/nats/nats_test.go b/examples/nats/nats_test.go index c894da5528..d4ef04d200 100644 --- a/examples/nats/nats_test.go +++ b/examples/nats/nats_test.go @@ -63,4 +63,3 @@ func TestNats(t *testing.T) { t.Fatalf("expected message to be 'hello', got '%s'", msg.Data) } } - diff --git a/examples/pubsub/pubsub_test.go b/examples/pubsub/pubsub_test.go index 67c97bd38d..21fdea7ce7 100644 --- a/examples/pubsub/pubsub_test.go +++ b/examples/pubsub/pubsub_test.go @@ -1,12 +1,13 @@ package pubsub import ( - "cloud.google.com/go/pubsub" "context" + "testing" + + "cloud.google.com/go/pubsub" "google.golang.org/api/option" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" - "testing" ) func TestPubsub(t *testing.T) { @@ -58,6 +59,9 @@ func TestPubsub(t *testing.T) { m.Ack() defer cancel() }) + if err != nil { + t.Fatal(err) + } if string(data) != "Hello World" { t.Fatalf("Expected value %s. Got %s.", "Hello World", data) } diff --git a/examples/spanner/spanner.go b/examples/spanner/spanner.go index ad8f3370af..84093c13ff 100644 --- a/examples/spanner/spanner.go +++ b/examples/spanner/spanner.go @@ -4,9 +4,8 @@ import ( "context" "fmt" - "github.com/testcontainers/testcontainers-go/wait" - "github.com/testcontainers/testcontainers-go" + "github.com/testcontainers/testcontainers-go/wait" ) // spannerContainer represents the spanner container type used in the module diff --git a/examples/spanner/spanner_test.go b/examples/spanner/spanner_test.go index 3715dc88ae..e26eb5c42e 100644 --- a/examples/spanner/spanner_test.go +++ b/examples/spanner/spanner_test.go @@ -1,18 +1,19 @@ package spanner import ( + "context" + "fmt" + "testing" + "cloud.google.com/go/spanner" database "cloud.google.com/go/spanner/admin/database/apiv1" instance "cloud.google.com/go/spanner/admin/instance/apiv1" - "context" - "fmt" "google.golang.org/api/option" "google.golang.org/api/option/internaloption" databasepb "google.golang.org/genproto/googleapis/spanner/admin/database/v1" instancepb "google.golang.org/genproto/googleapis/spanner/admin/instance/v1" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" - "testing" ) const ( @@ -95,7 +96,8 @@ func TestSpanner(t *testing.T) { _, err = client.Apply(ctx, []*spanner.Mutation{ spanner.Insert("Languages", []string{"language", "mascot"}, - []interface{}{"Go", "Gopher"})}) + []interface{}{"Go", "Gopher"}), + }) if err != nil { t.Fatal(err) } diff --git a/examples/toxiproxy/redis.go b/examples/toxiproxy/redis.go index 26e3336deb..ead526773d 100644 --- a/examples/toxiproxy/redis.go +++ b/examples/toxiproxy/redis.go @@ -2,6 +2,7 @@ package toxiproxy import ( "context" + "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/wait" ) diff --git a/examples/toxiproxy/toxiproxy.go b/examples/toxiproxy/toxiproxy.go index ed335c14f3..e7903a9f99 100644 --- a/examples/toxiproxy/toxiproxy.go +++ b/examples/toxiproxy/toxiproxy.go @@ -4,9 +4,8 @@ import ( "context" "fmt" - "github.com/testcontainers/testcontainers-go/wait" - "github.com/testcontainers/testcontainers-go" + "github.com/testcontainers/testcontainers-go/wait" ) // toxiproxyContainer represents the toxiproxy container type used in the module diff --git a/examples/toxiproxy/toxiproxy_test.go b/examples/toxiproxy/toxiproxy_test.go index 5cee012924..f1ba128b59 100644 --- a/examples/toxiproxy/toxiproxy_test.go +++ b/examples/toxiproxy/toxiproxy_test.go @@ -3,12 +3,14 @@ package toxiproxy import ( "context" "fmt" + "testing" + "time" + toxiproxy "github.com/Shopify/toxiproxy/v2/client" "github.com/go-redis/redis/v8" "github.com/google/uuid" + "github.com/testcontainers/testcontainers-go" - "testing" - "time" ) func TestToxiproxy(t *testing.T) { diff --git a/file_test.go b/file_test.go index 8d7231d0a8..41c25d095f 100644 --- a/file_test.go +++ b/file_test.go @@ -76,7 +76,7 @@ func Test_TarDir(t *testing.T) { src = absSrc } - buff, err := tarDir(src, 0755) + buff, err := tarDir(src, 0o755) if err != nil { t.Fatal(err) } @@ -117,7 +117,7 @@ func Test_TarFile(t *testing.T) { t.Fatal(err) } - buff, err := tarFile(b, "Docker.file", 0755) + buff, err := tarFile(b, "Docker.file", 0o755) if err != nil { t.Fatal(err) } @@ -177,7 +177,7 @@ func untar(dst string, r io.Reader) error { // if its a dir and it doesn't exist create it case tar.TypeDir: if _, err := os.Stat(target); err != nil { - if err := os.MkdirAll(target, 0755); err != nil { + if err := os.MkdirAll(target, 0o755); err != nil { return err } } diff --git a/generic.go b/generic.go index 0b8d46f1f3..85b1542c7d 100644 --- a/generic.go +++ b/generic.go @@ -10,6 +10,7 @@ import ( "dario.cat/mergo" "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/network" + "github.com/testcontainers/testcontainers-go/wait" ) diff --git a/generic_test.go b/generic_test.go index f71fb59dae..77faa919c2 100644 --- a/generic_test.go +++ b/generic_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/testcontainers/testcontainers-go/wait" ) diff --git a/internal/config/config.go b/internal/config/config.go index 5460d6d67e..dd5731e0f7 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -10,8 +10,10 @@ import ( "github.com/magiconair/properties" ) -var tcConfig Config -var tcConfigOnce *sync.Once = new(sync.Once) +var ( + tcConfig Config + tcConfigOnce *sync.Once = new(sync.Once) +) // Config represents the configuration for Testcontainers // testcontainersConfig { diff --git a/internal/testcontainersdocker/client.go b/internal/testcontainersdocker/client.go index 27eb87a473..ca88b2af4b 100644 --- a/internal/testcontainersdocker/client.go +++ b/internal/testcontainersdocker/client.go @@ -5,6 +5,7 @@ import ( "path/filepath" "github.com/docker/docker/client" + "github.com/testcontainers/testcontainers-go/internal" "github.com/testcontainers/testcontainers-go/internal/config" "github.com/testcontainers/testcontainers-go/internal/testcontainerssession" diff --git a/internal/testcontainersdocker/docker_host.go b/internal/testcontainersdocker/docker_host.go index a9a6f328cb..6d96029a9c 100644 --- a/internal/testcontainersdocker/docker_host.go +++ b/internal/testcontainersdocker/docker_host.go @@ -10,6 +10,7 @@ import ( "sync" "github.com/docker/docker/client" + "github.com/testcontainers/testcontainers-go/internal/config" ) @@ -29,11 +30,15 @@ var ( ErrTestcontainersHostNotSetInProperties = errors.New("tc.host not set in ~/.testcontainers.properties") ) -var dockerHostCache string -var dockerHostOnce sync.Once +var ( + dockerHostCache string + dockerHostOnce sync.Once +) -var dockerSocketPathCache string -var dockerSocketPathOnce sync.Once +var ( + dockerSocketPathCache string + dockerSocketPathOnce sync.Once +) // deprecated // see https://github.com/testcontainers/testcontainers-java/blob/main/core/src/main/java/org/testcontainers/dockerclient/DockerClientConfigUtils.java#L46 diff --git a/internal/testcontainersdocker/docker_host_test.go b/internal/testcontainersdocker/docker_host_test.go index 0cc1063abc..45684e134b 100644 --- a/internal/testcontainersdocker/docker_host_test.go +++ b/internal/testcontainersdocker/docker_host_test.go @@ -10,6 +10,7 @@ import ( "github.com/docker/docker/client" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/testcontainers/testcontainers-go/internal/config" ) @@ -21,8 +22,10 @@ var ( originalDockerSocketPathWithSchema string ) -var originalDockerSocketOverride string -var tmpSchema string +var ( + originalDockerSocketOverride string + tmpSchema string +) func init() { originalDockerSocketPath = DockerSocketPath @@ -403,7 +406,7 @@ func TestInAContainer(t *testing.T) { } func createTmpDir(dir string) error { - err := os.MkdirAll(dir, 0755) + err := os.MkdirAll(dir, 0o755) if err != nil { return err } @@ -413,7 +416,7 @@ func createTmpDir(dir string) error { func createTmpDockerSocket(parent string) error { socketPath := filepath.Join(parent, "docker.sock") - err := os.MkdirAll(filepath.Dir(socketPath), 0755) + err := os.MkdirAll(filepath.Dir(socketPath), 0o755) if err != nil { return err } diff --git a/internal/testcontainersdocker/docker_rootless_test.go b/internal/testcontainersdocker/docker_rootless_test.go index 40d82d36a8..faa43b3000 100644 --- a/internal/testcontainersdocker/docker_rootless_test.go +++ b/internal/testcontainersdocker/docker_rootless_test.go @@ -11,9 +11,11 @@ import ( "github.com/stretchr/testify/require" ) -var originalBaseRunDir string -var originalXDGRuntimeDir string -var originalHomeDir string +var ( + originalBaseRunDir string + originalXDGRuntimeDir string + originalHomeDir string +) func init() { originalBaseRunDir = baseRunDir diff --git a/internal/testcontainersdocker/images.go b/internal/testcontainersdocker/images.go index 3dc10c2a45..b462007a44 100644 --- a/internal/testcontainersdocker/images.go +++ b/internal/testcontainersdocker/images.go @@ -60,7 +60,7 @@ func ExtractImagesFromDockerfile(dockerfile string, buildArgs map[string]*string // interpolate build args for k, v := range buildArgs { if v != nil { - parts[0] = strings.Replace(parts[0], "${"+k+"}", *v, -1) + parts[0] = strings.ReplaceAll(parts[0], "${"+k+"}", *v) } } images = append(images, parts[0]) diff --git a/internal/testcontainerssession/session.go b/internal/testcontainerssession/session.go index 21bd1f9800..ed98808a69 100644 --- a/internal/testcontainerssession/session.go +++ b/internal/testcontainerssession/session.go @@ -6,8 +6,10 @@ import ( "github.com/google/uuid" ) -var id uuid.UUID -var idOnce sync.Once +var ( + id uuid.UUID + idOnce sync.Once +) func ID() uuid.UUID { idOnce.Do(func() { diff --git a/lifecycle_test.go b/lifecycle_test.go index 6aed6befc2..87b55f1436 100644 --- a/lifecycle_test.go +++ b/lifecycle_test.go @@ -15,6 +15,7 @@ import ( "github.com/docker/go-connections/nat" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/testcontainers/testcontainers-go/internal/testcontainersdocker" "github.com/testcontainers/testcontainers-go/wait" ) @@ -559,7 +560,6 @@ func TestLifecycleHooks(t *testing.T) { lifecycleHooksIsHonouredFn(t, ctx, c, prints) }) } - } type inMemoryLogger struct { @@ -704,7 +704,6 @@ func TestPrintContainerLogsOnError(t *testing.T) { } assert.True(t, found, "container log line not found in the output of the logger: %s", line) } - } func lifecycleHooksIsHonouredFn(t *testing.T, ctx context.Context, container Container, prints []string) { diff --git a/logconsumer_test.go b/logconsumer_test.go index 08f2a6ba60..d1176944a8 100644 --- a/logconsumer_test.go +++ b/logconsumer_test.go @@ -13,6 +13,7 @@ import ( "github.com/docker/docker/client" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/testcontainers/testcontainers-go/internal/testcontainersdocker" "github.com/testcontainers/testcontainers-go/wait" ) diff --git a/logger.go b/logger.go index 3a2b30b1ce..917f7eaba5 100644 --- a/logger.go +++ b/logger.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/docker/docker/client" + "github.com/testcontainers/testcontainers-go/internal/testcontainersdocker" ) diff --git a/modulegen/dependabot.go b/modulegen/dependabot.go index a06990fc99..d0807f635e 100644 --- a/modulegen/dependabot.go +++ b/modulegen/dependabot.go @@ -134,5 +134,5 @@ func writeDependabotConfig(rootDir string, config *DependabotConfig) error { data = append([]byte(header), data...) - return os.WriteFile(file, data, 0777) + return os.WriteFile(file, data, 0o777) } diff --git a/modulegen/dependabot_test.go b/modulegen/dependabot_test.go index 5b512637b1..7dab43fcb6 100644 --- a/modulegen/dependabot_test.go +++ b/modulegen/dependabot_test.go @@ -16,10 +16,10 @@ func TestGetDependabotConfigFile(t *testing.T) { rootDir := filepath.Join(tmp, "testcontainers-go") githubDir := filepath.Join(rootDir, ".github") cfgFile := filepath.Join(githubDir, "dependabot.yml") - err := os.MkdirAll(githubDir, 0777) + err := os.MkdirAll(githubDir, 0o777) require.NoError(t, err) - err = os.WriteFile(cfgFile, []byte{}, 0777) + err = os.WriteFile(cfgFile, []byte{}, 0o777) require.NoError(t, err) file := getDependabotConfigFile(rootDir) @@ -59,7 +59,7 @@ func TestReadDependabotConfig(t *testing.T) { rootDir := filepath.Join(tmp, "testcontainers-go") githubDir := filepath.Join(rootDir, ".github") - err := os.MkdirAll(githubDir, 0777) + err := os.MkdirAll(githubDir, 0o777) require.NoError(t, err) err = copyInitialDependabotConfig(t, rootDir) diff --git a/modulegen/main.go b/modulegen/main.go index aa31d18297..99acaf5925 100644 --- a/modulegen/main.go +++ b/modulegen/main.go @@ -17,10 +17,12 @@ import ( "golang.org/x/text/language" ) -var asModuleVar bool -var nameVar string -var nameTitleVar string -var imageVar string +var ( + asModuleVar bool + nameVar string + nameTitleVar string + imageVar string +) var templates = []string{ "ci.yml", "docs_example.md", "example_test.go", "example.go", "go.mod", "Makefile", @@ -188,7 +190,7 @@ func generate(example Example, rootDir string) error { exampleLower := example.Lower() // create the example dir - err := os.MkdirAll(filepath.Join(outputDir, exampleLower), 0700) + err := os.MkdirAll(filepath.Join(outputDir, exampleLower), 0o700) if err != nil { return err } @@ -242,7 +244,7 @@ func generate(example Example, rootDir string) error { exampleFilePath = filepath.Join(outputDir, exampleLower, strings.ReplaceAll(tmpl, "example", exampleLower)) } - err = os.MkdirAll(filepath.Dir(exampleFilePath), 0777) + err = os.MkdirAll(filepath.Dir(exampleFilePath), 0o777) if err != nil { return err } diff --git a/modulegen/main_test.go b/modulegen/main_test.go index 43d3300bae..c023d60656 100644 --- a/modulegen/main_test.go +++ b/modulegen/main_test.go @@ -154,11 +154,11 @@ func TestGenerateWrongExampleName(t *testing.T) { examplesDocTmp := filepath.Join(rootTmp, "docs", "examples") githubWorkflowsTmp := filepath.Join(rootTmp, ".github", "workflows") - err := os.MkdirAll(examplesTmp, 0777) + err := os.MkdirAll(examplesTmp, 0o777) assert.Nil(t, err) - err = os.MkdirAll(examplesDocTmp, 0777) + err = os.MkdirAll(examplesDocTmp, 0o777) assert.Nil(t, err) - err = os.MkdirAll(githubWorkflowsTmp, 0777) + err = os.MkdirAll(githubWorkflowsTmp, 0o777) assert.Nil(t, err) err = copyInitialMkdocsConfig(t, rootTmp) @@ -197,11 +197,11 @@ func TestGenerateWrongExampleTitle(t *testing.T) { examplesDocTmp := filepath.Join(rootTmp, "docs", "examples") githubWorkflowsTmp := filepath.Join(rootTmp, ".github", "workflows") - err := os.MkdirAll(examplesTmp, 0777) + err := os.MkdirAll(examplesTmp, 0o777) assert.Nil(t, err) - err = os.MkdirAll(examplesDocTmp, 0777) + err = os.MkdirAll(examplesDocTmp, 0o777) assert.Nil(t, err) - err = os.MkdirAll(githubWorkflowsTmp, 0777) + err = os.MkdirAll(githubWorkflowsTmp, 0o777) assert.Nil(t, err) err = copyInitialMkdocsConfig(t, rootTmp) @@ -241,11 +241,11 @@ func TestGenerate(t *testing.T) { examplesDocTmp := filepath.Join(rootTmp, "docs", "examples") githubWorkflowsTmp := filepath.Join(rootTmp, ".github", "workflows") - err := os.MkdirAll(examplesTmp, 0777) + err := os.MkdirAll(examplesTmp, 0o777) assert.Nil(t, err) - err = os.MkdirAll(examplesDocTmp, 0777) + err = os.MkdirAll(examplesDocTmp, 0o777) assert.Nil(t, err) - err = os.MkdirAll(githubWorkflowsTmp, 0777) + err = os.MkdirAll(githubWorkflowsTmp, 0o777) assert.Nil(t, err) err = copyInitialMkdocsConfig(t, rootTmp) @@ -312,11 +312,11 @@ func TestGenerateModule(t *testing.T) { modulesDocTmp := filepath.Join(rootTmp, "docs", "modules") githubWorkflowsTmp := filepath.Join(rootTmp, ".github", "workflows") - err := os.MkdirAll(modulesTmp, 0777) + err := os.MkdirAll(modulesTmp, 0o777) assert.Nil(t, err) - err = os.MkdirAll(modulesDocTmp, 0777) + err = os.MkdirAll(modulesDocTmp, 0o777) assert.Nil(t, err) - err = os.MkdirAll(githubWorkflowsTmp, 0777) + err = os.MkdirAll(githubWorkflowsTmp, 0o777) assert.Nil(t, err) err = copyInitialMkdocsConfig(t, rootTmp) diff --git a/modulegen/mkdocs.go b/modulegen/mkdocs.go index 815483524c..ed41f3dfa8 100644 --- a/modulegen/mkdocs.go +++ b/modulegen/mkdocs.go @@ -63,10 +63,6 @@ func getExamplesDocs() ([]os.DirEntry, error) { return os.ReadDir(dir) } -func getModules() ([]os.DirEntry, error) { - return getModulesOrExamples(true) -} - func getRootDir() (string, error) { current, err := os.Getwd() if err != nil { @@ -102,5 +98,5 @@ func writeMkdocsConfig(rootDir string, config *MkDocsConfig) error { file := getMkdocsConfigFile(rootDir) - return os.WriteFile(file, data, 0777) + return os.WriteFile(file, data, 0o777) } diff --git a/modulegen/mkdocs_test.go b/modulegen/mkdocs_test.go index 40d0473ba6..d996ecac7c 100644 --- a/modulegen/mkdocs_test.go +++ b/modulegen/mkdocs_test.go @@ -15,10 +15,10 @@ func TestGetMkDocsConfigFile(t *testing.T) { rootDir := filepath.Join(tmp, "testcontainers-go") cfgFile := filepath.Join(rootDir, "mkdocs.yml") - err := os.MkdirAll(rootDir, 0777) + err := os.MkdirAll(rootDir, 0o777) require.NoError(t, err) - err = os.WriteFile(cfgFile, []byte{}, 0777) + err = os.WriteFile(cfgFile, []byte{}, 0o777) require.NoError(t, err) file := getMkdocsConfigFile(rootDir) @@ -31,7 +31,7 @@ func TestReadMkDocsConfig(t *testing.T) { tmp := t.TempDir() rootDir := filepath.Join(tmp, "testcontainers-go") - err := os.MkdirAll(rootDir, 0777) + err := os.MkdirAll(rootDir, 0o777) require.NoError(t, err) err = copyInitialMkdocsConfig(t, rootDir) diff --git a/modules/artemis/artemis.go b/modules/artemis/artemis.go index 64bc588081..a3c26702ad 100644 --- a/modules/artemis/artemis.go +++ b/modules/artemis/artemis.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/docker/go-connections/nat" + "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/wait" ) diff --git a/modules/artemis/artemis_test.go b/modules/artemis/artemis_test.go index b68fac3f21..4cf70db556 100644 --- a/modules/artemis/artemis_test.go +++ b/modules/artemis/artemis_test.go @@ -10,6 +10,7 @@ import ( "github.com/go-stomp/stomp/v3" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/artemis" ) diff --git a/modules/artemis/example_test.go b/modules/artemis/example_test.go index b626056731..37e05af537 100644 --- a/modules/artemis/example_test.go +++ b/modules/artemis/example_test.go @@ -4,6 +4,7 @@ import ( "context" "github.com/go-stomp/stomp/v3" + "github.com/testcontainers/testcontainers-go/modules/artemis" ) diff --git a/modules/clickhouse/clickhouse.go b/modules/clickhouse/clickhouse.go index 9f59cf7280..3d6b111b56 100644 --- a/modules/clickhouse/clickhouse.go +++ b/modules/clickhouse/clickhouse.go @@ -7,17 +7,22 @@ import ( "strings" "github.com/docker/go-connections/nat" + "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/wait" ) -const defaultUser = "default" -const defaultDatabaseName = "clickhouse" +const ( + defaultUser = "default" + defaultDatabaseName = "clickhouse" +) const defaultImage = "clickhouse/clickhouse-server:23.3.8.21-alpine" -const httpPort = nat.Port("8123/tcp") -const nativePort = nat.Port("9000/tcp") +const ( + httpPort = nat.Port("8123/tcp") + nativePort = nat.Port("9000/tcp") +) // ClickHouseContainer represents the ClickHouse container type used in the module type ClickHouseContainer struct { @@ -71,7 +76,7 @@ func WithInitScripts(scripts ...string) testcontainers.CustomizeRequestOption { cf := testcontainers.ContainerFile{ HostFilePath: script, ContainerFilePath: "/docker-entrypoint-initdb.d/" + filepath.Base(script), - FileMode: 0755, + FileMode: 0o755, } initScripts = append(initScripts, cf) } @@ -87,7 +92,7 @@ func WithConfigFile(configFile string) testcontainers.CustomizeRequestOption { cf := testcontainers.ContainerFile{ HostFilePath: configFile, ContainerFilePath: "/etc/clickhouse-server/config.d/config.xml", - FileMode: 0755, + FileMode: 0o755, } req.Files = append(req.Files, cf) } @@ -101,7 +106,7 @@ func WithYamlConfigFile(configFile string) testcontainers.CustomizeRequestOption cf := testcontainers.ContainerFile{ HostFilePath: configFile, ContainerFilePath: "/etc/clickhouse-server/config.d/config.yaml", - FileMode: 0755, + FileMode: 0o755, } req.Files = append(req.Files, cf) } diff --git a/modules/clickhouse/clickhouse_test.go b/modules/clickhouse/clickhouse_test.go index f299219b09..5670719e0c 100644 --- a/modules/clickhouse/clickhouse_test.go +++ b/modules/clickhouse/clickhouse_test.go @@ -8,12 +8,15 @@ import ( ch "github.com/ClickHouse/clickhouse-go/v2" "github.com/ClickHouse/clickhouse-go/v2/lib/driver" "github.com/stretchr/testify/assert" + "github.com/testcontainers/testcontainers-go" ) -const dbname = "testdb" -const user = "clickhouse" -const password = "password" +const ( + dbname = "testdb" + user = "clickhouse" + password = "password" +) type Test struct { Id uint64 diff --git a/modules/compose/compose.go b/modules/compose/compose.go index 5ee34a6dd6..6c45d5119b 100644 --- a/modules/compose/compose.go +++ b/modules/compose/compose.go @@ -24,8 +24,10 @@ const ( envComposeFile = "COMPOSE_FILE" ) -var composeLogOnce sync.Once -var ErrNoStackConfigured = errors.New("no stack files configured") +var ( + composeLogOnce sync.Once + ErrNoStackConfigured = errors.New("no stack files configured") +) type composeStackOptions struct { Identifier string diff --git a/modules/compose/compose_api_test.go b/modules/compose/compose_api_test.go index f9c875bc6e..152d348ea7 100644 --- a/modules/compose/compose_api_test.go +++ b/modules/compose/compose_api_test.go @@ -485,7 +485,7 @@ func TestDockerComposeApiWithWaitForShortLifespanService(t *testing.T) { t.Cleanup(cancel) err = compose. - //Assumption: tzatziki service wait logic will run before falafel, so that falafel service will exit before + // Assumption: tzatziki service wait logic will run before falafel, so that falafel service will exit before WaitForService("tzatziki", wait.ForExit().WithExitTimeout(10*time.Second)). WaitForService("falafel", wait.ForExit().WithExitTimeout(10*time.Second)). Up(ctx) diff --git a/modules/compose/compose_local.go b/modules/compose/compose_local.go index 3b58989ec6..ba4fb8beef 100644 --- a/modules/compose/compose_local.go +++ b/modules/compose/compose_local.go @@ -30,15 +30,13 @@ type ComposeVersion interface { Format(parts ...string) string } -type composeVersion1 struct { -} +type composeVersion1 struct{} func (c composeVersion1) Format(parts ...string) string { return strings.Join(parts, "_") } -type composeVersion2 struct { -} +type composeVersion2 struct{} func (c composeVersion2) Format(parts ...string) string { return strings.Join(parts, "-") @@ -279,8 +277,8 @@ type ExecError struct { // execute executes a program with arguments and environment variables inside a specific directory func execute( - dirContext string, environment map[string]string, binary string, args []string) ExecError { - + dirContext string, environment map[string]string, binary string, args []string, +) ExecError { var errStdout, errStderr error cmd := exec.Command(binary, args...) diff --git a/modules/compose/compose_test.go b/modules/compose/compose_test.go index caf755f7e1..548e27fd36 100644 --- a/modules/compose/compose_test.go +++ b/modules/compose/compose_test.go @@ -19,8 +19,10 @@ import ( "github.com/testcontainers/testcontainers-go/wait" ) -var complexComposeTestFile string = filepath.Join("testdata", "docker-compose-complex.yml") -var simpleComposeTestFile string = filepath.Join("testdata", "docker-compose-simple.yml") +var ( + complexComposeTestFile string = filepath.Join("testdata", "docker-compose-complex.yml") + simpleComposeTestFile string = filepath.Join("testdata", "docker-compose-simple.yml") +) func ExampleNewLocalDockerCompose() { path := "/path/to/docker-compose.yml" @@ -116,6 +118,7 @@ func TestLocalDockerCompose(t *testing.T) { Invoke() checkIfError(t, err) } + func TestDockerComposeStrategyForInvalidService(t *testing.T) { path := simpleComposeTestFile @@ -202,7 +205,7 @@ func TestDockerComposeWithWaitForShortLifespanService(t *testing.T) { err := compose. WithCommand([]string{"up", "-d"}). - //Assumption: tzatziki service wait logic will run before falafel, so that falafel service will exit before + // Assumption: tzatziki service wait logic will run before falafel, so that falafel service will exit before WaitForService(compose.Format("tzatziki", "1"), wait.ForExit().WithExitTimeout(10*time.Second)). WaitForService(compose.Format("falafel", "1"), wait.ForExit().WithExitTimeout(10*time.Second)). Invoke() diff --git a/modules/compose/testdata/echoserver.go b/modules/compose/testdata/echoserver.go index 1b331e8890..090e7fcf58 100644 --- a/modules/compose/testdata/echoserver.go +++ b/modules/compose/testdata/echoserver.go @@ -10,7 +10,6 @@ import ( func envHandler() http.HandlerFunc { return func(rw http.ResponseWriter, req *http.Request) { - _, _ = rw.Write([]byte(os.Getenv("FOO"))) rw.WriteHeader(http.StatusAccepted) diff --git a/modules/couchbase/couchbase.go b/modules/couchbase/couchbase.go index b452a92ef5..7e0e87e2eb 100644 --- a/modules/couchbase/couchbase.go +++ b/modules/couchbase/couchbase.go @@ -12,9 +12,10 @@ import ( "github.com/cenkalti/backoff/v4" "github.com/docker/go-connections/nat" + "github.com/tidwall/gjson" + "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/wait" - "github.com/tidwall/gjson" ) // containerPorts { diff --git a/modules/couchbase/couchbase_test.go b/modules/couchbase/couchbase_test.go index 4e721390c9..605fa00d1e 100644 --- a/modules/couchbase/couchbase_test.go +++ b/modules/couchbase/couchbase_test.go @@ -6,6 +6,7 @@ import ( "time" "github.com/couchbase/gocb/v2" + "github.com/testcontainers/testcontainers-go" tccouchbase "github.com/testcontainers/testcontainers-go/modules/couchbase" ) @@ -108,7 +109,6 @@ func TestWithCredentials(t *testing.T) { testcontainers.WithImage(communityEdition), tccouchbase.WithAdminCredentials("testcontainers", "testcontainers.IS.cool!"), tccouchbase.WithBuckets(tccouchbase.NewBucket(bucketName))) - if err != nil { t.Errorf("Expected error to be [%v] , got nil", err) } @@ -179,7 +179,7 @@ func testBucketUsage(t *testing.T, bucket *gocb.Bucket) { var resultData map[string]string err = result.Content(&resultData) if err != nil { - t.Fatalf("could not asign content: %s", err) + t.Fatalf("could not assign content: %s", err) } if resultData["key"] != "value" { diff --git a/modules/k3s/k3s.go b/modules/k3s/k3s.go index 30f7c348d5..fa8c43bb0a 100644 --- a/modules/k3s/k3s.go +++ b/modules/k3s/k3s.go @@ -8,9 +8,10 @@ import ( "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/mount" "github.com/docker/go-connections/nat" + "gopkg.in/yaml.v3" + "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/wait" - "gopkg.in/yaml.v3" ) var ( @@ -47,7 +48,6 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize "/var/run": "", } hc.Mounts = []mount.Mount{} - }, Cmd: []string{ "server", @@ -134,7 +134,6 @@ func (c *K3sContainer) GetKubeConfig(ctx context.Context) ([]byte, error) { } func kubeConfigWithServerUrl(kubeConfigYaml, server string) ([]byte, error) { - kubeConfig, err := unmarshal([]byte(kubeConfigYaml)) if err != nil { return nil, fmt.Errorf("failed to unmarshal kubeconfig: %w", err) diff --git a/modules/k3s/k3s_test.go b/modules/k3s/k3s_test.go index 71f2ec5827..e55f1e0aad 100644 --- a/modules/k3s/k3s_test.go +++ b/modules/k3s/k3s_test.go @@ -5,11 +5,12 @@ import ( "testing" "github.com/stretchr/testify/assert" - "github.com/testcontainers/testcontainers-go" - "github.com/testcontainers/testcontainers-go/wait" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/clientcmd" + + "github.com/testcontainers/testcontainers-go" + "github.com/testcontainers/testcontainers-go/wait" ) func TestK3s(t *testing.T) { diff --git a/modules/localstack/localstack.go b/modules/localstack/localstack.go index 8046b8e40b..f5aca5b031 100644 --- a/modules/localstack/localstack.go +++ b/modules/localstack/localstack.go @@ -6,21 +6,19 @@ import ( "strings" "time" + "golang.org/x/mod/semver" + "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/internal/testcontainersdocker" "github.com/testcontainers/testcontainers-go/wait" - "golang.org/x/mod/semver" ) -const defaultPort = 4566 -const defaultRegion = "us-east-1" -const defaultVersion = "1.4.0" -const hostnameExternalEnvVar = "HOSTNAME_EXTERNAL" -const localstackHostEnvVar = "LOCALSTACK_HOST" - -const defaultAccessKeyID = "accesskey" -const defaultSecretAccessKey = "secretkey" -const defaultToken = "token" +const ( + defaultPort = 4566 + defaultVersion = "1.4.0" + hostnameExternalEnvVar = "HOSTNAME_EXTERNAL" + localstackHostEnvVar = "LOCALSTACK_HOST" +) func isLegacyMode(image string) bool { parts := strings.Split(image, ":") diff --git a/modules/localstack/localstack_legacy_mode_test.go b/modules/localstack/localstack_legacy_mode_test.go index 4356c8f2c9..40a8271b43 100644 --- a/modules/localstack/localstack_legacy_mode_test.go +++ b/modules/localstack/localstack_legacy_mode_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/wait" ) diff --git a/modules/localstack/localstack_test.go b/modules/localstack/localstack_test.go index de99d150b4..857808a2ee 100644 --- a/modules/localstack/localstack_test.go +++ b/modules/localstack/localstack_test.go @@ -8,11 +8,11 @@ import ( "testing" "time" - "github.com/testcontainers/testcontainers-go/wait" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/testcontainers/testcontainers-go" + "github.com/testcontainers/testcontainers-go/wait" ) func generateContainerRequest() *LocalStackContainerRequest { @@ -246,8 +246,10 @@ func TestStartV2WithNetwork(t *testing.T) { "AWS_SECRET_ACCESS_KEY": "secretkey", "AWS_REGION": "eu-west-1", }, - WaitingFor: wait.ForExec([]string{"/usr/local/bin/aws", "sqs", "create-queue", "--queue-name", "baz", "--region", "eu-west-1", - "--endpoint-url", "http://localstack:4566", "--no-verify-ssl"}). + WaitingFor: wait.ForExec([]string{ + "/usr/local/bin/aws", "sqs", "create-queue", "--queue-name", "baz", "--region", "eu-west-1", + "--endpoint-url", "http://localstack:4566", "--no-verify-ssl", + }). WithStartupTimeout(time.Second * 10). WithExitCodeMatcher(func(exitCode int) bool { return exitCode == 0 diff --git a/modules/localstack/v1/s3_test.go b/modules/localstack/v1/s3_test.go index 3dbf2297a8..5d60747258 100644 --- a/modules/localstack/v1/s3_test.go +++ b/modules/localstack/v1/s3_test.go @@ -14,6 +14,7 @@ import ( "github.com/docker/go-connections/nat" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/localstack" ) diff --git a/modules/localstack/v2/s3_test.go b/modules/localstack/v2/s3_test.go index 66286f671f..7de829d9f8 100644 --- a/modules/localstack/v2/s3_test.go +++ b/modules/localstack/v2/s3_test.go @@ -13,6 +13,7 @@ import ( "github.com/docker/go-connections/nat" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/localstack" ) diff --git a/modules/mysql/mysql.go b/modules/mysql/mysql.go index 8390e9b272..ec98b481be 100644 --- a/modules/mysql/mysql.go +++ b/modules/mysql/mysql.go @@ -10,10 +10,12 @@ import ( "github.com/testcontainers/testcontainers-go/wait" ) -const rootUser = "root" -const defaultUser = "test" -const defaultPassword = "test" -const defaultDatabaseName = "test" +const ( + rootUser = "root" + defaultUser = "test" + defaultPassword = "test" + defaultDatabaseName = "test" +) // defaultImage { const defaultImage = "mysql:8" @@ -134,7 +136,7 @@ func WithConfigFile(configFile string) testcontainers.CustomizeRequestOption { cf := testcontainers.ContainerFile{ HostFilePath: configFile, ContainerFilePath: "/etc/mysql/conf.d/my.cnf", - FileMode: 0755, + FileMode: 0o755, } req.Files = append(req.Files, cf) } @@ -147,7 +149,7 @@ func WithScripts(scripts ...string) testcontainers.CustomizeRequestOption { cf := testcontainers.ContainerFile{ HostFilePath: script, ContainerFilePath: "/docker-entrypoint-initdb.d/" + filepath.Base(script), - FileMode: 0755, + FileMode: 0o755, } initScripts = append(initScripts, cf) } diff --git a/modules/mysql/mysql_test.go b/modules/mysql/mysql_test.go index fe578b0f00..41ac2f828b 100644 --- a/modules/mysql/mysql_test.go +++ b/modules/mysql/mysql_test.go @@ -8,6 +8,7 @@ import ( // Import mysql into the scope of this package (required) _ "github.com/go-sql-driver/mysql" + "github.com/testcontainers/testcontainers-go" ) @@ -145,7 +146,7 @@ func TestMySQLWithConfigFile(t *testing.T) { } defer stmt.Close() row := stmt.QueryRow() - var innodbFileFormat = "" + innodbFileFormat := "" err = row.Scan(&innodbFileFormat) if err != nil { t.Errorf("error fetching innodb_file_format value") diff --git a/modules/neo4j/neo4j.go b/modules/neo4j/neo4j.go index aa7a33c782..62dd7e3763 100644 --- a/modules/neo4j/neo4j.go +++ b/modules/neo4j/neo4j.go @@ -6,6 +6,7 @@ import ( "net/http" "github.com/docker/go-connections/nat" + "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/wait" ) diff --git a/modules/neo4j/neo4j_test.go b/modules/neo4j/neo4j_test.go index 9429511d88..35294a246c 100644 --- a/modules/neo4j/neo4j_test.go +++ b/modules/neo4j/neo4j_test.go @@ -8,6 +8,7 @@ import ( "testing" neo "github.com/neo4j/neo4j-go-driver/v5/neo4j" + "github.com/testcontainers/testcontainers-go/modules/neo4j" ) @@ -30,7 +31,6 @@ func TestNeo4j(outer *testing.T) { driver := createDriver(t, ctx, container) err := driver.VerifyConnectivity(ctx) - if err != nil { t.Fatalf("should have successfully connected to server but did not: %s", err) } @@ -42,7 +42,6 @@ func TestNeo4j(outer *testing.T) { result, err := neo.ExecuteQuery(ctx, driver, "RETURN apoc.number.arabicToRoman(1986) AS output", nil, neo.EagerResultTransformer) - if err != nil { t.Fatalf("expected APOC query to successfully run but did not: %s", err) } @@ -175,7 +174,6 @@ func createDriver(t *testing.T, ctx context.Context, container *neo4j.Neo4jConta func getContainerEnv(t *testing.T, ctx context.Context, container *neo4j.Neo4jContainer) string { exec, reader, err := container.Exec(ctx, []string{"env"}) - if err != nil { t.Fatalf("expected env to successfully run but did not: %s", err) } diff --git a/modules/postgres/postgres.go b/modules/postgres/postgres.go index 95e598b228..b50f58737a 100644 --- a/modules/postgres/postgres.go +++ b/modules/postgres/postgres.go @@ -10,9 +10,11 @@ import ( "github.com/testcontainers/testcontainers-go" ) -const defaultUser = "postgres" -const defaultPassword = "postgres" -const defaultPostgresImage = "docker.io/postgres:11-alpine" +const ( + defaultUser = "postgres" + defaultPassword = "postgres" + defaultPostgresImage = "docker.io/postgres:11-alpine" +) // PostgresContainer represents the postgres container type used in the module type PostgresContainer struct { @@ -50,7 +52,7 @@ func WithConfigFile(cfg string) testcontainers.CustomizeRequestOption { cfgFile := testcontainers.ContainerFile{ HostFilePath: cfg, ContainerFilePath: "/etc/postgresql.conf", - FileMode: 0755, + FileMode: 0o755, } req.Files = append(req.Files, cfgFile) @@ -75,7 +77,7 @@ func WithInitScripts(scripts ...string) testcontainers.CustomizeRequestOption { cf := testcontainers.ContainerFile{ HostFilePath: script, ContainerFilePath: "/docker-entrypoint-initdb.d/" + filepath.Base(script), - FileMode: 0755, + FileMode: 0o755, } initScripts = append(initScripts, cf) } diff --git a/modules/postgres/postgres_test.go b/modules/postgres/postgres_test.go index bf2c5e13c3..f375268940 100644 --- a/modules/postgres/postgres_test.go +++ b/modules/postgres/postgres_test.go @@ -10,16 +10,18 @@ import ( "github.com/docker/go-connections/nat" _ "github.com/lib/pq" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/wait" ) -const dbname = "test-db" -const user = "postgres" -const password = "password" +const ( + dbname = "test-db" + user = "postgres" + password = "password" +) func TestPostgres(t *testing.T) { ctx := context.Background() @@ -103,7 +105,7 @@ func TestPostgres(t *testing.T) { func TestContainerWithWaitForSQL(t *testing.T) { ctx := context.Background() - var port = "5432/tcp" + port := "5432/tcp" dbURL := func(host string, port nat.Port) string { return fmt.Sprintf("postgres://postgres:password@%s:%s/%s?sslmode=disable", host, port.Port(), dbname) } diff --git a/modules/pulsar/pulsar.go b/modules/pulsar/pulsar.go index 47fc2da0da..eeb8f907b0 100644 --- a/modules/pulsar/pulsar.go +++ b/modules/pulsar/pulsar.go @@ -7,16 +7,19 @@ import ( "strings" "github.com/docker/go-connections/nat" + "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/wait" ) -const defaultPulsarImage = "docker.io/apachepulsar/pulsar:2.10.2" -const defaultPulsarPort = "6650/tcp" -const defaultPulsarAdminPort = "8080/tcp" -const defaultPulsarCmd = "/pulsar/bin/apply-config-from-env.py /pulsar/conf/standalone.conf && bin/pulsar standalone" -const detaultPulsarCmdWithoutFunctionsWorker = "--no-functions-worker -nss" -const transactionTopicEndpoint = "/admin/v2/persistent/pulsar/system/transaction_coordinator_assign/partitions" +const ( + defaultPulsarImage = "docker.io/apachepulsar/pulsar:2.10.2" + defaultPulsarPort = "6650/tcp" + defaultPulsarAdminPort = "8080/tcp" + defaultPulsarCmd = "/pulsar/bin/apply-config-from-env.py /pulsar/conf/standalone.conf && bin/pulsar standalone" + detaultPulsarCmdWithoutFunctionsWorker = "--no-functions-worker -nss" + transactionTopicEndpoint = "/admin/v2/persistent/pulsar/system/transaction_coordinator_assign/partitions" +) var defaultWaitStrategies = wait.ForAll( wait.ForHTTP("/admin/v2/clusters").WithPort(defaultPulsarAdminPort).WithResponseMatcher(func(r io.Reader) bool { @@ -121,8 +124,9 @@ func WithTransactions() testcontainers.CustomizeRequestOption { // - image: docker.io/apachepulsar/pulsar:2.10.2 // - exposed ports: 6650/tcp, 8080/tcp // - waiting strategy: wait for all the following strategies: -// - the Pulsar admin API ("/admin/v2/clusters") to be ready on port 8080/tcp and return the response `["standalone"]` -// - the log message "Successfully updated the policies on namespace public/default" +// - the Pulsar admin API ("/admin/v2/clusters") to be ready on port 8080/tcp and return the response `["standalone"]` +// - the log message "Successfully updated the policies on namespace public/default" +// // - command: "/bin/bash -c /pulsar/bin/apply-config-from-env.py /pulsar/conf/standalone.conf && bin/pulsar standalone --no-functions-worker -nss" func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*Container, error) { req := testcontainers.ContainerRequest{ diff --git a/modules/pulsar/pulsar_test.go b/modules/pulsar/pulsar_test.go index f994f3e33c..208cd094b2 100644 --- a/modules/pulsar/pulsar_test.go +++ b/modules/pulsar/pulsar_test.go @@ -15,6 +15,7 @@ import ( "github.com/docker/docker/api/types/network" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/testcontainers/testcontainers-go" testcontainerspulsar "github.com/testcontainers/testcontainers-go/modules/pulsar" ) diff --git a/modules/redis/redis.go b/modules/redis/redis.go index c4f20852a1..a828816d73 100644 --- a/modules/redis/redis.go +++ b/modules/redis/redis.go @@ -80,7 +80,7 @@ func WithConfigFile(configFile string) testcontainers.CustomizeRequestOption { cf := testcontainers.ContainerFile{ HostFilePath: configFile, ContainerFilePath: defaultConfigFile, - FileMode: 0755, + FileMode: 0o755, } req.Files = append(req.Files, cf) diff --git a/modules/redis/redis_test.go b/modules/redis/redis_test.go index b9cffc032e..fd29c81432 100644 --- a/modules/redis/redis_test.go +++ b/modules/redis/redis_test.go @@ -10,6 +10,7 @@ import ( "github.com/go-redis/redis/v8" "github.com/google/uuid" "github.com/stretchr/testify/require" + "github.com/testcontainers/testcontainers-go" ) @@ -130,7 +131,7 @@ func assertSetsGets(t *testing.T, ctx context.Context, redisContainer *RedisCont // } // You will likely want to wrap your Redis package of choice in an - // interface to aid in unit testing and limit lock-in throughtout your + // interface to aid in unit testing and limit lock-in throughout your // codebase but that's out of scope for this example options, err := redis.ParseURL(uri) require.NoError(t, err) diff --git a/modules/redpanda/redpanda.go b/modules/redpanda/redpanda.go index cc373b42cd..944a6d112a 100644 --- a/modules/redpanda/redpanda.go +++ b/modules/redpanda/redpanda.go @@ -254,7 +254,7 @@ func createBootstrapConfigFile(settings options) (*os.File, error) { return bootstrapTmpFile, nil } -// renderNodeConfig renders the redpanda.yaml node config and retuns it as +// renderNodeConfig renders the redpanda.yaml node config and returns it as // byte array. func renderNodeConfig(settings options, hostIP string, advertisedKafkaPort int) ([]byte, error) { tplParams := redpandaConfigTplParams{ diff --git a/modules/vault/vault.go b/modules/vault/vault.go index d5e655f9bf..ca5ab4bb13 100644 --- a/modules/vault/vault.go +++ b/modules/vault/vault.go @@ -5,10 +5,10 @@ import ( "fmt" "strings" - "github.com/testcontainers/testcontainers-go/wait" - "github.com/docker/docker/api/types/container" + "github.com/testcontainers/testcontainers-go" + "github.com/testcontainers/testcontainers-go/wait" ) const ( diff --git a/modules/vault/vault_test.go b/modules/vault/vault_test.go index 008f5f5ff6..c139c91611 100644 --- a/modules/vault/vault_test.go +++ b/modules/vault/vault_test.go @@ -12,9 +12,10 @@ import ( vaultClient "github.com/hashicorp/vault-client-go" "github.com/hashicorp/vault-client-go/schema" "github.com/stretchr/testify/assert" + "github.com/tidwall/gjson" + "github.com/testcontainers/testcontainers-go" testcontainervault "github.com/testcontainers/testcontainers-go/modules/vault" - "github.com/tidwall/gjson" ) const ( diff --git a/mounts.go b/mounts.go index c4b6fc916a..85fcfa8b63 100644 --- a/mounts.go +++ b/mounts.go @@ -63,8 +63,7 @@ func (GenericVolumeMountSource) Type() MountType { // GenericTmpfsMountSource implements ContainerMountSource and represents a TmpFS mount // Optionally mount.TmpfsOptions might be added for advanced scenarios -type GenericTmpfsMountSource struct { -} +type GenericTmpfsMountSource struct{} func (s GenericTmpfsMountSource) Source() string { return "" diff --git a/mounts_test.go b/mounts_test.go index c445e24d64..16a6458ed4 100644 --- a/mounts_test.go +++ b/mounts_test.go @@ -6,6 +6,7 @@ import ( "github.com/docker/docker/api/types/mount" "github.com/stretchr/testify/assert" + "github.com/testcontainers/testcontainers-go/internal/testcontainersdocker" ) diff --git a/network_test.go b/network_test.go index 453c854114..52b44c1e96 100644 --- a/network_test.go +++ b/network_test.go @@ -9,6 +9,7 @@ import ( "github.com/docker/docker/api/types/network" "github.com/stretchr/testify/assert" + "github.com/testcontainers/testcontainers-go/wait" ) @@ -68,7 +69,6 @@ func Test_NetworkWithIPAM(t *testing.T) { IPAM: &ipamConfig, }, }) - if err != nil { t.Fatal("cannot create network: ", err) } @@ -129,7 +129,6 @@ func Test_MultipleContainersInTheNewNetwork(t *testing.T) { net, err := GenericNetwork(ctx, GenericNetworkRequest{ NetworkRequest: networkRequest, }) - if err != nil { t.Fatal("cannot create network") } diff --git a/parallel.go b/parallel.go index 297ab9d6dc..34740eeaf4 100644 --- a/parallel.go +++ b/parallel.go @@ -36,8 +36,8 @@ func parallelContainersRunner( requests <-chan GenericContainerRequest, errors chan<- ParallelContainersRequestError, containers chan<- Container, - wg *sync.WaitGroup) { - + wg *sync.WaitGroup, +) { for req := range requests { c, err := GenericContainer(ctx, req) if err != nil { @@ -101,7 +101,6 @@ func ParallelContainers(ctx context.Context, reqs ParallelContainerRequest, opt break } } - }() for _, req := range reqs { diff --git a/parallel_test.go b/parallel_test.go index 3a23c47e57..7195c9f4f3 100644 --- a/parallel_test.go +++ b/parallel_test.go @@ -7,6 +7,7 @@ import ( "time" "github.com/stretchr/testify/require" + "github.com/testcontainers/testcontainers-go/wait" ) @@ -22,7 +23,6 @@ func TestParallelContainers(t *testing.T) { reqs: ParallelContainerRequest{ { ContainerRequest: ContainerRequest{ - Image: "nginx", ExposedPorts: []string{ "10080/tcp", @@ -32,7 +32,6 @@ func TestParallelContainers(t *testing.T) { }, { ContainerRequest: ContainerRequest{ - Image: "bad bad bad", ExposedPorts: []string{ "10081/tcp", @@ -49,7 +48,6 @@ func TestParallelContainers(t *testing.T) { reqs: ParallelContainerRequest{ { ContainerRequest: ContainerRequest{ - Image: "bad bad bad", ExposedPorts: []string{ "10081/tcp", @@ -59,7 +57,6 @@ func TestParallelContainers(t *testing.T) { }, { ContainerRequest: ContainerRequest{ - Image: "bad bad bad", ExposedPorts: []string{ "10081/tcp", @@ -76,7 +73,6 @@ func TestParallelContainers(t *testing.T) { reqs: ParallelContainerRequest{ { ContainerRequest: ContainerRequest{ - Image: "nginx", ExposedPorts: []string{ "10080/tcp", @@ -86,7 +82,6 @@ func TestParallelContainers(t *testing.T) { }, { ContainerRequest: ContainerRequest{ - Image: "nginx", ExposedPorts: []string{ "10081/tcp", diff --git a/provider_test.go b/provider_test.go index a634ef7914..3459dfe634 100644 --- a/provider_test.go +++ b/provider_test.go @@ -8,7 +8,7 @@ import ( ) func TestProviderTypeGetProviderAutodetect(t *testing.T) { - var dockerHost = testcontainersdocker.ExtractDockerHost(context.Background()) + dockerHost := testcontainersdocker.ExtractDockerHost(context.Background()) const podmanSocket = "unix://$XDG_RUNTIME_DIR/podman/podman.sock" tests := []struct { diff --git a/reaper.go b/reaper.go index 5813f0992a..d55a6d6d55 100644 --- a/reaper.go +++ b/reaper.go @@ -11,6 +11,7 @@ import ( "github.com/docker/docker/api/types/container" "github.com/docker/go-connections/nat" + "github.com/testcontainers/testcontainers-go/internal/testcontainersdocker" "github.com/testcontainers/testcontainers-go/wait" ) diff --git a/reaper_test.go b/reaper_test.go index 9f955f366d..511a216d34 100644 --- a/reaper_test.go +++ b/reaper_test.go @@ -9,6 +9,7 @@ import ( "github.com/docker/docker/api/types/network" "github.com/docker/go-connections/nat" "github.com/stretchr/testify/assert" + "github.com/testcontainers/testcontainers-go/internal/config" "github.com/testcontainers/testcontainers-go/internal/testcontainersdocker" "github.com/testcontainers/testcontainers-go/wait" diff --git a/testdata/echoserver.go b/testdata/echoserver.go index 019c825cd6..db5798699a 100644 --- a/testdata/echoserver.go +++ b/testdata/echoserver.go @@ -10,7 +10,6 @@ import ( func envHandler() http.HandlerFunc { return func(rw http.ResponseWriter, req *http.Request) { - _, _ = rw.Write([]byte(os.Getenv("FOO"))) rw.WriteHeader(http.StatusAccepted) diff --git a/wait/all.go b/wait/all.go index 18531cbf54..fb097fb5ea 100644 --- a/wait/all.go +++ b/wait/all.go @@ -7,8 +7,10 @@ import ( ) // Implement interface -var _ Strategy = (*MultiStrategy)(nil) -var _ StrategyTimeout = (*MultiStrategy)(nil) +var ( + _ Strategy = (*MultiStrategy)(nil) + _ StrategyTimeout = (*MultiStrategy)(nil) +) type MultiStrategy struct { // all Strategies should have a startupTimeout to avoid waiting infinitely diff --git a/wait/exec.go b/wait/exec.go index 82f15c609f..e0ffc89758 100644 --- a/wait/exec.go +++ b/wait/exec.go @@ -9,8 +9,10 @@ import ( ) // Implement interface -var _ Strategy = (*ExecStrategy)(nil) -var _ StrategyTimeout = (*ExecStrategy)(nil) +var ( + _ Strategy = (*ExecStrategy)(nil) + _ StrategyTimeout = (*ExecStrategy)(nil) +) type ExecStrategy struct { // all Strategies should have a startupTimeout to avoid waiting infinitely diff --git a/wait/exec_test.go b/wait/exec_test.go index f4a001314b..21a5b6c331 100644 --- a/wait/exec_test.go +++ b/wait/exec_test.go @@ -11,6 +11,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/go-connections/nat" + "github.com/testcontainers/testcontainers-go" tcexec "github.com/testcontainers/testcontainers-go/exec" "github.com/testcontainers/testcontainers-go/wait" diff --git a/wait/exit.go b/wait/exit.go index 8ff59fe0ae..5526483441 100644 --- a/wait/exit.go +++ b/wait/exit.go @@ -7,8 +7,10 @@ import ( ) // Implement interface -var _ Strategy = (*ExitStrategy)(nil) -var _ StrategyTimeout = (*ExitStrategy)(nil) +var ( + _ Strategy = (*ExitStrategy)(nil) + _ StrategyTimeout = (*ExitStrategy)(nil) +) // ExitStrategy will wait until container exit type ExitStrategy struct { @@ -24,7 +26,6 @@ func NewExitStrategy() *ExitStrategy { return &ExitStrategy{ PollInterval: defaultPollInterval(), } - } // fluent builders for each property diff --git a/wait/exit_test.go b/wait/exit_test.go index 9a4f7eded3..df6aec1c4a 100644 --- a/wait/exit_test.go +++ b/wait/exit_test.go @@ -8,6 +8,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/go-connections/nat" + tcexec "github.com/testcontainers/testcontainers-go/exec" ) diff --git a/wait/health.go b/wait/health.go index b0821c8aec..e4513ae883 100644 --- a/wait/health.go +++ b/wait/health.go @@ -8,8 +8,10 @@ import ( ) // Implement interface -var _ Strategy = (*HealthStrategy)(nil) -var _ StrategyTimeout = (*HealthStrategy)(nil) +var ( + _ Strategy = (*HealthStrategy)(nil) + _ StrategyTimeout = (*HealthStrategy)(nil) +) // HealthStrategy will wait until the container becomes healthy type HealthStrategy struct { @@ -25,7 +27,6 @@ func NewHealthStrategy() *HealthStrategy { return &HealthStrategy{ PollInterval: defaultPollInterval(), } - } // fluent builders for each property diff --git a/wait/health_test.go b/wait/health_test.go index 9f75cf5987..beafe33527 100644 --- a/wait/health_test.go +++ b/wait/health_test.go @@ -10,6 +10,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/go-connections/nat" "github.com/stretchr/testify/assert" + tcexec "github.com/testcontainers/testcontainers-go/exec" ) diff --git a/wait/host_port.go b/wait/host_port.go index 59fe7c113a..6ef1da82bf 100644 --- a/wait/host_port.go +++ b/wait/host_port.go @@ -14,8 +14,10 @@ import ( ) // Implement interface -var _ Strategy = (*HostPortStrategy)(nil) -var _ StrategyTimeout = (*HostPortStrategy)(nil) +var ( + _ Strategy = (*HostPortStrategy)(nil) + _ StrategyTimeout = (*HostPortStrategy)(nil) +) var errShellNotExecutable = errors.New("/bin/sh command not executable") @@ -83,7 +85,7 @@ func (hp *HostPortStrategy) WaitUntilReady(ctx context.Context, target StrategyT return } - var waitInterval = hp.PollInterval + waitInterval := hp.PollInterval internalPort := hp.Port if internalPort == "" { @@ -107,7 +109,7 @@ func (hp *HostPortStrategy) WaitUntilReady(ctx context.Context, target StrategyT var port nat.Port port, err = target.MappedPort(ctx, internalPort) - var i = 0 + i := 0 for port == "" { i++ diff --git a/wait/host_port_test.go b/wait/host_port_test.go index 0a766360b7..92212989eb 100644 --- a/wait/host_port_test.go +++ b/wait/host_port_test.go @@ -10,6 +10,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/go-connections/nat" + "github.com/testcontainers/testcontainers-go/exec" ) diff --git a/wait/http.go b/wait/http.go index 3ebd4469b0..39c0c155f8 100644 --- a/wait/http.go +++ b/wait/http.go @@ -17,8 +17,10 @@ import ( ) // Implement interface -var _ Strategy = (*HTTPStrategy)(nil) -var _ StrategyTimeout = (*HTTPStrategy)(nil) +var ( + _ Strategy = (*HTTPStrategy)(nil) + _ StrategyTimeout = (*HTTPStrategy)(nil) +) type HTTPStrategy struct { // all Strategies should have a startupTimeout to avoid waiting infinitely diff --git a/wait/http_test.go b/wait/http_test.go index a1daee2c15..f1df456bcd 100644 --- a/wait/http_test.go +++ b/wait/http_test.go @@ -17,6 +17,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/go-connections/nat" + "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/wait" ) diff --git a/wait/log.go b/wait/log.go index fca23e28e6..0b802a5693 100644 --- a/wait/log.go +++ b/wait/log.go @@ -8,8 +8,10 @@ import ( ) // Implement interface -var _ Strategy = (*LogStrategy)(nil) -var _ StrategyTimeout = (*LogStrategy)(nil) +var ( + _ Strategy = (*LogStrategy)(nil) + _ StrategyTimeout = (*LogStrategy)(nil) +) // LogStrategy will wait until a given log entry shows up in the docker logs type LogStrategy struct { @@ -104,11 +106,12 @@ LOOP: } logs := string(b) - if length == len(logs) && checkErr != nil { + switch { + case length == len(logs) && checkErr != nil: return checkErr - } else if strings.Count(logs, ws.Log) >= ws.Occurrence { + case strings.Count(logs, ws.Log) >= ws.Occurrence: break LOOP - } else { + default: length = len(logs) time.Sleep(ws.PollInterval) continue diff --git a/wait/nop.go b/wait/nop.go index a16feb8787..e7c86bea5e 100644 --- a/wait/nop.go +++ b/wait/nop.go @@ -7,11 +7,14 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/go-connections/nat" + "github.com/testcontainers/testcontainers-go/exec" ) -var _ Strategy = (*NopStrategy)(nil) -var _ StrategyTimeout = (*NopStrategy)(nil) +var ( + _ Strategy = (*NopStrategy)(nil) + _ StrategyTimeout = (*NopStrategy)(nil) +) type NopStrategy struct { timeout *time.Duration diff --git a/wait/sql.go b/wait/sql.go index 9e0c05607c..c24629ed94 100644 --- a/wait/sql.go +++ b/wait/sql.go @@ -9,8 +9,10 @@ import ( "github.com/docker/go-connections/nat" ) -var _ Strategy = (*waitForSql)(nil) -var _ StrategyTimeout = (*waitForSql)(nil) +var ( + _ Strategy = (*waitForSql)(nil) + _ StrategyTimeout = (*waitForSql)(nil) +) const defaultForSqlQuery = "SELECT 1" diff --git a/wait/wait.go b/wait/wait.go index 559ce39794..46a66f7dfa 100644 --- a/wait/wait.go +++ b/wait/wait.go @@ -9,6 +9,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/go-connections/nat" + "github.com/testcontainers/testcontainers-go/exec" ) diff --git a/wait/wait_test.go b/wait/wait_test.go index 4a18e7bbdb..0e07ba87b6 100644 --- a/wait/wait_test.go +++ b/wait/wait_test.go @@ -7,6 +7,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/go-connections/nat" + tcexec "github.com/testcontainers/testcontainers-go/exec" )