2015-05-23 18:08:50 -04:00
|
|
|
package packer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"io/ioutil"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCoreConfig(t *testing.T) *CoreConfig {
|
|
|
|
// Create some test components
|
|
|
|
components := ComponentFinder{
|
2019-12-17 05:25:56 -05:00
|
|
|
BuilderStore: MapOfBuilder{
|
|
|
|
"test": func() (Builder, error) { return &MockBuilder{}, nil },
|
2015-05-23 18:08:50 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return &CoreConfig{
|
|
|
|
Components: components,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCore(t *testing.T, c *CoreConfig) *Core {
|
|
|
|
core, err := NewCore(c)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return core
|
|
|
|
}
|
2015-05-25 20:58:59 -04:00
|
|
|
|
2015-05-26 12:28:59 -04:00
|
|
|
func TestUi(t *testing.T) Ui {
|
|
|
|
var buf bytes.Buffer
|
|
|
|
return &BasicUi{
|
|
|
|
Reader: &buf,
|
|
|
|
Writer: ioutil.Discard,
|
|
|
|
ErrorWriter: ioutil.Discard,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-25 20:58:59 -04:00
|
|
|
// TestBuilder sets the builder with the name n to the component finder
|
|
|
|
// and returns the mock.
|
|
|
|
func TestBuilder(t *testing.T, c *CoreConfig, n string) *MockBuilder {
|
|
|
|
var b MockBuilder
|
|
|
|
|
2019-12-17 05:25:56 -05:00
|
|
|
c.Components.BuilderStore = MapOfBuilder{
|
|
|
|
n: func() (Builder, error) { return &b, nil },
|
2015-05-25 20:58:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return &b
|
|
|
|
}
|
2015-05-26 12:14:29 -04:00
|
|
|
|
|
|
|
// TestProvisioner sets the prov. with the name n to the component finder
|
|
|
|
// and returns the mock.
|
|
|
|
func TestProvisioner(t *testing.T, c *CoreConfig, n string) *MockProvisioner {
|
|
|
|
var b MockProvisioner
|
|
|
|
|
2019-12-17 05:25:56 -05:00
|
|
|
c.Components.ProvisionerStore = MapOfProvisioner{
|
|
|
|
n: func() (Provisioner, error) { return &b, nil },
|
2015-05-26 12:14:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return &b
|
|
|
|
}
|
2015-05-26 12:28:59 -04:00
|
|
|
|
|
|
|
// TestPostProcessor sets the prov. with the name n to the component finder
|
|
|
|
// and returns the mock.
|
|
|
|
func TestPostProcessor(t *testing.T, c *CoreConfig, n string) *MockPostProcessor {
|
|
|
|
var b MockPostProcessor
|
|
|
|
|
2019-12-17 05:25:56 -05:00
|
|
|
c.Components.PostProcessorStore = MapOfPostProcessor{
|
|
|
|
n: func() (PostProcessor, error) { return &b, nil },
|
2015-05-26 12:28:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return &b
|
|
|
|
}
|