Describe the bug
Trying to run a test results in a panic when trying to get mapped ports.
To Reproduce
https://github.com/todanni/account/blob/main/internal/repository/repository_test.go
Expected behavior
Not panic.
** docker info **
output of the command:
Client:
Context: default
Debug Mode: false
Plugins:
app: Docker App (Docker Inc., v0.9.1-beta3)
buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)
scan: Docker Scan (Docker Inc., v0.5.0)
Server:
Containers: 6
Running: 0
Paused: 0
Stopped: 6
Images: 7
Server Version: 20.10.5
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 269548fa27e0089a8b8278fc4fc781d7f65a939b
runc version: ff819c7e9184c13b7c2607fe6c30ae19403a7aff
init version: de40ad0
Security Options:
seccomp
Profile: default
Kernel Version: 5.4.72-microsoft-standard-WSL2
Operating System: Docker Desktop
OSType: linux
Architecture: x86_64
CPUs: 16
Total Memory: 25.01GiB
Name: docker-desktop
ID: K2UZ:4XFZ:UKRM:UXYT:MSZF:OGA3:QDVU:GVOR:EYU5:54DD:Q3J4:KSCK
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
WARNING: No blkio throttle.read_bps_device support
WARNING: No blkio throttle.write_bps_device support
WARNING: No blkio throttle.read_iops_device support
WARNING: No blkio throttle.write_iops_device support
Additional context
Output from running go test
❯ go test
2021/03/16 13:17:45 Starting container id: dd41a0e8a506 image: quay.io/testcontainers/ryuk:0.2.3
2021/03/16 13:17:46 Waiting for container id dd41a0e8a506 image: quay.io/testcontainers/ryuk:0.2.3
--- FAIL: TestRunAuthenticationTestSuite (0.28s)
suite.go:63: test panicked: runtime error: index out of range [0] with length 0
goroutine 6 [running]:
runtime/debug.Stack(0xc00014e218, 0xc99160, 0xc000128c60)
/usr/local/go/src/runtime/debug/stack.go:24 +0x9f
github.com/stretchr/testify/suite.failOnPanic(0xc0001ce780)
/home/dannipo/go/pkg/mod/github.com/stretchr/[email protected]/suite/suite.go:63 +0x5b
panic(0xc99160, 0xc000128c60)
/usr/local/go/src/runtime/panic.go:965 +0x1b9
github.com/testcontainers/testcontainers-go.(*DockerContainer).MappedPort(0xc00045e100, 0xddd700, 0xc0005244e0, 0xcede63, 0x8, 0x0, 0x0, 0x3132303200000000, 0x63)
/home/dannipo/go/pkg/mod/github.com/testcontainers/[email protected]/docker.go:133 +0x485
github.com/testcontainers/testcontainers-go/wait.(*HostPortStrategy).WaitUntilReady(0xc00011c600, 0xddd6c8, 0xc0005244e0, 0xddd9a0, 0xc00045e100, 0x0, 0x0)
/home/dannipo/go/pkg/mod/github.com/testcontainers/[email protected]/wait/host_port.go:59 +0x16f
github.com/testcontainers/testcontainers-go.(*DockerContainer).Start(0xc00045e100, 0xddd6c8, 0xc0000360d0, 0x0, 0x0)
/home/dannipo/go/pkg/mod/github.com/testcontainers/[email protected]/docker.go:165 +0x315
github.com/testcontainers/testcontainers-go.(*DockerProvider).RunContainer(0xc0005060f0, 0xddd6c8, 0xc0000360d0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xd00532, ...)
/home/dannipo/go/pkg/mod/github.com/testcontainers/[email protected]/docker.go:727 +0xeb
github.com/testcontainers/testcontainers-go.NewReaper(0xddd6c8, 0xc0000360d0, 0xc000152180, 0x24, 0xdcd3a0, 0xc0005060f0, 0x0, 0x0, 0x0, 0x0, ...)
/home/dannipo/go/pkg/mod/github.com/testcontainers/[email protected]/reaper.go:78 +0x455
github.com/testcontainers/testcontainers-go.(*DockerProvider).CreateContainer(0xc0005060f0, 0xddd6c8, 0xc0000360d0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xcee503, ...)
/home/dannipo/go/pkg/mod/github.com/testcontainers/[email protected]/docker.go:534 +0x18c8
github.com/testcontainers/testcontainers-go.GenericContainer(0xddd6c8, 0xc0000360d0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xcee503, 0x8, ...)
/home/dannipo/go/pkg/mod/github.com/testcontainers/[email protected]/generic.go:43 +0xb5
github.com/todanni/authentication/test/container.NewPGContainer(0xcf23fe, 0xf, 0xcea328, 0xcea318, 0xc0000bfd88)
/mnt/c/Projects/todanni/authentication/test/container/postgres.go:41 +0x3db
github.com/todanni/authentication/internal/repository.(*AccountRepoTestSuite).SetupSuite(0xc0004385a0)
/mnt/c/Projects/todanni/authentication/internal/repository/repository_test.go:55 +0x48
github.com/stretchr/testify/suite.Run(0xc0001ce780, 0xdd4880, 0xc0004385a0)
/home/dannipo/go/pkg/mod/github.com/stretchr/[email protected]/suite/suite.go:118 +0x5c7
github.com/todanni/authentication/internal/repository.TestRunAuthenticationTestSuite(0xc0001ce780)
/mnt/c/Projects/todanni/authentication/internal/repository/repository_test.go:25 +0x51
testing.tRunner(0xc0001ce780, 0xd1bd78)
/usr/local/go/src/testing/testing.go:1194 +0xef
created by testing.(*T).Run
/usr/local/go/src/testing/testing.go:1239 +0x2b3
FAIL
exit status 1
FAIL github.com/todanni/authentication/internal/repository 0.287s