Extract testUI func
This commit is contained in:
parent
9ed6fab8c4
commit
b3e361a139
|
@ -0,0 +1,19 @@
|
|||
package chroot
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
)
|
||||
|
||||
// testUI returns a test ui plus a function to retrieve the errors written to the ui
|
||||
func testUI() (packer.Ui, func() string) {
|
||||
errorBuffer := &strings.Builder{}
|
||||
ui := &packer.BasicUi{
|
||||
Reader: strings.NewReader(""),
|
||||
Writer: ioutil.Discard,
|
||||
ErrorWriter: errorBuffer,
|
||||
}
|
||||
return ui, errorBuffer.String
|
||||
}
|
|
@ -129,12 +129,7 @@ func Test_StepVerifySourceDisk_Run(t *testing.T) {
|
|||
}, nil
|
||||
})
|
||||
|
||||
errorBuffer := &strings.Builder{}
|
||||
ui := &packer.BasicUi{
|
||||
Reader: strings.NewReader(""),
|
||||
Writer: ioutil.Discard,
|
||||
ErrorWriter: errorBuffer,
|
||||
}
|
||||
ui, getErr := testUI()
|
||||
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("azureclient", &client.AzureClientSetMock{
|
||||
|
@ -148,8 +143,9 @@ func Test_StepVerifySourceDisk_Run(t *testing.T) {
|
|||
}
|
||||
|
||||
if tt.errormatch != "" {
|
||||
if !regexp.MustCompile(tt.errormatch).MatchString(errorBuffer.String()) {
|
||||
t.Errorf("Expected the error output (%q) to match %q", errorBuffer.String(), tt.errormatch)
|
||||
errs := getErr()
|
||||
if !regexp.MustCompile(tt.errormatch).MatchString(errs) {
|
||||
t.Errorf("Expected the error output (%q) to match %q", errs, tt.errormatch)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue