Compare commits
1
Commits
next
..
696ac05a45
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
696ac05a45 |
@@ -68,6 +68,32 @@ func TestPerformBuildFollowsDockerignore(t *testing.T) {
|
|||||||
},
|
},
|
||||||
want: []string{defaultDockerignoreName, defaultDockerfileName, testMainGo},
|
want: []string{defaultDockerignoreName, defaultDockerfileName, testMainGo},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "keeps a lowercase dockerfile built in place of a missing Dockerfile",
|
||||||
|
dockerfile: defaultDockerfileName,
|
||||||
|
files: map[string]string{
|
||||||
|
defaultDockerignoreName: "*\n",
|
||||||
|
testLowercaseDockerfile: "",
|
||||||
|
},
|
||||||
|
want: []string{defaultDockerignoreName, testLowercaseDockerfile},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "reads a lowercase dockerfile's own ignore file",
|
||||||
|
dockerfile: defaultDockerfileName,
|
||||||
|
files: map[string]string{
|
||||||
|
defaultDockerignoreName: "main.go\n",
|
||||||
|
testLowercaseDockerfile: "",
|
||||||
|
"dockerfile.dockerignore": "secret.txt\n",
|
||||||
|
testMainGo: "",
|
||||||
|
testSecretFile: "",
|
||||||
|
},
|
||||||
|
want: []string{
|
||||||
|
defaultDockerignoreName,
|
||||||
|
testLowercaseDockerfile,
|
||||||
|
"dockerfile.dockerignore",
|
||||||
|
testMainGo,
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "an ignore file next to the Dockerfile wins over .dockerignore",
|
name: "an ignore file next to the Dockerfile wins over .dockerignore",
|
||||||
dockerfile: testDeployDockerfile,
|
dockerfile: testDeployDockerfile,
|
||||||
@@ -106,62 +132,6 @@ func TestPerformBuildFollowsDockerignore(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestPerformBuildKeepsLowercaseDockerfile checks that when the Dockerfile
|
|
||||||
// named Dockerfile is missing, the lowercase dockerfile Docker builds instead
|
|
||||||
// stays in the build context, and its own ignore file is read.
|
|
||||||
func TestPerformBuildKeepsLowercaseDockerfile(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
files map[string]string // path in the context: contents
|
|
||||||
want []string // files sent in the build context
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "kept when the ignore file names it",
|
|
||||||
files: map[string]string{
|
|
||||||
defaultDockerignoreName: "*\n",
|
|
||||||
testLowercaseDockerfile: "",
|
|
||||||
},
|
|
||||||
want: []string{defaultDockerignoreName, testLowercaseDockerfile},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "its own ignore file wins over .dockerignore",
|
|
||||||
files: map[string]string{
|
|
||||||
defaultDockerignoreName: "main.go\n",
|
|
||||||
testLowercaseDockerfile: "",
|
|
||||||
"dockerfile.dockerignore": "secret.txt\n",
|
|
||||||
testMainGo: "",
|
|
||||||
testSecretFile: "",
|
|
||||||
},
|
|
||||||
want: []string{
|
|
||||||
defaultDockerignoreName,
|
|
||||||
testLowercaseDockerfile,
|
|
||||||
"dockerfile.dockerignore",
|
|
||||||
testMainGo,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tt := range tests {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
contextDir := t.TempDir()
|
|
||||||
writeFiles(t, contextDir, tt.files)
|
|
||||||
|
|
||||||
got, err := buildContextFiles(t, contextDir, defaultDockerfileName)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !slices.Equal(got, tt.want) {
|
|
||||||
t.Errorf("build context holds %q, want %q", got, tt.want)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TestPerformBuildReadsDockerfilePathInsideContext checks that ./Dockerfile
|
// TestPerformBuildReadsDockerfilePathInsideContext checks that ./Dockerfile
|
||||||
// and /Dockerfile name the Dockerfile at the root of the context, as Docker
|
// and /Dockerfile name the Dockerfile at the root of the context, as Docker
|
||||||
// reads them, so an ignore file that names the Dockerfile does not leave it
|
// reads them, so an ignore file that names the Dockerfile does not leave it
|
||||||
|
|||||||
Reference in New Issue
Block a user