add tests for progress bar rpc calls
This commit is contained in:
parent
6d3e36e6ea
commit
f3c923c47d
|
@ -1,6 +1,7 @@
|
||||||
package rpc
|
package rpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -8,18 +9,23 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type testUi struct {
|
type testUi struct {
|
||||||
askCalled bool
|
askCalled bool
|
||||||
askQuery string
|
askQuery string
|
||||||
errorCalled bool
|
errorCalled bool
|
||||||
errorMessage string
|
errorMessage string
|
||||||
machineCalled bool
|
machineCalled bool
|
||||||
machineType string
|
machineType string
|
||||||
machineArgs []string
|
machineArgs []string
|
||||||
messageCalled bool
|
messageCalled bool
|
||||||
messageMessage string
|
messageMessage string
|
||||||
sayCalled bool
|
sayCalled bool
|
||||||
sayMessage string
|
sayMessage string
|
||||||
progressBarCalled bool
|
|
||||||
|
progressBarCalled bool
|
||||||
|
progressBarStartCalled bool
|
||||||
|
progressBarAddCalled bool
|
||||||
|
progressBarFinishCalled bool
|
||||||
|
progressBarNewProxyReaderCalled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *testUi) Ask(query string) (string, error) {
|
func (u *testUi) Ask(query string) (string, error) {
|
||||||
|
@ -51,7 +57,24 @@ func (u *testUi) Say(message string) {
|
||||||
|
|
||||||
func (u *testUi) ProgressBar() packer.ProgressBar {
|
func (u *testUi) ProgressBar() packer.ProgressBar {
|
||||||
u.progressBarCalled = true
|
u.progressBarCalled = true
|
||||||
return new(packer.NoopProgressBar)
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *testUi) Start(uint64) {
|
||||||
|
u.progressBarStartCalled = true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *testUi) Add(uint64) {
|
||||||
|
u.progressBarAddCalled = true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *testUi) Finish() {
|
||||||
|
u.progressBarFinishCalled = true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *testUi) NewProxyReader(r io.Reader) io.Reader {
|
||||||
|
u.progressBarNewProxyReaderCalled = true
|
||||||
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUiRPC(t *testing.T) {
|
func TestUiRPC(t *testing.T) {
|
||||||
|
@ -95,9 +118,25 @@ func TestUiRPC(t *testing.T) {
|
||||||
if ui.sayMessage != "message" {
|
if ui.sayMessage != "message" {
|
||||||
t.Fatalf("bad: %#v", ui.errorMessage)
|
t.Fatalf("bad: %#v", ui.errorMessage)
|
||||||
}
|
}
|
||||||
uiClient.ProgressBar()
|
|
||||||
|
bar := uiClient.ProgressBar()
|
||||||
if ui.progressBarCalled != true {
|
if ui.progressBarCalled != true {
|
||||||
t.Fatalf("ProgressBar not called.")
|
t.Errorf("ProgressBar not called.")
|
||||||
|
}
|
||||||
|
|
||||||
|
bar.Start(100)
|
||||||
|
if ui.progressBarStartCalled != true {
|
||||||
|
t.Errorf("progressBar.Start not called.")
|
||||||
|
}
|
||||||
|
|
||||||
|
bar.Add(1)
|
||||||
|
if ui.progressBarAddCalled != true {
|
||||||
|
t.Errorf("progressBar.Add not called.")
|
||||||
|
}
|
||||||
|
|
||||||
|
bar.Finish()
|
||||||
|
if ui.progressBarFinishCalled != true {
|
||||||
|
t.Errorf("progressBar.Finish not called.")
|
||||||
}
|
}
|
||||||
|
|
||||||
uiClient.Machine("foo", "bar", "baz")
|
uiClient.Machine("foo", "bar", "baz")
|
||||||
|
|
Loading…
Reference in New Issue