Commit c9748b8e authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

post-processor/vagrant: the proper post-processor is actually run

parent f4c9f960
......@@ -5,7 +5,7 @@ import (
"testing"
)
func TestPostProcessor_ImplementsPostProcessor(t *testing.T) {
func TestAWSBoxPostProcessor_ImplementsPostProcessor(t *testing.T) {
var raw interface{}
raw = &AWSBoxPostProcessor{}
if _, ok := raw.(packer.PostProcessor); !ok {
......
......@@ -4,6 +4,8 @@
package vagrant
import (
"fmt"
"github.com/mitchellh/mapstructure"
"github.com/mitchellh/packer/packer"
)
......@@ -11,16 +13,47 @@ var builtins = map[string]string{
"mitchellh.amazonebs": "aws",
}
type Config struct{}
type Config struct{
OutputPath string `mapstructure:"output"`
}
type PostProcessor struct {
config Config
}
func (p *PostProcessor) Configure(raw interface{}) error {
err := mapstructure.Decode(raw, &p.config)
if err != nil {
return err
}
if p.config.OutputPath == "" {
return fmt.Errorf("`output` must be specified.")
}
return nil
}
func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (packer.Artifact, error) {
return nil, nil
ppName, ok := builtins[artifact.BuilderId()]
if !ok {
return nil, fmt.Errorf("Unknown artifact type, can't build box: %s", artifact.BuilderId())
}
// Get the actual PostProcessor implementation for this type
var pp packer.PostProcessor
switch ppName {
case "aws":
pp = new(AWSBoxPostProcessor)
default:
return nil, fmt.Errorf("Vagrant box post-processor not found: %s", ppName)
}
// Prepare and run the post-processor
config := map[string]string{"output": p.config.OutputPath}
if err := pp.Configure(config); err != nil {
return nil, err
}
return pp.PostProcess(ui, artifact)
}
package vagrant
import (
"github.com/mitchellh/packer/packer"
"testing"
)
func testConfig() map[string]interface{} {
return map[string]interface{}{}
}
func TestPostProcessor_ImplementsPostProcessor(t *testing.T) {
var raw interface{}
raw = &PostProcessor{}
if _, ok := raw.(packer.PostProcessor); !ok {
t.Fatalf("AWS PostProcessor should be a PostProcessor")
}
}
func TestBuilderPrepare_OutputPath(t *testing.T) {
var p PostProcessor
c := testConfig()
delete(c, "output")
err := p.Configure(c)
if err == nil {
t.Fatalf("configure should fail")
}
}
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