Implemented acceptance test for compress

This commit is contained in:
Chris Bednarski 2015-06-16 16:31:09 -07:00
parent f5067e9736
commit ddbc145d29
1 changed files with 88 additions and 15 deletions

View File

@ -1,22 +1,95 @@
package compress package compress
// import ( import (
// "testing" "fmt"
// "os"
// builderT "github.com/mitchellh/packer/helper/builder/testing" "strings"
// ) "testing"
//
// func TestBuilderTagsAcc_basic(t *testing.T) { "github.com/mitchellh/packer/builder/file"
// builderT.Test(t, builderT.TestCase{ env "github.com/mitchellh/packer/helper/builder/testing"
// Builder: &Builder{}, "github.com/mitchellh/packer/packer"
// Template: simpleTestCase, "github.com/mitchellh/packer/template"
// Check: checkTags(), )
// })
// } func setup(t *testing.T) (packer.Ui, packer.Artifact, error) {
// Create fake UI and Cache
ui := packer.TestUi(t)
cache := &packer.FileCache{CacheDir: os.TempDir()}
// Create config for file builder
const fileConfig = `{"builders":[{"type":"file","target":"package.txt","content":"Hello world!"}]}`
tpl, err := template.Parse(strings.NewReader(fileConfig))
if err != nil {
return nil, nil, fmt.Errorf("Unable to parse setup configuration: %s", err)
}
// Prepare the file builder
builder := file.Builder{}
warnings, err := builder.Prepare(tpl.Builders["file"].Config)
if len(warnings) > 0 {
for _, warn := range warnings {
return nil, nil, fmt.Errorf("Configuration warning: %s", warn)
}
}
if err != nil {
return nil, nil, fmt.Errorf("Invalid configuration: %s", err)
}
// Run the file builder
artifact, err := builder.Run(ui, nil, cache)
if err != nil {
return nil, nil, fmt.Errorf("Failed to build artifact: %s", err)
}
return ui, artifact, err
}
func TestSimpleCompress(t *testing.T) {
if os.Getenv(env.TestEnvVar) == "" {
t.Skip(fmt.Sprintf(
"Acceptance tests skipped unless env '%s' set", env.TestEnvVar))
}
ui, artifact, err := setup(t)
if err != nil {
t.Fatalf("Error bootstrapping test: %s", err)
}
if artifact != nil {
defer artifact.Destroy()
}
tpl, err := template.Parse(strings.NewReader(simpleTestCase))
if err != nil {
t.Fatalf("Unable to parse test config: %s", err)
}
compressor := PostProcessor{}
compressor.Configure(tpl.PostProcessors[0][0].Config)
artifactOut, _, err := compressor.PostProcess(ui, artifact)
if err != nil {
t.Fatalf("Failed to compress artifact: %s", err)
}
// Cleanup after the test completes
defer artifactOut.Destroy()
// Verify things look good
fi, err := os.Stat("package.tar.gz")
if err != nil {
t.Errorf("Unable to read archive: %s", err)
}
if fi.IsDir() {
t.Error("Archive should not be a directory")
}
}
const simpleTestCase = ` const simpleTestCase = `
{
"post-processors": [
{ {
"type": "compress", "type": "compress",
"output": "foo.tar.gz" "output": "package.tar.gz"
}
]
} }
` `