packer: Rename ReaderWriterUi to BasicUi

This commit is contained in:
Mitchell Hashimoto 2013-08-11 18:20:27 -07:00
parent fb6d2754da
commit 02edc7579b
6 changed files with 27 additions and 24 deletions

View File

@ -9,7 +9,7 @@ import (
func testEnvironment() packer.Environment {
config := packer.DefaultEnvironmentConfig()
config.Ui = &packer.ReaderWriterUi{
config.Ui = &packer.BasicUi{
Reader: new(bytes.Buffer),
Writer: new(bytes.Buffer),
}

View File

@ -47,7 +47,7 @@ func TestRemoteCmd_StartWithUi(t *testing.T) {
Stdout: rcOutput,
}
testUi := &ReaderWriterUi{
testUi := &BasicUi{
Reader: new(bytes.Buffer),
Writer: uiOutput,
}

View File

@ -73,7 +73,7 @@ type EnvironmentConfig struct {
func DefaultEnvironmentConfig() *EnvironmentConfig {
config := &EnvironmentConfig{}
config.Commands = make([]string, 0)
config.Ui = &ReaderWriterUi{
config.Ui = &BasicUi{
Reader: os.Stdin,
Writer: os.Stdout,
}

View File

@ -19,7 +19,7 @@ func init() {
func testEnvironment() Environment {
config := DefaultEnvironmentConfig()
config.Ui = &ReaderWriterUi{
config.Ui = &BasicUi{
Reader: new(bytes.Buffer),
Writer: new(bytes.Buffer),
}
@ -45,8 +45,8 @@ func TestEnvironment_DefaultConfig_Ui(t *testing.T) {
config := DefaultEnvironmentConfig()
assert.NotNil(config.Ui, "default UI should not be nil")
rwUi, ok := config.Ui.(*ReaderWriterUi)
assert.True(ok, "default UI should be ReaderWriterUi")
rwUi, ok := config.Ui.(*BasicUi)
assert.True(ok, "default UI should be BasicUi")
assert.Equal(rwUi.Writer, os.Stdout, "default UI should go to stdout")
assert.Equal(rwUi.Reader, os.Stdin, "default UI should read from stdin")
}
@ -175,7 +175,7 @@ func TestEnvironment_DefaultCli_Help(t *testing.T) {
// A little lambda to help us test the output actually contains help
testOutput := func() {
buffer := defaultEnv.Ui().(*ReaderWriterUi).Writer.(*bytes.Buffer)
buffer := defaultEnv.Ui().(*BasicUi).Writer.(*bytes.Buffer)
output := buffer.String()
buffer.Reset()
assert.True(strings.Contains(output, "usage: packer"), "should print help")
@ -341,7 +341,7 @@ func TestEnvironmentProvisioner_Error(t *testing.T) {
func TestEnvironment_SettingUi(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
ui := &ReaderWriterUi{
ui := &BasicUi{
Reader: new(bytes.Buffer),
Writer: new(bytes.Buffer),
}

View File

@ -51,9 +51,12 @@ type PrefixedUi struct {
Ui Ui
}
// The ReaderWriterUi is a UI that writes and reads from standard Go
// io.Reader and io.Writer.
type ReaderWriterUi struct {
// The BasicUI is a UI that reads and writes from a standard Go reader
// and writer. It is safe to be called from multiple goroutines. The
// 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
Writer io.Writer
l sync.Mutex
@ -144,7 +147,7 @@ func (u *PrefixedUi) prefixLines(prefix, message string) string {
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()
defer rw.l.Unlock()
@ -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()
defer rw.l.Unlock()
@ -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()
defer rw.l.Unlock()
@ -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()
defer rw.l.Unlock()
@ -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
}

View File

@ -6,8 +6,8 @@ import (
"testing"
)
func testUi() *ReaderWriterUi {
return &ReaderWriterUi{
func testUi() *BasicUi {
return &BasicUi{
Reader: new(bytes.Buffer),
Writer: new(bytes.Buffer),
}
@ -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{}
raw = &ReaderWriterUi{}
raw = &BasicUi{}
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)
bufferUi := testUi()
@ -91,7 +91,7 @@ func TestReaderWriterUi_Error(t *testing.T) {
assert.Equal(readWriter(bufferUi), "5\n", "formatting")
}
func TestReaderWriterUi_Say(t *testing.T) {
func TestBasicUi_Say(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true)
bufferUi := testUi()
@ -105,7 +105,7 @@ func TestReaderWriterUi_Say(t *testing.T) {
// This reads the output from the bytes.Buffer in our test object
// and then resets the buffer.
func readWriter(ui *ReaderWriterUi) (result string) {
func readWriter(ui *BasicUi) (result string) {
buffer := ui.Writer.(*bytes.Buffer)
result = buffer.String()
buffer.Reset()