fix build_test.go on windows. This code needs to not be run in parallel, or else there can be race conditions with the post-processors all trying to access the same file at once. Additionally, I changed the test template itself so that it is valid code on either bash or cmd. Finally, I found and fixed a small bug in naming the file extensions in shell local inline scripts.

This commit is contained in:
Megan Marsh 2019-04-04 13:22:07 -07:00
parent 196028a7ed
commit 217a93fc30
3 changed files with 13 additions and 7 deletions

View File

@ -17,6 +17,7 @@ func TestBuildOnlyFileCommaFlags(t *testing.T) {
}
args := []string{
"-parallel=false",
"-only=chocolate,vanilla",
filepath.Join(testFixture("build-only"), "template.json"),
}
@ -58,7 +59,7 @@ func TestBuildStdin(t *testing.T) {
defer func() { os.Stdin = stdin }()
defer cleanup()
if code := c.Run([]string{"-"}); code != 0 {
if code := c.Run([]string{"-parallel=false", "-"}); code != 0 {
fatalCommand(t, c.Meta)
}
@ -76,6 +77,7 @@ func TestBuildOnlyFileMultipleFlags(t *testing.T) {
}
args := []string{
"-parallel=false",
"-only=chocolate",
"-only=cherry",
"-only=apple", // ignored
@ -109,6 +111,7 @@ func TestBuildEverything(t *testing.T) {
}
args := []string{
"-parallel=false",
`-except=`,
filepath.Join(testFixture("build-only"), "template.json"),
}
@ -133,6 +136,7 @@ func TestBuildExceptFileCommaFlags(t *testing.T) {
}
args := []string{
"-parallel=false",
"-except=chocolate,vanilla",
filepath.Join(testFixture("build-only"), "template.json"),
}

View File

@ -24,19 +24,19 @@
{
"name": "apple",
"type": "shell-local",
"inline": [ "touch apple.txt" ]
"inline": [ "echo apple > apple.txt" ]
},
{
"name": "peach",
"type": "shell-local",
"inline": [ "touch peach.txt" ]
"inline": [ "echo peach > peach.txt" ]
}
],
[
{
"name": "pear",
"type": "shell-local",
"inline": [ "touch pear.txt" ]
"inline": [ "echo pear > pear.txt" ]
}
],
[
@ -46,7 +46,7 @@
],
"name": "tomato",
"type": "shell-local",
"inline": [ "touch tomato.txt" ]
"inline": [ "echo tomato > tomato.txt" ]
}
],
[
@ -55,7 +55,7 @@
"chocolate"
],
"type": "shell-local",
"inline": [ "touch unnamed.txt" ]
"inline": [ "echo unnamed > unnamed.txt" ]
}
]
]

View File

@ -54,13 +54,15 @@ func Run(ui packer.Ui, config *Config) (bool, error) {
if err != nil {
return false, err
}
scripts = append(scripts, tempScriptFileName)
// figure out what extension the file should have, and rename it.
if config.TempfileExtension != "" {
os.Rename(tempScriptFileName, fmt.Sprintf("%s.%s", tempScriptFileName, config.TempfileExtension))
tempScriptFileName = fmt.Sprintf("%s.%s", tempScriptFileName, config.TempfileExtension)
}
scripts = append(scripts, tempScriptFileName)
defer os.Remove(tempScriptFileName)
}