2013-06-26 22:09:24 -04:00
|
|
|
package vagrant
|
|
|
|
|
|
|
|
import (
|
2013-12-19 17:04:45 -05:00
|
|
|
"bytes"
|
|
|
|
"compress/flate"
|
2013-06-26 22:09:24 -04:00
|
|
|
"github.com/mitchellh/packer/packer"
|
2013-12-19 17:04:45 -05:00
|
|
|
"strings"
|
2013-06-26 22:09:24 -04:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func testConfig() map[string]interface{} {
|
|
|
|
return map[string]interface{}{}
|
|
|
|
}
|
|
|
|
|
2013-12-19 17:04:45 -05:00
|
|
|
func testPP(t *testing.T) *PostProcessor {
|
|
|
|
var p PostProcessor
|
|
|
|
if err := p.Configure(testConfig()); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &p
|
|
|
|
}
|
|
|
|
|
|
|
|
func testUi() *packer.BasicUi {
|
|
|
|
return &packer.BasicUi{
|
|
|
|
Reader: new(bytes.Buffer),
|
|
|
|
Writer: new(bytes.Buffer),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-26 22:09:24 -04:00
|
|
|
func TestPostProcessor_ImplementsPostProcessor(t *testing.T) {
|
2013-12-19 16:22:46 -05:00
|
|
|
var _ packer.PostProcessor = new(PostProcessor)
|
2013-06-26 22:09:24 -04:00
|
|
|
}
|
|
|
|
|
2013-12-19 17:04:45 -05:00
|
|
|
func TestPostProcessorPrepare_compressionLevel(t *testing.T) {
|
|
|
|
var p PostProcessor
|
|
|
|
|
|
|
|
// Default
|
|
|
|
c := testConfig()
|
|
|
|
delete(c, "compression_level")
|
|
|
|
if err := p.Configure(c); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if p.config.CompressionLevel != flate.DefaultCompression {
|
|
|
|
t.Fatalf("bad: %#v", p.config.CompressionLevel)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set
|
|
|
|
c = testConfig()
|
|
|
|
c["compression_level"] = 7
|
|
|
|
if err := p.Configure(c); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if p.config.CompressionLevel != 7 {
|
|
|
|
t.Fatalf("bad: %#v", p.config.CompressionLevel)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPostProcessorPrepare_outputPath(t *testing.T) {
|
2013-06-26 22:09:24 -04:00
|
|
|
var p PostProcessor
|
|
|
|
|
2013-06-27 13:53:43 -04:00
|
|
|
// Default
|
2013-06-26 22:09:24 -04:00
|
|
|
c := testConfig()
|
|
|
|
delete(c, "output")
|
|
|
|
err := p.Configure(c)
|
2013-06-27 13:53:43 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bad template
|
|
|
|
c["output"] = "bad {{{{.Template}}}}"
|
|
|
|
err = p.Configure(c)
|
2013-06-26 22:09:24 -04:00
|
|
|
if err == nil {
|
2013-06-27 13:53:43 -04:00
|
|
|
t.Fatal("should have error")
|
2013-06-26 22:09:24 -04:00
|
|
|
}
|
|
|
|
}
|
2013-06-28 10:16:38 -04:00
|
|
|
|
2013-12-19 17:04:45 -05:00
|
|
|
func TestPostProcessorPostProcess_badId(t *testing.T) {
|
|
|
|
artifact := &packer.MockArtifact{
|
|
|
|
BuilderIdValue: "invalid.packer",
|
|
|
|
}
|
|
|
|
|
|
|
|
_, _, err := testPP(t).PostProcess(testUi(), artifact)
|
|
|
|
if !strings.Contains(err.Error(), "artifact type") {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-19 16:22:46 -05:00
|
|
|
func TestProviderForName(t *testing.T) {
|
|
|
|
if v, ok := providerForName("virtualbox").(*VBoxProvider); !ok {
|
|
|
|
t.Fatalf("bad: %#v", v)
|
|
|
|
}
|
2013-06-28 10:16:38 -04:00
|
|
|
|
2013-12-19 16:22:46 -05:00
|
|
|
if providerForName("nope") != nil {
|
|
|
|
t.Fatal("should be nil if bad provider")
|
2013-06-28 10:16:38 -04:00
|
|
|
}
|
|
|
|
}
|