diff --git a/builder/azure/chroot/packerui_test.go b/builder/azure/chroot/packerui_test.go new file mode 100644 index 000000000..af7b250ec --- /dev/null +++ b/builder/azure/chroot/packerui_test.go @@ -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 +} diff --git a/builder/azure/chroot/step_verify_source_disk_test.go b/builder/azure/chroot/step_verify_source_disk_test.go index 8d2191ac0..0609176a0 100644 --- a/builder/azure/chroot/step_verify_source_disk_test.go +++ b/builder/azure/chroot/step_verify_source_disk_test.go @@ -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) } }