testcontainers / testcontainers-go

Testcontainers for Go is a Go package that makes it simple to create and clean up container-based dependencies for automated integration/smoke tests. The clean, easy-to-use API enables developers to programmatically define containers that should be run as part of a test and clean up those resources when the test is done.
https://golang.testcontainers.org
MIT License
3.34k stars 460 forks source link

[Bug]: linting #2330

Open antonyc opened 4 months ago

antonyc commented 4 months ago

Testcontainers version

0.27.0

Using the latest Testcontainers version?

Yes

Host OS

MacOS

Host arch

arm

Go version

1.21

Docker version

Client:
 Version:           25.0.2
 API version:       1.44
 Go version:        go1.21.6
 Git commit:        29cf629
 Built:             Thu Feb  1 00:18:45 2024
 OS/Arch:           darwin/arm64
 Context:           orbstack

Server: Docker Engine - Community
 Engine:
  Version:          25.0.2
  API version:      1.44 (minimum version 1.24)
  Go version:       go1.21.6
  Git commit:       fce6e0c
  Built:            Thu Feb  1 00:23:35 2024
  OS/Arch:          linux/arm64
  Experimental:     true
 containerd:
  Version:          v1.7.7
  GitCommit:        8c087663b0233f6e6e2f4515cee61d49f14746a8
 runc:
  Version:          1.1.9
  GitCommit:        82f18fe0e44a59034f3e1f45e475fa5636e539aa
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Docker info

Client:
 Version:    25.0.2
 Context:    orbstack
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.11.2-desktop.4
    Path:     /Users/chapson/.docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.21.0-desktop.1
    Path:     /Users/chapson/.docker/cli-plugins/docker-compose
  dev: Docker Dev Environments (Docker Inc.)
    Version:  v0.1.0
    Path:     /Users/chapson/.docker/cli-plugins/docker-dev
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.20
    Path:     /Users/chapson/.docker/cli-plugins/docker-extension
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v0.1.0-beta.7
    Path:     /Users/chapson/.docker/cli-plugins/docker-init
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     /Users/chapson/.docker/cli-plugins/docker-sbom
  scan: Docker Scan (Docker Inc.)
    Version:  v0.26.0
    Path:     /Users/chapson/.docker/cli-plugins/docker-scan
  scout: Command line tool for Docker Scout (Docker Inc.)
    Version:  0.24.1
    Path:     /Users/chapson/.docker/cli-plugins/docker-scout

Server:
 Containers: 820
  Running: 3
  Paused: 0
  Stopped: 817
 Images: 182
 Server Version: 25.0.2
 Storage Driver: overlay2
  Backing Filesystem: btrfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 8c087663b0233f6e6e2f4515cee61d49f14746a8
 runc version: 82f18fe0e44a59034f3e1f45e475fa5636e539aa
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.5.13-orbstack-00122-g57b8027e2387
 Operating System: OrbStack
 OSType: linux
 Architecture: aarch64
 CPUs: 12
 Total Memory: 7.748GiB
 Name: orbstack
 ID: 42d6769b-51b9-405a-b5a8-9d84d387b7ab
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: true
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false
 Product License: Community Engine
 Default Address Pools:
   Base: 192.168.215.0/24, Size: 24
   Base: 192.168.228.0/24, Size: 24
   Base: 192.168.247.0/24, Size: 24
   Base: 192.168.207.0/24, Size: 24
   Base: 192.168.167.0/24, Size: 24
   Base: 192.168.107.0/24, Size: 24
   Base: 192.168.237.0/24, Size: 24
   Base: 192.168.148.0/24, Size: 24
   Base: 192.168.214.0/24, Size: 24
   Base: 192.168.165.0/24, Size: 24
   Base: 192.168.227.0/24, Size: 24
   Base: 192.168.181.0/24, Size: 24
   Base: 192.168.158.0/24, Size: 24
   Base: 192.168.117.0/24, Size: 24
   Base: 192.168.155.0/24, Size: 24
   Base: 192.168.147.0/24, Size: 24
   Base: 192.168.229.0/24, Size: 24
   Base: 192.168.183.0/24, Size: 24
   Base: 192.168.156.0/24, Size: 24
   Base: 192.168.97.0/24, Size: 24
   Base: 192.168.171.0/24, Size: 24
   Base: 192.168.186.0/24, Size: 24
   Base: 192.168.216.0/24, Size: 24
   Base: 192.168.242.0/24, Size: 24
   Base: 192.168.166.0/24, Size: 24
   Base: 192.168.239.0/24, Size: 24
   Base: 192.168.223.0/24, Size: 24
   Base: 192.168.164.0/24, Size: 24
   Base: 192.168.163.0/24, Size: 24
   Base: 192.168.172.0/24, Size: 24
   Base: 172.17.0.0/16, Size: 16
   Base: 172.18.0.0/16, Size: 16
   Base: 172.19.0.0/16, Size: 16
   Base: 172.20.0.0/14, Size: 16
   Base: 172.24.0.0/14, Size: 16
   Base: 172.28.0.0/14, Size: 16

What happened?

Running golangci lint after upgrading to either latest version v0.29.1 or to v0.27.0 makes golang ci lint fail.

Relevant log output

ERRO [runner] Panic: SA4023: package "postgres" (isInitialPkg: true, needAnalyzeSource: true): runtime error: index out of range [1] with length 1: goroutine 37321 [running]:
runtime/debug.Stack()
    /usr/local/go/src/runtime/debug/stack.go:24 +0x64
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func1()
    /Users/chapson/go/pkg/mod/github.com/golangci/golangci-lint@v1.55.2/pkg/golinters/goanalysis/runner_action.go:109 +0x224
panic({0x101603cc0?, 0x14027579920?})
    /usr/local/go/src/runtime/panic.go:914 +0x218
honnef.co/go/tools/analysis/facts/nilness.(*Result).MayReturnNil(0x14007e0d388, 0x1400a5ab3e0, 0x1)
    /Users/chapson/go/pkg/mod/honnef.co/go/tools@v0.4.6/analysis/facts/nilness/nilness.go:56 +0x108
honnef.co/go/tools/staticcheck.CheckTypedNilInterface(0x140307e8750)
    /Users/chapson/go/pkg/mod/honnef.co/go/tools@v0.4.6/staticcheck/lint.go:4615 +0x74c
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyze(0x140050eaea0)
    /Users/chapson/go/pkg/mod/github.com/golangci/golangci-lint@v1.55.2/pkg/golinters/goanalysis/runner_action.go:195 +0x900
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func2()
    /Users/chapson/go/pkg/mod/github.com/golangci/golangci-lint@v1.55.2/pkg/golinters/goanalysis/runner_action.go:113 +0x20
github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0x140018714a0, {0x10113f3b9, 0x6}, 0x140033b5730)
    /Users/chapson/go/pkg/mod/github.com/golangci/golangci-lint@v1.55.2/pkg/timeutils/stopwatch.go:111 +0x44
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe(0x100b13800?)
    /Users/chapson/go/pkg/mod/github.com/golangci/golangci-lint@v1.55.2/pkg/golinters/goanalysis/runner_action.go:112 +0x78
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze.func2(0x140050eaea0)
    /Users/chapson/go/pkg/mod/github.com/golangci/golangci-lint@v1.55.2/pkg/golinters/goanalysis/runner_loadingpackage.go:80 +0xb0
created by github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze in goroutine 239
    /Users/chapson/go/pkg/mod/github.com/golangci/golangci-lint@v1.55.2/pkg/golinters/goanalysis/runner_loadingpackage.go:75 +0x184
WARN [runner] Can't run linter goanalysis_metalinter: goanalysis_metalinter: SA4023: package "postgres" (isInitialPkg: true, needAnalyzeSource: true): runtime error: index out of range [1] with length 1
ERRO Running error: 1 error occurred:
    * can't run linter goanalysis_metalinter: goanalysis_metalinter: SA4023: package "postgres" (isInitialPkg: true, needAnalyzeSource: true): runtime error: index out of range [1] with length 1

make: *** [lint] Error 3

Additional information

Using 0.25.0 does not produce such errors.

mdelapenya commented 4 months ago

Hey @antonyc I understand this is happening in your own project, right?

We do run golangci-lint for every PR, with the settings in the root dir of the repo, so I'm not sure what is going on here.

From the above output, I cannot see anything in clear: could you provide some more feedback or a repro repo where it fails (including golangci-lint configs 🙏 ?

stevenh commented 4 months ago

might want to try reinstalling golangci-lint could be you have go version miss match.