packer: Core.Build
This commit is contained in:
parent
ded13a8b10
commit
d74dacc4c0
|
@ -47,6 +47,35 @@ func NewCore(c *CoreConfig) (*Core, error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
// Build returns the Build object for the given name.
|
||||
func (c *Core) Build(n string) (Build, error) {
|
||||
// Setup the builder
|
||||
configBuilder, ok := c.template.Builders[n]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("no such build found: %s", n)
|
||||
}
|
||||
builder, err := c.components.Builder(configBuilder.Type)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(
|
||||
"error initializing builder '%s': %s",
|
||||
configBuilder.Type, err)
|
||||
}
|
||||
if builder == nil {
|
||||
return nil, fmt.Errorf(
|
||||
"builder type not found: %s", configBuilder.Type)
|
||||
}
|
||||
|
||||
// TODO: template process name
|
||||
|
||||
return &coreBuild{
|
||||
name: n,
|
||||
builder: builder,
|
||||
builderConfig: configBuilder.Config,
|
||||
builderType: configBuilder.Type,
|
||||
variables: c.variables,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Validate does a full validation of the template.
|
||||
//
|
||||
// This will automatically call template.Validate() in addition to doing
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package packer
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCoreConfig(t *testing.T) *CoreConfig {
|
||||
// Create a UI that is effectively /dev/null everywhere
|
||||
var buf bytes.Buffer
|
||||
ui := &BasicUi{
|
||||
Reader: &buf,
|
||||
Writer: ioutil.Discard,
|
||||
ErrorWriter: ioutil.Discard,
|
||||
}
|
||||
|
||||
// Create some test components
|
||||
components := ComponentFinder{
|
||||
Builder: func(n string) (Builder, error) {
|
||||
if n != "test" {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return &MockBuilder{}, nil
|
||||
},
|
||||
}
|
||||
|
||||
return &CoreConfig{
|
||||
Cache: &FileCache{CacheDir: os.TempDir()},
|
||||
Components: components,
|
||||
Ui: ui,
|
||||
}
|
||||
}
|
||||
|
||||
func TestCore(t *testing.T, c *CoreConfig) *Core {
|
||||
core, err := NewCore(c)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
return core
|
||||
}
|
Loading…
Reference in New Issue