package main_test import ( "strings" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) // TestDockerfileBoundsEveryModuleDownload fails unless every // `go mod download` in the Dockerfile runs under a time limit, is tried // a fixed number of times, and then fails the build with a message that // names the module download (issue #351). Like the version tests, this // parses the Dockerfile; that a stalled download really is cut off and // retried was checked by hand. func TestDockerfileBoundsEveryModuleDownload(t *testing.T) { t.Parallel() var downloads []string for _, instruction := range instructions(t, productDockerfile) { if strings.Contains(instruction, "go mod download") { downloads = append(downloads, instruction) } } require.NotEmpty(t, downloads, "%s must download modules", productDockerfile) for _, download := range downloads { assert.Contains(t, download, "timeout 300 go mod download", "%s: a module download must have a time limit: %s", productDockerfile, download) assert.Contains(t, download, "for attempt in 1 2 3", "%s: a module download must be retried: %s", productDockerfile, download) assert.Contains(t, download, "module download failed", "%s: a module download that never succeeds must say so: %s", productDockerfile, download) assert.True(t, strings.HasSuffix(download, "exit 1"), "%s: a module download that never succeeds must fail the"+ " build: %s", productDockerfile, download) } }