Commit 6518c92e authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

post-processor/vagrant: more tests

parent 7b6bbbf4
...@@ -2,16 +2,26 @@ package packer ...@@ -2,16 +2,26 @@ package packer
// MockArtifact is an implementation of Artifact that can be used for tests. // MockArtifact is an implementation of Artifact that can be used for tests.
type MockArtifact struct { type MockArtifact struct {
IdValue string BuilderIdValue string
DestroyCalled bool FilesValue []string
IdValue string
DestroyCalled bool
} }
func (*MockArtifact) BuilderId() string { func (a *MockArtifact) BuilderId() string {
return "bid" if a.BuilderIdValue == "" {
return "bid"
}
return a.BuilderIdValue
} }
func (*MockArtifact) Files() []string { func (a *MockArtifact) Files() []string {
return []string{"a", "b"} if a.FilesValue == nil {
return []string{"a", "b"}
}
return a.FilesValue
} }
func (a *MockArtifact) Id() string { func (a *MockArtifact) Id() string {
......
package vagrant package vagrant
import ( import (
"bytes"
"compress/flate"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"strings"
"testing" "testing"
) )
...@@ -9,11 +12,53 @@ func testConfig() map[string]interface{} { ...@@ -9,11 +12,53 @@ func testConfig() map[string]interface{} {
return map[string]interface{}{} return map[string]interface{}{}
} }
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),
}
}
func TestPostProcessor_ImplementsPostProcessor(t *testing.T) { func TestPostProcessor_ImplementsPostProcessor(t *testing.T) {
var _ packer.PostProcessor = new(PostProcessor) var _ packer.PostProcessor = new(PostProcessor)
} }
func TestBuilderPrepare_OutputPath(t *testing.T) { 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) {
var p PostProcessor var p PostProcessor
// Default // Default
...@@ -32,6 +77,17 @@ func TestBuilderPrepare_OutputPath(t *testing.T) { ...@@ -32,6 +77,17 @@ func TestBuilderPrepare_OutputPath(t *testing.T) {
} }
} }
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)
}
}
func TestProviderForName(t *testing.T) { func TestProviderForName(t *testing.T) {
if v, ok := providerForName("virtualbox").(*VBoxProvider); !ok { if v, ok := providerForName("virtualbox").(*VBoxProvider); !ok {
t.Fatalf("bad: %#v", v) t.Fatalf("bad: %#v", v)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment