mirror of
https://github.com/hashicorp/packer.git
synced 2026-09-30 11:44:01 -04:00
post-processor/vagrant: the proper post-processor is actually run
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user