Commit d74dacc4 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer: Core.Build

parent ded13a8b
......@@ -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
......
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
}
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