packer/rpc/ui_test.go: test progress bar too

This commit is contained in:
Adrien Delorme 2018-09-06 15:52:46 +02:00
parent 5b66069da0
commit 42561cf777
1 changed files with 23 additions and 11 deletions

View File

@ -3,20 +3,23 @@ package rpc
import (
"reflect"
"testing"
"github.com/hashicorp/packer/packer"
)
type testUi struct {
askCalled bool
askQuery string
errorCalled bool
errorMessage string
machineCalled bool
machineType string
machineArgs []string
messageCalled bool
messageMessage string
sayCalled bool
sayMessage string
askCalled bool
askQuery string
errorCalled bool
errorMessage string
machineCalled bool
machineType string
machineArgs []string
messageCalled bool
messageMessage string
sayCalled bool
sayMessage string
progressBarCalled bool
}
func (u *testUi) Ask(query string) (string, error) {
@ -46,6 +49,11 @@ func (u *testUi) Say(message string) {
u.sayMessage = message
}
func (u *testUi) ProgressBar() packer.ProgressBar {
u.progressBarCalled = true
return new(packer.NoopProgressBar)
}
func TestUiRPC(t *testing.T) {
// Create the UI to test
ui := new(testUi)
@ -87,6 +95,10 @@ func TestUiRPC(t *testing.T) {
if ui.sayMessage != "message" {
t.Fatalf("bad: %#v", ui.errorMessage)
}
uiClient.ProgressBar()
if ui.progressBarCalled != true {
t.Fatalf("ProgressBar not called.")
}
uiClient.Machine("foo", "bar", "baz")
if !ui.machineCalled {