2013-03-24 17:31:18 -04:00
|
|
|
package packer
|
|
|
|
|
2013-03-24 17:47:59 -04:00
|
|
|
import (
|
2013-04-15 23:26:38 -04:00
|
|
|
"bytes"
|
2013-05-07 23:47:56 -04:00
|
|
|
"errors"
|
2013-06-19 02:18:21 -04:00
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
2013-03-24 17:47:59 -04:00
|
|
|
"os"
|
2013-10-17 03:09:27 -04:00
|
|
|
"reflect"
|
2013-04-20 20:30:09 -04:00
|
|
|
"strings"
|
2013-03-24 17:47:59 -04:00
|
|
|
"testing"
|
|
|
|
)
|
2013-03-24 17:31:18 -04:00
|
|
|
|
2013-06-19 02:18:21 -04:00
|
|
|
func init() {
|
|
|
|
// Disable log output for tests
|
|
|
|
log.SetOutput(ioutil.Discard)
|
|
|
|
}
|
|
|
|
|
2013-08-15 15:45:34 -04:00
|
|
|
func testComponentFinder() *ComponentFinder {
|
2013-11-02 23:31:12 -04:00
|
|
|
builderFactory := func(n string) (Builder, error) { return new(MockBuilder), nil }
|
2013-08-15 15:45:34 -04:00
|
|
|
ppFactory := func(n string) (PostProcessor, error) { return new(TestPostProcessor), nil }
|
2013-08-31 02:21:15 -04:00
|
|
|
provFactory := func(n string) (Provisioner, error) { return new(MockProvisioner), nil }
|
2013-08-15 15:45:34 -04:00
|
|
|
return &ComponentFinder{
|
|
|
|
Builder: builderFactory,
|
|
|
|
PostProcessor: ppFactory,
|
|
|
|
Provisioner: provFactory,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-02 17:03:55 -04:00
|
|
|
func testEnvironment() Environment {
|
2013-05-05 17:47:17 -04:00
|
|
|
config := DefaultEnvironmentConfig()
|
2013-08-11 21:20:27 -04:00
|
|
|
config.Ui = &BasicUi{
|
2013-06-14 18:17:03 -04:00
|
|
|
Reader: new(bytes.Buffer),
|
|
|
|
Writer: new(bytes.Buffer),
|
2013-04-15 23:26:38 -04:00
|
|
|
}
|
|
|
|
|
2013-04-20 21:00:03 -04:00
|
|
|
env, err := NewEnvironment(config)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return env
|
|
|
|
}
|
|
|
|
|
2013-05-05 17:47:17 -04:00
|
|
|
func TestEnvironment_DefaultConfig_Commands(t *testing.T) {
|
2013-04-21 22:04:35 -04:00
|
|
|
config := DefaultEnvironmentConfig()
|
2013-10-17 03:09:27 -04:00
|
|
|
if len(config.Commands) != 0 {
|
|
|
|
t.Fatalf("bad: %#v", config.Commands)
|
|
|
|
}
|
2013-04-21 22:04:35 -04:00
|
|
|
}
|
|
|
|
|
2013-04-20 21:00:03 -04:00
|
|
|
func TestEnvironment_DefaultConfig_Ui(t *testing.T) {
|
|
|
|
config := DefaultEnvironmentConfig()
|
2013-10-17 03:09:27 -04:00
|
|
|
if config.Ui == nil {
|
|
|
|
t.Fatal("config.Ui should not be nil")
|
|
|
|
}
|
2013-04-20 21:00:03 -04:00
|
|
|
|
2013-08-11 21:20:27 -04:00
|
|
|
rwUi, ok := config.Ui.(*BasicUi)
|
2013-10-17 03:09:27 -04:00
|
|
|
if !ok {
|
|
|
|
t.Fatal("default UI should be BasicUi")
|
|
|
|
}
|
|
|
|
if rwUi.Writer != os.Stdout {
|
|
|
|
t.Fatal("default UI should go to stdout")
|
|
|
|
}
|
|
|
|
if rwUi.Reader != os.Stdin {
|
|
|
|
t.Fatal("default UI reader should go to stdin")
|
|
|
|
}
|
2013-04-20 21:00:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewEnvironment_NoConfig(t *testing.T) {
|
|
|
|
env, err := NewEnvironment(nil)
|
2013-10-17 03:09:27 -04:00
|
|
|
if env != nil {
|
|
|
|
t.Fatal("env should be nil")
|
|
|
|
}
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("should have error")
|
|
|
|
}
|
2013-04-15 18:03:41 -04:00
|
|
|
}
|
|
|
|
|
2013-05-11 02:15:13 -04:00
|
|
|
func TestEnvironment_NilComponents(t *testing.T) {
|
|
|
|
config := DefaultEnvironmentConfig()
|
|
|
|
config.Components = *new(ComponentFinder)
|
|
|
|
|
|
|
|
env, err := NewEnvironment(config)
|
2013-10-17 03:09:27 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
2013-05-11 02:15:13 -04:00
|
|
|
|
|
|
|
// All of these should not cause panics... so we don't assert
|
|
|
|
// anything but if there is a panic in the test then yeah, something
|
|
|
|
// went wrong.
|
|
|
|
env.Builder("foo")
|
|
|
|
env.Cli([]string{"foo"})
|
|
|
|
env.Hook("foo")
|
2013-06-18 12:49:05 -04:00
|
|
|
env.PostProcessor("foo")
|
2013-05-22 18:39:30 -04:00
|
|
|
env.Provisioner("foo")
|
2013-05-11 02:15:13 -04:00
|
|
|
}
|
|
|
|
|
2013-05-05 18:12:55 -04:00
|
|
|
func TestEnvironment_Builder(t *testing.T) {
|
2013-11-02 23:31:12 -04:00
|
|
|
builder := &MockBuilder{}
|
2013-05-05 18:12:55 -04:00
|
|
|
builders := make(map[string]Builder)
|
|
|
|
builders["foo"] = builder
|
|
|
|
|
|
|
|
config := DefaultEnvironmentConfig()
|
2013-05-11 02:15:13 -04:00
|
|
|
config.Components.Builder = func(n string) (Builder, error) { return builders[n], nil }
|
2013-05-05 18:12:55 -04:00
|
|
|
|
|
|
|
env, _ := NewEnvironment(config)
|
2013-05-07 23:42:49 -04:00
|
|
|
returnedBuilder, err := env.Builder("foo")
|
2013-10-17 03:09:27 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
if returnedBuilder != builder {
|
|
|
|
t.Fatalf("bad: %#v", returnedBuilder)
|
|
|
|
}
|
2013-05-05 18:12:55 -04:00
|
|
|
}
|
|
|
|
|
2013-05-07 23:47:56 -04:00
|
|
|
func TestEnvironment_Builder_NilError(t *testing.T) {
|
|
|
|
config := DefaultEnvironmentConfig()
|
2013-05-11 02:15:13 -04:00
|
|
|
config.Components.Builder = func(n string) (Builder, error) { return nil, nil }
|
2013-05-07 23:47:56 -04:00
|
|
|
|
|
|
|
env, _ := NewEnvironment(config)
|
|
|
|
returnedBuilder, err := env.Builder("foo")
|
2013-10-17 03:09:27 -04:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("should have error")
|
|
|
|
}
|
|
|
|
if returnedBuilder != nil {
|
|
|
|
t.Fatalf("bad: %#v", returnedBuilder)
|
|
|
|
}
|
2013-05-07 23:47:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestEnvironment_Builder_Error(t *testing.T) {
|
|
|
|
config := DefaultEnvironmentConfig()
|
2013-05-11 02:15:13 -04:00
|
|
|
config.Components.Builder = func(n string) (Builder, error) { return nil, errors.New("foo") }
|
2013-05-07 23:47:56 -04:00
|
|
|
|
|
|
|
env, _ := NewEnvironment(config)
|
|
|
|
returnedBuilder, err := env.Builder("foo")
|
2013-10-17 03:09:27 -04:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("should have error")
|
|
|
|
}
|
|
|
|
if err.Error() != "foo" {
|
|
|
|
t.Fatalf("bad err: %s", err)
|
|
|
|
}
|
|
|
|
if returnedBuilder != nil {
|
|
|
|
t.Fatalf("should be nil: %#v", returnedBuilder)
|
|
|
|
}
|
2013-05-07 23:47:56 -04:00
|
|
|
}
|
|
|
|
|
2013-06-10 00:18:06 -04:00
|
|
|
func TestEnvironment_Cache(t *testing.T) {
|
|
|
|
config := DefaultEnvironmentConfig()
|
|
|
|
env, _ := NewEnvironment(config)
|
|
|
|
if env.Cache() == nil {
|
|
|
|
t.Fatal("cache should not be nil")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-07 23:50:22 -04:00
|
|
|
func TestEnvironment_Cli_Error(t *testing.T) {
|
|
|
|
config := DefaultEnvironmentConfig()
|
2013-05-11 02:15:13 -04:00
|
|
|
config.Components.Command = func(n string) (Command, error) { return nil, errors.New("foo") }
|
2013-05-07 23:50:22 -04:00
|
|
|
|
|
|
|
env, _ := NewEnvironment(config)
|
|
|
|
_, err := env.Cli([]string{"foo"})
|
2013-10-17 03:09:27 -04:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("should have error")
|
|
|
|
}
|
|
|
|
if err.Error() != "foo" {
|
|
|
|
t.Fatalf("bad: %s", err)
|
|
|
|
}
|
2013-05-07 23:50:22 -04:00
|
|
|
}
|
|
|
|
|
2013-04-15 18:03:41 -04:00
|
|
|
func TestEnvironment_Cli_CallsRun(t *testing.T) {
|
2013-04-20 20:17:53 -04:00
|
|
|
command := &TestCommand{}
|
2013-05-05 17:47:17 -04:00
|
|
|
commands := make(map[string]Command)
|
|
|
|
commands["foo"] = command
|
2013-04-20 20:17:53 -04:00
|
|
|
|
|
|
|
config := &EnvironmentConfig{}
|
2013-05-05 17:47:17 -04:00
|
|
|
config.Commands = []string{"foo"}
|
2013-05-11 02:15:13 -04:00
|
|
|
config.Components.Command = func(n string) (Command, error) { return commands[n], nil }
|
2013-04-15 18:03:41 -04:00
|
|
|
|
2013-04-20 21:00:03 -04:00
|
|
|
env, _ := NewEnvironment(config)
|
2013-05-07 23:42:49 -04:00
|
|
|
exitCode, err := env.Cli([]string{"foo", "bar", "baz"})
|
2013-10-17 03:09:27 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
if exitCode != 0 {
|
|
|
|
t.Fatalf("bad: %d", exitCode)
|
|
|
|
}
|
|
|
|
if !command.runCalled {
|
|
|
|
t.Fatal("command should be run")
|
|
|
|
}
|
|
|
|
if command.runEnv != env {
|
|
|
|
t.Fatalf("bad env: %#v", command.runEnv)
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(command.runArgs, []string{"bar", "baz"}) {
|
|
|
|
t.Fatalf("bad: %#v", command.runArgs)
|
|
|
|
}
|
2013-04-15 18:03:41 -04:00
|
|
|
}
|
|
|
|
|
2013-03-24 17:47:59 -04:00
|
|
|
func TestEnvironment_DefaultCli_Empty(t *testing.T) {
|
2013-04-15 23:26:38 -04:00
|
|
|
defaultEnv := testEnvironment()
|
2013-03-24 17:47:59 -04:00
|
|
|
|
2013-05-07 23:42:49 -04:00
|
|
|
exitCode, _ := defaultEnv.Cli([]string{})
|
2013-10-17 03:09:27 -04:00
|
|
|
if exitCode != 1 {
|
|
|
|
t.Fatalf("bad: %d", exitCode)
|
|
|
|
}
|
2013-03-24 17:47:59 -04:00
|
|
|
}
|
|
|
|
|
2013-03-24 19:35:33 -04:00
|
|
|
func TestEnvironment_DefaultCli_Help(t *testing.T) {
|
2013-04-15 23:26:38 -04:00
|
|
|
defaultEnv := testEnvironment()
|
2013-03-24 19:35:33 -04:00
|
|
|
|
2013-04-20 20:30:09 -04:00
|
|
|
// A little lambda to help us test the output actually contains help
|
|
|
|
testOutput := func() {
|
2013-08-11 21:20:27 -04:00
|
|
|
buffer := defaultEnv.Ui().(*BasicUi).Writer.(*bytes.Buffer)
|
2013-04-20 20:30:09 -04:00
|
|
|
output := buffer.String()
|
|
|
|
buffer.Reset()
|
2013-10-17 03:09:27 -04:00
|
|
|
if !strings.Contains(output, "usage: packer") {
|
|
|
|
t.Fatalf("should contain help: %#v", output)
|
|
|
|
}
|
2013-04-20 20:30:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test "--help"
|
2013-05-07 23:42:49 -04:00
|
|
|
exitCode, _ := defaultEnv.Cli([]string{"--help"})
|
2013-10-17 03:09:27 -04:00
|
|
|
if exitCode != 1 {
|
|
|
|
t.Fatalf("bad: %d", exitCode)
|
|
|
|
}
|
2013-04-20 20:30:09 -04:00
|
|
|
testOutput()
|
|
|
|
|
|
|
|
// Test "-h"
|
2013-05-07 23:42:49 -04:00
|
|
|
exitCode, _ = defaultEnv.Cli([]string{"--help"})
|
2013-10-17 03:09:27 -04:00
|
|
|
if exitCode != 1 {
|
|
|
|
t.Fatalf("bad: %d", exitCode)
|
|
|
|
}
|
2013-04-20 20:30:09 -04:00
|
|
|
testOutput()
|
2013-03-24 19:35:33 -04:00
|
|
|
}
|
|
|
|
|
2013-03-24 17:47:59 -04:00
|
|
|
func TestEnvironment_DefaultCli_Version(t *testing.T) {
|
2013-04-15 23:26:38 -04:00
|
|
|
defaultEnv := testEnvironment()
|
2013-03-24 17:47:59 -04:00
|
|
|
|
2013-05-07 23:42:49 -04:00
|
|
|
versionCommands := []string{"version", "--version", "-v"}
|
|
|
|
for _, command := range versionCommands {
|
|
|
|
exitCode, _ := defaultEnv.Cli([]string{command})
|
2013-10-17 03:09:27 -04:00
|
|
|
if exitCode != 0 {
|
|
|
|
t.Fatalf("bad: %d", exitCode)
|
|
|
|
}
|
2013-03-24 17:47:59 -04:00
|
|
|
|
2013-05-07 23:42:49 -04:00
|
|
|
// Test the --version and -v can appear anywhere
|
|
|
|
exitCode, _ = defaultEnv.Cli([]string{"bad", command})
|
2013-03-24 17:47:59 -04:00
|
|
|
|
2013-05-07 23:42:49 -04:00
|
|
|
if command != "version" {
|
2013-10-17 03:09:27 -04:00
|
|
|
if exitCode != 0 {
|
|
|
|
t.Fatalf("bad: %d", exitCode)
|
|
|
|
}
|
2013-05-07 23:42:49 -04:00
|
|
|
} else {
|
2013-10-17 03:09:27 -04:00
|
|
|
if exitCode != 1 {
|
|
|
|
t.Fatalf("bad: %d", exitCode)
|
|
|
|
}
|
2013-05-07 23:42:49 -04:00
|
|
|
}
|
|
|
|
}
|
2013-03-24 17:47:59 -04:00
|
|
|
}
|
|
|
|
|
2013-05-11 02:15:13 -04:00
|
|
|
func TestEnvironment_Hook(t *testing.T) {
|
2013-08-30 20:03:55 -04:00
|
|
|
hook := &MockHook{}
|
2013-05-11 02:15:13 -04:00
|
|
|
hooks := make(map[string]Hook)
|
|
|
|
hooks["foo"] = hook
|
|
|
|
|
|
|
|
config := DefaultEnvironmentConfig()
|
|
|
|
config.Components.Hook = func(n string) (Hook, error) { return hooks[n], nil }
|
|
|
|
|
|
|
|
env, _ := NewEnvironment(config)
|
|
|
|
returned, err := env.Hook("foo")
|
2013-10-17 03:09:27 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
if returned != hook {
|
|
|
|
t.Fatalf("bad: %#v", returned)
|
|
|
|
}
|
2013-05-11 02:15:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestEnvironment_Hook_NilError(t *testing.T) {
|
|
|
|
config := DefaultEnvironmentConfig()
|
|
|
|
config.Components.Hook = func(n string) (Hook, error) { return nil, nil }
|
|
|
|
|
|
|
|
env, _ := NewEnvironment(config)
|
|
|
|
returned, err := env.Hook("foo")
|
2013-10-17 03:09:27 -04:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("should have error")
|
|
|
|
}
|
|
|
|
if returned != nil {
|
|
|
|
t.Fatalf("bad: %#v", returned)
|
|
|
|
}
|
2013-05-11 02:15:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestEnvironment_Hook_Error(t *testing.T) {
|
|
|
|
config := DefaultEnvironmentConfig()
|
|
|
|
config.Components.Hook = func(n string) (Hook, error) { return nil, errors.New("foo") }
|
|
|
|
|
|
|
|
env, _ := NewEnvironment(config)
|
|
|
|
returned, err := env.Hook("foo")
|
2013-10-17 03:09:27 -04:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("should have error")
|
|
|
|
}
|
|
|
|
if err.Error() != "foo" {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
if returned != nil {
|
|
|
|
t.Fatalf("bad: %#v", returned)
|
|
|
|
}
|
2013-05-11 02:15:13 -04:00
|
|
|
}
|
|
|
|
|
2013-06-18 12:49:05 -04:00
|
|
|
func TestEnvironment_PostProcessor(t *testing.T) {
|
|
|
|
pp := &TestPostProcessor{}
|
|
|
|
pps := make(map[string]PostProcessor)
|
|
|
|
pps["foo"] = pp
|
|
|
|
|
|
|
|
config := DefaultEnvironmentConfig()
|
|
|
|
config.Components.PostProcessor = func(n string) (PostProcessor, error) { return pps[n], nil }
|
|
|
|
|
|
|
|
env, _ := NewEnvironment(config)
|
|
|
|
returned, err := env.PostProcessor("foo")
|
2013-10-17 03:09:27 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
if returned != pp {
|
|
|
|
t.Fatalf("bad: %#v", returned)
|
|
|
|
}
|
2013-06-18 12:49:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestEnvironment_PostProcessor_NilError(t *testing.T) {
|
|
|
|
config := DefaultEnvironmentConfig()
|
|
|
|
config.Components.PostProcessor = func(n string) (PostProcessor, error) { return nil, nil }
|
|
|
|
|
|
|
|
env, _ := NewEnvironment(config)
|
|
|
|
returned, err := env.PostProcessor("foo")
|
2013-10-17 03:09:27 -04:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("should have error")
|
|
|
|
}
|
|
|
|
if returned != nil {
|
|
|
|
t.Fatalf("bad: %#v", returned)
|
|
|
|
}
|
2013-06-18 12:49:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestEnvironment_PostProcessor_Error(t *testing.T) {
|
|
|
|
config := DefaultEnvironmentConfig()
|
|
|
|
config.Components.PostProcessor = func(n string) (PostProcessor, error) { return nil, errors.New("foo") }
|
|
|
|
|
|
|
|
env, _ := NewEnvironment(config)
|
|
|
|
returned, err := env.PostProcessor("foo")
|
2013-10-17 03:09:27 -04:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("should be an error")
|
|
|
|
}
|
|
|
|
if err.Error() != "foo" {
|
|
|
|
t.Fatalf("bad err: %s", err)
|
|
|
|
}
|
|
|
|
if returned != nil {
|
|
|
|
t.Fatalf("bad: %#v", returned)
|
|
|
|
}
|
2013-06-18 12:49:05 -04:00
|
|
|
}
|
|
|
|
|
2013-05-22 18:39:30 -04:00
|
|
|
func TestEnvironmentProvisioner(t *testing.T) {
|
2013-08-31 02:21:15 -04:00
|
|
|
p := &MockProvisioner{}
|
2013-05-22 18:39:30 -04:00
|
|
|
ps := make(map[string]Provisioner)
|
|
|
|
ps["foo"] = p
|
|
|
|
|
|
|
|
config := DefaultEnvironmentConfig()
|
|
|
|
config.Components.Provisioner = func(n string) (Provisioner, error) { return ps[n], nil }
|
|
|
|
|
|
|
|
env, _ := NewEnvironment(config)
|
|
|
|
returned, err := env.Provisioner("foo")
|
2013-10-17 03:09:27 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
if returned != p {
|
|
|
|
t.Fatalf("bad: %#v", returned)
|
|
|
|
}
|
2013-05-22 18:39:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestEnvironmentProvisioner_NilError(t *testing.T) {
|
|
|
|
config := DefaultEnvironmentConfig()
|
|
|
|
config.Components.Provisioner = func(n string) (Provisioner, error) { return nil, nil }
|
|
|
|
|
|
|
|
env, _ := NewEnvironment(config)
|
|
|
|
returned, err := env.Provisioner("foo")
|
2013-10-17 03:09:27 -04:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("should have error")
|
|
|
|
}
|
|
|
|
if returned != nil {
|
|
|
|
t.Fatalf("bad: %#v", returned)
|
|
|
|
}
|
2013-05-22 18:39:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestEnvironmentProvisioner_Error(t *testing.T) {
|
|
|
|
config := DefaultEnvironmentConfig()
|
|
|
|
config.Components.Provisioner = func(n string) (Provisioner, error) {
|
|
|
|
return nil, errors.New("foo")
|
|
|
|
}
|
|
|
|
|
|
|
|
env, _ := NewEnvironment(config)
|
|
|
|
returned, err := env.Provisioner("foo")
|
2013-10-17 03:09:27 -04:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("should have error")
|
|
|
|
}
|
|
|
|
if err.Error() != "foo" {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
if returned != nil {
|
|
|
|
t.Fatalf("bad: %#v", returned)
|
|
|
|
}
|
2013-05-22 18:39:30 -04:00
|
|
|
}
|
|
|
|
|
2013-04-15 23:26:38 -04:00
|
|
|
func TestEnvironment_SettingUi(t *testing.T) {
|
2013-08-11 21:20:27 -04:00
|
|
|
ui := &BasicUi{
|
2013-06-14 18:17:03 -04:00
|
|
|
Reader: new(bytes.Buffer),
|
|
|
|
Writer: new(bytes.Buffer),
|
|
|
|
}
|
2013-04-15 23:26:38 -04:00
|
|
|
|
|
|
|
config := &EnvironmentConfig{}
|
2013-04-20 20:08:43 -04:00
|
|
|
config.Ui = ui
|
2013-04-15 23:26:38 -04:00
|
|
|
|
2013-04-20 21:00:03 -04:00
|
|
|
env, _ := NewEnvironment(config)
|
2013-04-15 23:26:38 -04:00
|
|
|
|
2013-10-17 03:09:27 -04:00
|
|
|
if env.Ui() != ui {
|
|
|
|
t.Fatalf("UI should be equal: %#v", env.Ui())
|
|
|
|
}
|
2013-03-24 19:28:35 -04:00
|
|
|
}
|