command.TestBuildOnlyFileCommaFlags: create some files using post processors

This commit is contained in:
Adrien Delorme 2019-01-10 11:37:41 +01:00
parent 9f2a3bdfbc
commit 905db043c4
2 changed files with 24 additions and 7 deletions

View File

@ -8,6 +8,7 @@ import (
"github.com/hashicorp/packer/builder/file" "github.com/hashicorp/packer/builder/file"
"github.com/hashicorp/packer/packer" "github.com/hashicorp/packer/packer"
shell_local "github.com/hashicorp/packer/post-processor/shell-local"
) )
func TestBuildOnlyFileCommaFlags(t *testing.T) { func TestBuildOnlyFileCommaFlags(t *testing.T) {
@ -111,14 +112,15 @@ func TestBuildExceptFileCommaFlags(t *testing.T) {
fatalCommand(t, c.Meta) fatalCommand(t, c.Meta)
} }
if fileExists("chocolate.txt") { for _, f := range []string{"chocolate.txt"} {
t.Error("Expected NOT to find chocolate.txt") if fileExists(f) {
t.Errorf("Expected NOT to find %s", f)
} }
if !fileExists("vanilla.txt") {
t.Error("Expected to find vanilla.txt")
} }
if !fileExists("cherry.txt") { for _, f := range []string{"vanilla.txt", "cherry.txt", "apple.txt", "peach.txt"} {
t.Error("Expected to find cherry.txt") if !fileExists(f) {
t.Errorf("Expected to find %s", f)
}
} }
} }
@ -137,6 +139,9 @@ func testCoreConfigBuilder(t *testing.T) *packer.CoreConfig {
Builder: func(n string) (packer.Builder, error) { Builder: func(n string) (packer.Builder, error) {
return &file.Builder{}, nil return &file.Builder{}, nil
}, },
PostProcessor: func(n string) (packer.PostProcessor, error) {
return &shell_local.PostProcessor{}, nil
},
} }
return &packer.CoreConfig{ return &packer.CoreConfig{
Components: components, Components: components,
@ -159,4 +164,6 @@ func cleanup() {
os.RemoveAll("chocolate.txt") os.RemoveAll("chocolate.txt")
os.RemoveAll("vanilla.txt") os.RemoveAll("vanilla.txt")
os.RemoveAll("cherry.txt") os.RemoveAll("cherry.txt")
os.RemoveAll("apple.txt")
os.RemoveAll("peach.txt")
} }

View File

@ -18,5 +18,15 @@
"content":"cherry", "content":"cherry",
"target":"cherry.txt" "target":"cherry.txt"
} }
],
"post-processors": [
{
"type": "shell-local",
"inline": ["touch apple.txt"]
},
{
"type": "shell-local",
"inline": ["touch peach.txt"]
}
] ]
} }