Commit 02edc757 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer: Rename ReaderWriterUi to BasicUi

parent fb6d2754
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
func testEnvironment() packer.Environment { func testEnvironment() packer.Environment {
config := packer.DefaultEnvironmentConfig() config := packer.DefaultEnvironmentConfig()
config.Ui = &packer.ReaderWriterUi{ config.Ui = &packer.BasicUi{
Reader: new(bytes.Buffer), Reader: new(bytes.Buffer),
Writer: new(bytes.Buffer), Writer: new(bytes.Buffer),
} }
......
...@@ -47,7 +47,7 @@ func TestRemoteCmd_StartWithUi(t *testing.T) { ...@@ -47,7 +47,7 @@ func TestRemoteCmd_StartWithUi(t *testing.T) {
Stdout: rcOutput, Stdout: rcOutput,
} }
testUi := &ReaderWriterUi{ testUi := &BasicUi{
Reader: new(bytes.Buffer), Reader: new(bytes.Buffer),
Writer: uiOutput, Writer: uiOutput,
} }
......
...@@ -73,7 +73,7 @@ type EnvironmentConfig struct { ...@@ -73,7 +73,7 @@ type EnvironmentConfig struct {
func DefaultEnvironmentConfig() *EnvironmentConfig { func DefaultEnvironmentConfig() *EnvironmentConfig {
config := &EnvironmentConfig{} config := &EnvironmentConfig{}
config.Commands = make([]string, 0) config.Commands = make([]string, 0)
config.Ui = &ReaderWriterUi{ config.Ui = &BasicUi{
Reader: os.Stdin, Reader: os.Stdin,
Writer: os.Stdout, Writer: os.Stdout,
} }
......
...@@ -19,7 +19,7 @@ func init() { ...@@ -19,7 +19,7 @@ func init() {
func testEnvironment() Environment { func testEnvironment() Environment {
config := DefaultEnvironmentConfig() config := DefaultEnvironmentConfig()
config.Ui = &ReaderWriterUi{ config.Ui = &BasicUi{
Reader: new(bytes.Buffer), Reader: new(bytes.Buffer),
Writer: new(bytes.Buffer), Writer: new(bytes.Buffer),
} }
...@@ -45,8 +45,8 @@ func TestEnvironment_DefaultConfig_Ui(t *testing.T) { ...@@ -45,8 +45,8 @@ func TestEnvironment_DefaultConfig_Ui(t *testing.T) {
config := DefaultEnvironmentConfig() config := DefaultEnvironmentConfig()
assert.NotNil(config.Ui, "default UI should not be nil") assert.NotNil(config.Ui, "default UI should not be nil")
rwUi, ok := config.Ui.(*ReaderWriterUi) rwUi, ok := config.Ui.(*BasicUi)
assert.True(ok, "default UI should be ReaderWriterUi") assert.True(ok, "default UI should be BasicUi")
assert.Equal(rwUi.Writer, os.Stdout, "default UI should go to stdout") assert.Equal(rwUi.Writer, os.Stdout, "default UI should go to stdout")
assert.Equal(rwUi.Reader, os.Stdin, "default UI should read from stdin") assert.Equal(rwUi.Reader, os.Stdin, "default UI should read from stdin")
} }
...@@ -175,7 +175,7 @@ func TestEnvironment_DefaultCli_Help(t *testing.T) { ...@@ -175,7 +175,7 @@ func TestEnvironment_DefaultCli_Help(t *testing.T) {
// A little lambda to help us test the output actually contains help // A little lambda to help us test the output actually contains help
testOutput := func() { testOutput := func() {
buffer := defaultEnv.Ui().(*ReaderWriterUi).Writer.(*bytes.Buffer) buffer := defaultEnv.Ui().(*BasicUi).Writer.(*bytes.Buffer)
output := buffer.String() output := buffer.String()
buffer.Reset() buffer.Reset()
assert.True(strings.Contains(output, "usage: packer"), "should print help") assert.True(strings.Contains(output, "usage: packer"), "should print help")
...@@ -341,7 +341,7 @@ func TestEnvironmentProvisioner_Error(t *testing.T) { ...@@ -341,7 +341,7 @@ func TestEnvironmentProvisioner_Error(t *testing.T) {
func TestEnvironment_SettingUi(t *testing.T) { func TestEnvironment_SettingUi(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true) assert := asserts.NewTestingAsserts(t, true)
ui := &ReaderWriterUi{ ui := &BasicUi{
Reader: new(bytes.Buffer), Reader: new(bytes.Buffer),
Writer: new(bytes.Buffer), Writer: new(bytes.Buffer),
} }
......
...@@ -51,9 +51,12 @@ type PrefixedUi struct { ...@@ -51,9 +51,12 @@ type PrefixedUi struct {
Ui Ui Ui Ui
} }
// The ReaderWriterUi is a UI that writes and reads from standard Go // The BasicUI is a UI that reads and writes from a standard Go reader
// io.Reader and io.Writer. // and writer. It is safe to be called from multiple goroutines. The
type ReaderWriterUi struct { // target for machine-readable output can be configured by prefixing the
// type of the machine readable output with the target and separating it
// with a comma.
type BasicUi struct {
Reader io.Reader Reader io.Reader
Writer io.Writer Writer io.Writer
l sync.Mutex l sync.Mutex
...@@ -144,7 +147,7 @@ func (u *PrefixedUi) prefixLines(prefix, message string) string { ...@@ -144,7 +147,7 @@ func (u *PrefixedUi) prefixLines(prefix, message string) string {
return strings.TrimRightFunc(result.String(), unicode.IsSpace) return strings.TrimRightFunc(result.String(), unicode.IsSpace)
} }
func (rw *ReaderWriterUi) Ask(query string) (string, error) { func (rw *BasicUi) Ask(query string) (string, error) {
rw.l.Lock() rw.l.Lock()
defer rw.l.Unlock() defer rw.l.Unlock()
...@@ -188,7 +191,7 @@ func (rw *ReaderWriterUi) Ask(query string) (string, error) { ...@@ -188,7 +191,7 @@ func (rw *ReaderWriterUi) Ask(query string) (string, error) {
} }
} }
func (rw *ReaderWriterUi) Say(message string) { func (rw *BasicUi) Say(message string) {
rw.l.Lock() rw.l.Lock()
defer rw.l.Unlock() defer rw.l.Unlock()
...@@ -199,7 +202,7 @@ func (rw *ReaderWriterUi) Say(message string) { ...@@ -199,7 +202,7 @@ func (rw *ReaderWriterUi) Say(message string) {
} }
} }
func (rw *ReaderWriterUi) Message(message string) { func (rw *BasicUi) Message(message string) {
rw.l.Lock() rw.l.Lock()
defer rw.l.Unlock() defer rw.l.Unlock()
...@@ -210,7 +213,7 @@ func (rw *ReaderWriterUi) Message(message string) { ...@@ -210,7 +213,7 @@ func (rw *ReaderWriterUi) Message(message string) {
} }
} }
func (rw *ReaderWriterUi) Error(message string) { func (rw *BasicUi) Error(message string) {
rw.l.Lock() rw.l.Lock()
defer rw.l.Unlock() defer rw.l.Unlock()
...@@ -221,6 +224,6 @@ func (rw *ReaderWriterUi) Error(message string) { ...@@ -221,6 +224,6 @@ func (rw *ReaderWriterUi) Error(message string) {
} }
} }
func (rw *ReaderWriterUi) Machine(t string, args ...string) { func (rw *BasicUi) Machine(t string, args ...string) {
// TODO // TODO
} }
...@@ -6,8 +6,8 @@ import ( ...@@ -6,8 +6,8 @@ import (
"testing" "testing"
) )
func testUi() *ReaderWriterUi { func testUi() *BasicUi {
return &ReaderWriterUi{ return &BasicUi{
Reader: new(bytes.Buffer), Reader: new(bytes.Buffer),
Writer: new(bytes.Buffer), Writer: new(bytes.Buffer),
} }
...@@ -71,15 +71,15 @@ func TestPrefixedUi_ImplUi(t *testing.T) { ...@@ -71,15 +71,15 @@ func TestPrefixedUi_ImplUi(t *testing.T) {
} }
} }
func TestReaderWriterUi_ImplUi(t *testing.T) { func TestBasicUi_ImplUi(t *testing.T) {
var raw interface{} var raw interface{}
raw = &ReaderWriterUi{} raw = &BasicUi{}
if _, ok := raw.(Ui); !ok { if _, ok := raw.(Ui); !ok {
t.Fatalf("ReaderWriterUi must implement Ui") t.Fatalf("BasicUi must implement Ui")
} }
} }
func TestReaderWriterUi_Error(t *testing.T) { func TestBasicUi_Error(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true) assert := asserts.NewTestingAsserts(t, true)
bufferUi := testUi() bufferUi := testUi()
...@@ -91,7 +91,7 @@ func TestReaderWriterUi_Error(t *testing.T) { ...@@ -91,7 +91,7 @@ func TestReaderWriterUi_Error(t *testing.T) {
assert.Equal(readWriter(bufferUi), "5\n", "formatting") assert.Equal(readWriter(bufferUi), "5\n", "formatting")
} }
func TestReaderWriterUi_Say(t *testing.T) { func TestBasicUi_Say(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true) assert := asserts.NewTestingAsserts(t, true)
bufferUi := testUi() bufferUi := testUi()
...@@ -105,7 +105,7 @@ func TestReaderWriterUi_Say(t *testing.T) { ...@@ -105,7 +105,7 @@ func TestReaderWriterUi_Say(t *testing.T) {
// This reads the output from the bytes.Buffer in our test object // This reads the output from the bytes.Buffer in our test object
// and then resets the buffer. // and then resets the buffer.
func readWriter(ui *ReaderWriterUi) (result string) { func readWriter(ui *BasicUi) (result string) {
buffer := ui.Writer.(*bytes.Buffer) buffer := ui.Writer.(*bytes.Buffer)
result = buffer.String() result = buffer.String()
buffer.Reset() buffer.Reset()
......
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