Skip to content
Merged
4 changes: 2 additions & 2 deletions .github/workflows/ci-lint-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ jobs:
id: go

- name: golangci-lint
uses: golangci/golangci-lint-action@55c2c1448f86e01eaae002a5a3a9624417608d84 # v6.5.2
uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # v7.0.0
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.63.4
version: v2.0.2
# Optional: working directory, useful for monorepos
working-directory: ${{ inputs.project-directory }}

Expand Down
149 changes: 76 additions & 73 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,86 +1,89 @@
formatters:
enable:
- gci
- gofumpt
settings:
gci:
sections:
- standard
- default
- prefix(github.com/testcontainers)
linters:
enable:
- errcheck
- errorlint
- gci
- gocritic
- gofumpt
- misspell
- nolintlint
- nakedret
- nolintlint
- perfsprint
- revive
- testifylint
- thelper
- usestdlibvars

linters-settings:
errorlint:
# Check whether fmt.Errorf uses the %w verb for formatting errors.
# See the https://github.com/polyfloyd/go-errorlint for caveats.
errorf: true
# Permit more than 1 %w verb, valid per Go 1.20 (Requires errorf:true)
errorf-multi: true
# Check for plain type assertions and type switches.
asserts: true
# Check for plain error comparisons.
comparison: true
gci:
sections:
- standard
- default
- prefix(github.com/testcontainers)
nakedret:
max-func-lines: 0
revive:
rules:
- name: blank-imports
- name: context-as-argument
arguments:
- allowTypesBefore: "*testing.T"
- name: context-keys-type
- name: dot-imports
- name: early-return
arguments:
- "preserveScope"
- name: empty-block
- name: error-naming
disabled: true
- name: error-return
- name: error-strings
disabled: true
- name: errorf
- name: increment-decrement
- name: indent-error-flow
arguments:
- "preserveScope"
- name: range
- name: receiver-naming
- name: redefines-builtin-id
disabled: true
- name: superfluous-else
arguments:
- "preserveScope"
- name: time-naming
- name: unexported-return
disabled: true
- name: unreachable-code
- name: unused-parameter
- name: use-any
- name: var-declaration
- name: var-naming
arguments:
- ["ID"] # AllowList
- ["VM"] # DenyList
- - upperCaseConst: true # Extra parameter (upperCaseConst|skipPackageNameChecks)
testifylint:
disable:
- float-compare
- go-require
enable-all: true
exclusions:
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
settings:
errorlint:
asserts: true
comparison: true
errorf: true
errorf-multi: true
revive:
rules:
- name: blank-imports
- name: context-as-argument
arguments:
- allowTypesBefore: '*testing.T'
- name: context-keys-type
- name: dot-imports
- name: early-return
arguments:
- preserveScope
- name: empty-block
- name: error-naming
disabled: true
- name: error-return
- name: error-strings
disabled: true
- name: errorf
- name: increment-decrement
- name: indent-error-flow
arguments:
- preserveScope
- name: range
- name: receiver-naming
- name: redefines-builtin-id
disabled: true
- name: superfluous-else
arguments:
- preserveScope
- name: time-naming
- name: unexported-return
disabled: true
- name: unreachable-code
- name: unused-parameter
- name: use-any
- name: var-declaration
- name: var-naming
arguments:
- - ID
- - VM
- - upperCaseConst: true
staticcheck:
checks:
- all
testifylint:
disable:
- float-compare
- go-require
enable-all: true
output:
formats:
- format: colored-line-number
path-prefix: "."
run:
timeout: 5m
text:
path: stdout
path-prefix: .
version: "2"
2 changes: 1 addition & 1 deletion commons-test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ define go_install
endef

$(GOBIN)/golangci-lint:
$(call go_install,github.com/golangci/golangci-lint/cmd/golangci-lint@v1.63.4)
$(call go_install,github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.0.2)

$(GOBIN)/gotestsum:
$(call go_install,gotest.tools/gotestsum@latest)
Expand Down
40 changes: 21 additions & 19 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,37 +285,37 @@ func parseDockerIgnore(targetDir string) (bool, []string, error) {

// GetBuildArgs returns the env args to be used when creating from Dockerfile
func (c *ContainerRequest) GetBuildArgs() map[string]*string {
return c.FromDockerfile.BuildArgs
return c.BuildArgs
}

// GetDockerfile returns the Dockerfile from the ContainerRequest, defaults to "Dockerfile".
// Sets FromDockerfile.Dockerfile to the default if blank.
func (c *ContainerRequest) GetDockerfile() string {
if c.FromDockerfile.Dockerfile == "" {
c.FromDockerfile.Dockerfile = "Dockerfile"
if c.Dockerfile == "" {
c.Dockerfile = "Dockerfile"
}

return c.FromDockerfile.Dockerfile
return c.Dockerfile
}

// GetRepo returns the Repo label for image from the ContainerRequest, defaults to UUID.
// Sets FromDockerfile.Repo to the default value if blank.
func (c *ContainerRequest) GetRepo() string {
if c.FromDockerfile.Repo == "" {
c.FromDockerfile.Repo = uuid.NewString()
if c.Repo == "" {
c.Repo = uuid.NewString()
}

return strings.ToLower(c.FromDockerfile.Repo)
return strings.ToLower(c.Repo)
}

// GetTag returns the Tag label for image from the ContainerRequest, defaults to UUID.
// Sets FromDockerfile.Tag to the default value if blank.
func (c *ContainerRequest) GetTag() string {
if c.FromDockerfile.Tag == "" {
c.FromDockerfile.Tag = uuid.NewString()
if c.Tag == "" {
c.Tag = uuid.NewString()
}

return strings.ToLower(c.FromDockerfile.Tag)
return strings.ToLower(c.Tag)
}

// Deprecated: Testcontainers will detect registry credentials automatically, and it will be removed in the next major release.
Expand Down Expand Up @@ -343,13 +343,13 @@ func (c *ContainerRequest) dockerFileImages() ([]string, error) {

// Source is an archive, we need to read it to get the Dockerfile.
dockerFile := c.GetDockerfile()
tr := tar.NewReader(c.FromDockerfile.ContextArchive)
tr := tar.NewReader(c.ContextArchive)

for {
hdr, err := tr.Next()
if err != nil {
if errors.Is(err, io.EOF) {
return nil, fmt.Errorf("Dockerfile %q not found in context archive", dockerFile)
return nil, fmt.Errorf("dockerfile %q not found in context archive", dockerFile)
}

return nil, fmt.Errorf("reading tar archive: %w", err)
Expand Down Expand Up @@ -405,22 +405,24 @@ func getAuthConfigsFromDockerfile(c *ContainerRequest) (map[string]registry.Auth
}

func (c *ContainerRequest) ShouldBuildImage() bool {
return c.FromDockerfile.Context != "" || c.FromDockerfile.ContextArchive != nil
return c.Context != "" || c.ContextArchive != nil
}

func (c *ContainerRequest) ShouldKeepBuiltImage() bool {
return c.FromDockerfile.KeepImage
return c.KeepImage
}

// BuildLogWriter returns the io.Writer for output of log when building a Docker image from
// a Dockerfile. It returns the BuildLogWriter from the ContainerRequest, defaults to io.Discard.
// For backward compatibility, if BuildLogWriter is default and PrintBuildLog is true,
// the function returns os.Stderr.
//
//nolint:staticcheck //FIXME
func (c *ContainerRequest) BuildLogWriter() io.Writer {
if c.FromDockerfile.BuildLogWriter != nil {
return c.FromDockerfile.BuildLogWriter
}
if c.FromDockerfile.PrintBuildLog {
if c.PrintBuildLog {
c.FromDockerfile.BuildLogWriter = os.Stderr
} else {
c.FromDockerfile.BuildLogWriter = io.Discard
Expand All @@ -437,8 +439,8 @@ func (c *ContainerRequest) BuildOptions() (types.ImageBuildOptions, error) {
ForceRemove: true,
}

if c.FromDockerfile.BuildOptionsModifier != nil {
c.FromDockerfile.BuildOptionsModifier(&buildOptions)
if c.BuildOptionsModifier != nil {
c.BuildOptionsModifier(&buildOptions)
}

// apply mandatory values after the modifier
Expand Down Expand Up @@ -505,15 +507,15 @@ func (c *ContainerRequest) BuildOptions() (types.ImageBuildOptions, error) {
}

func (c *ContainerRequest) validateContextAndImage() error {
if c.FromDockerfile.Context != "" && c.Image != "" {
if c.Context != "" && c.Image != "" {
return errors.New("you cannot specify both an Image and Context in a ContainerRequest")
}

return nil
}

func (c *ContainerRequest) validateContextOrImageIsSpecified() error {
if c.FromDockerfile.Context == "" && c.FromDockerfile.ContextArchive == nil && c.Image == "" {
if c.Context == "" && c.ContextArchive == nil && c.Image == "" {
return errors.New("you must specify either a build context or an image")
}

Expand Down
4 changes: 2 additions & 2 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (c *DockerContainer) MappedPort(ctx context.Context, port nat.Port) (nat.Po
if err != nil {
return "", fmt.Errorf("inspect: %w", err)
}
if inspect.ContainerJSONBase.HostConfig.NetworkMode == "host" {
if inspect.HostConfig.NetworkMode == "host" {
return port, nil
}

Expand Down Expand Up @@ -1619,7 +1619,7 @@ func (p *DockerProvider) getGatewayIP(ctx context.Context, defaultNetwork string
}
}
if ip == "" {
return "", errors.New("Failed to get gateway IP from network settings")
return "", errors.New("failed to get gateway IP from network settings")
}

return ip, nil
Expand Down
2 changes: 1 addition & 1 deletion docker_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (c *DockerClient) Info(ctx context.Context) (system.Info, error) {

log.Printf(infoMessage, packagePath,
dockerInfo.ServerVersion,
c.Client.ClientVersion(),
c.ClientVersion(),
dockerInfo.OperatingSystem, dockerInfo.MemTotal/1024/1024,
infoLabels,
internal.Version,
Expand Down
4 changes: 2 additions & 2 deletions docs/features/wait/walk.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ removing specific strategies based on requirements of functional options.
For example removing a TLS strategy if a functional option enabled insecure mode
or changing the location of the certificate based on the configured user.

If visit function returns `wait.VisitStop`, the walk stops.
If visit function returns `wait.VisitRemove`, the current node is removed.
If visit function returns `wait.ErrVisitStop`, the walk stops.
If visit function returns `wait.ErrVisitRemove`, the current node is removed.

## Walk removing entries

Expand Down
2 changes: 1 addition & 1 deletion internal/core/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func init() {
}

hasher := sha256.New()
_, err = hasher.Write([]byte(fmt.Sprintf(sessionIDPlaceholder, parentPid, createTime)))
_, err = fmt.Fprintf(hasher, sessionIDPlaceholder, parentPid, createTime)
if err != nil {
sessionID = uuid.New().String()
return
Expand Down
8 changes: 4 additions & 4 deletions internal/core/docker_host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func TestExtractDockerHost(t *testing.T) {

host, err := extractDockerHost(context.Background())
require.Error(t, err)
require.Equal(t, "", host)
require.Empty(t, host)
})

t.Run("Docker Host as environment variable", func(t *testing.T) {
Expand All @@ -122,7 +122,7 @@ func TestExtractDockerHost(t *testing.T) {

host, err := extractDockerHost(context.WithValue(ctx, DockerHostContextKey, "path-to-docker-sock"))
require.Error(t, err)
require.Equal(t, "", host)
require.Empty(t, host)
})

t.Run("Malformed Schema Docker Host is passed in context", func(t *testing.T) {
Expand All @@ -132,7 +132,7 @@ func TestExtractDockerHost(t *testing.T) {

host, err := extractDockerHost(context.WithValue(ctx, DockerHostContextKey, "http://path to docker sock"))
require.Error(t, err)
require.Equal(t, "", host)
require.Empty(t, host)
})

t.Run("Unix Docker Host is passed in context", func(t *testing.T) {
Expand Down Expand Up @@ -169,7 +169,7 @@ func TestExtractDockerHost(t *testing.T) {
setupRootlessNotFound(t)
host, err := extractDockerHost(context.Background())
require.Error(t, err)
require.Equal(t, "", host)
require.Empty(t, host)
})

t.Run("Extract Docker socket", func(t *testing.T) {
Expand Down
Loading
Loading