Add unit test to find issue #7655
This commit is contained in:
parent
07dbf8195e
commit
ec14ab4875
|
@ -3,6 +3,7 @@ package packer
|
|||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
@ -112,3 +113,19 @@ func (c *MockCommunicator) DownloadDir(src string, dst string, excl []string) er
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ScriptUploadErrorMockCommunicator returns an error from it's Upload() method
|
||||
// when a script is uploaded to test the case where this upload fails.
|
||||
type ScriptUploadErrorMockCommunicator struct {
|
||||
MockCommunicator
|
||||
}
|
||||
|
||||
var ScriptUploadErrorMockCommunicatorError = errors.New("ScriptUploadErrorMockCommunicator Upload error")
|
||||
|
||||
func (c *ScriptUploadErrorMockCommunicator) Upload(path string, r io.Reader, fi *os.FileInfo) error {
|
||||
// only fail on script uploads, not on environment variable uploads
|
||||
if !strings.Contains(path, "packer-ps-env-vars") {
|
||||
return ScriptUploadErrorMockCommunicatorError
|
||||
}
|
||||
return c.MockCommunicator.Upload(path, r, fi)
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
)
|
||||
|
@ -502,6 +503,22 @@ func TestProvisionerProvision_UISlurp(t *testing.T) {
|
|||
// UI should receive following messages / output
|
||||
}
|
||||
|
||||
func TestProvisionerProvision_UploadFails(t *testing.T) {
|
||||
config := testConfig()
|
||||
ui := testUi()
|
||||
|
||||
p := new(Provisioner)
|
||||
comm := new(packer.ScriptUploadErrorMockCommunicator)
|
||||
p.Prepare(config)
|
||||
p.config.StartRetryTimeout = time.Second
|
||||
err := p.Provision(context.Background(), ui, comm)
|
||||
if !strings.Contains(err.Error(), packer.ScriptUploadErrorMockCommunicatorError.Error()) {
|
||||
t.Fatalf("expected Provision() error %q to contain %q",
|
||||
err.Error(),
|
||||
packer.ScriptUploadErrorMockCommunicatorError.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestProvisioner_createFlattenedElevatedEnvVars_windows(t *testing.T) {
|
||||
var flattenedEnvVars string
|
||||
config := testConfig()
|
||||
|
|
Loading…
Reference in New Issue