fix tests by moving mock hooks and communicators, and BasicUi definition, into SDK
This commit is contained in:
parent
f81ed344a2
commit
d5971ca25e
|
@ -11,8 +11,8 @@ import (
|
|||
"github.com/aws/aws-sdk-go/aws/request"
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"github.com/aws/aws-sdk-go/service/ec2/ec2iface"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/template/config"
|
||||
)
|
||||
|
||||
|
@ -87,7 +87,7 @@ func getMockConn(config *AccessConfig, target string) (ec2iface.EC2API, error) {
|
|||
// Create statebag for running test
|
||||
func tState() multistep.StateBag {
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("ui", &packer.BasicUi{
|
||||
state.Put("ui", &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
})
|
||||
|
|
|
@ -12,12 +12,13 @@ import (
|
|||
"github.com/hashicorp/packer/helper/communicator"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
// Create statebag for running test
|
||||
func tStateSpot() multistep.StateBag {
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("ui", &packer.BasicUi{
|
||||
state.Put("ui", &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
})
|
||||
|
|
|
@ -7,13 +7,13 @@ import (
|
|||
|
||||
azcommon "github.com/hashicorp/packer/builder/azure/common"
|
||||
"github.com/hashicorp/packer/builder/azure/common/constants"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func TestNewStepCertificateInKeyVault(t *testing.T) {
|
||||
cli := azcommon.MockAZVaultClient{}
|
||||
ui := &packer.BasicUi{
|
||||
ui := &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ func TestNewStepCertificateInKeyVault_error(t *testing.T) {
|
|||
cli := azcommon.MockAZVaultClient{}
|
||||
cli.IsError = true
|
||||
|
||||
ui := &packer.BasicUi{
|
||||
ui := &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
}
|
||||
|
|
|
@ -4,14 +4,13 @@ import (
|
|||
"io/ioutil"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
// testUI returns a test ui plus a function to retrieve the errors written to the ui
|
||||
func testUI() (packersdk.Ui, func() string) {
|
||||
errorBuffer := &strings.Builder{}
|
||||
ui := &packer.BasicUi{
|
||||
ui := &packersdk.BasicUi{
|
||||
Reader: strings.NewReader(""),
|
||||
Writer: ioutil.Discard,
|
||||
ErrorWriter: errorBuffer,
|
||||
|
|
|
@ -12,8 +12,8 @@ import (
|
|||
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-12-01/compute"
|
||||
"github.com/Azure/go-autorest/autorest"
|
||||
"github.com/hashicorp/packer/builder/azure/common/client"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func TestStepAttachDisk_Run(t *testing.T) {
|
||||
|
@ -69,7 +69,7 @@ func TestStepAttachDisk_Run(t *testing.T) {
|
|||
})
|
||||
|
||||
errorBuffer := &strings.Builder{}
|
||||
ui := &packer.BasicUi{
|
||||
ui := &packersdk.BasicUi{
|
||||
Reader: strings.NewReader(""),
|
||||
Writer: ioutil.Discard,
|
||||
ErrorWriter: errorBuffer,
|
||||
|
|
|
@ -64,13 +64,13 @@ func TestUploadDownload(t *testing.T) {
|
|||
hooks := map[string][]packersdk.Hook{}
|
||||
hooks[packersdk.HookProvision] = []packersdk.Hook{
|
||||
&packer.ProvisionHook{
|
||||
Provisioners: []*packersdk.HookedProvisioner{
|
||||
Provisioners: []*packer.HookedProvisioner{
|
||||
{Provisioner: upload, Config: nil, TypeName: ""},
|
||||
{Provisioner: download, Config: nil, TypeName: ""},
|
||||
},
|
||||
},
|
||||
}
|
||||
hook := &packer.DispatchHook{Mapping: hooks}
|
||||
hook := &packersdk.DispatchHook{Mapping: hooks}
|
||||
|
||||
// Run things
|
||||
artifact, err := builder.Run(context.Background(), ui, hook)
|
||||
|
@ -152,14 +152,14 @@ func TestLargeDownload(t *testing.T) {
|
|||
hooks := map[string][]packersdk.Hook{}
|
||||
hooks[packersdk.HookProvision] = []packersdk.Hook{
|
||||
&packer.ProvisionHook{
|
||||
Provisioners: []*packersdk.HookedProvisioner{
|
||||
Provisioners: []*packer.HookedProvisioner{
|
||||
{Provisioner: shell, Config: nil, TypeName: ""},
|
||||
{Provisioner: downloadCupcake, Config: nil, TypeName: ""},
|
||||
{Provisioner: downloadBigcake, Config: nil, TypeName: ""},
|
||||
},
|
||||
},
|
||||
}
|
||||
hook := &packer.DispatchHook{Mapping: hooks}
|
||||
hook := &packersdk.DispatchHook{Mapping: hooks}
|
||||
|
||||
// Run things
|
||||
artifact, err := builder.Run(context.Background(), ui, hook)
|
||||
|
@ -260,7 +260,7 @@ func TestFixUploadOwner(t *testing.T) {
|
|||
hooks := map[string][]packersdk.Hook{}
|
||||
hooks[packersdk.HookProvision] = []packersdk.Hook{
|
||||
&packer.ProvisionHook{
|
||||
Provisioners: []*packersdk.HookedProvisioner{
|
||||
Provisioners: []*packer.HookedProvisioner{
|
||||
{Provisioner: fileProvisioner, Config: nil, TypeName: ""},
|
||||
{Provisioner: dirProvisioner, Config: nil, TypeName: ""},
|
||||
{Provisioner: shellProvisioner, Config: nil, TypeName: ""},
|
||||
|
@ -268,7 +268,7 @@ func TestFixUploadOwner(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
hook := &packer.DispatchHook{Mapping: hooks}
|
||||
hook := &packersdk.DispatchHook{Mapping: hooks}
|
||||
|
||||
artifact, err := builder.Run(context.Background(), ui, hook)
|
||||
if err != nil {
|
||||
|
|
|
@ -4,16 +4,16 @@ import (
|
|||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func testState(t *testing.T) multistep.StateBag {
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("config", testConfigStruct(t))
|
||||
state.Put("driver", &MockDriver{})
|
||||
state.Put("hook", &packer.MockHook{})
|
||||
state.Put("ui", &packer.BasicUi{
|
||||
state.Put("hook", &packersdk.MockHook{})
|
||||
state.Put("ui", &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
})
|
||||
|
|
|
@ -4,16 +4,16 @@ import (
|
|||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func testState(t *testing.T) multistep.StateBag {
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("config", testConfigStruct(t))
|
||||
state.Put("driver", &DriverMock{})
|
||||
state.Put("hook", &packer.MockHook{})
|
||||
state.Put("ui", &packer.BasicUi{
|
||||
state.Put("hook", &packersdk.MockHook{})
|
||||
state.Put("ui", &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
})
|
||||
|
|
|
@ -6,15 +6,15 @@ import (
|
|||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/uuid"
|
||||
)
|
||||
|
||||
func testState(t *testing.T) multistep.StateBag {
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("driver", new(DriverMock))
|
||||
state.Put("ui", &packer.BasicUi{
|
||||
state.Put("ui", &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
})
|
||||
|
|
|
@ -603,7 +603,7 @@ func TestUserVariablesInBootCommand(t *testing.T) {
|
|||
}
|
||||
|
||||
ui := packer.TestUi(t)
|
||||
hook := &packer.MockHook{}
|
||||
hook := &packersdk.MockHook{}
|
||||
driver := &hypervcommon.DriverMock{}
|
||||
|
||||
// Set up the state.
|
||||
|
|
|
@ -495,7 +495,7 @@ func TestUserVariablesInBootCommand(t *testing.T) {
|
|||
}
|
||||
|
||||
ui := packer.TestUi(t)
|
||||
hook := &packer.MockHook{}
|
||||
hook := &packersdk.MockHook{}
|
||||
driver := &hypervcommon.DriverMock{}
|
||||
|
||||
// Set up the state.
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"os/exec"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
|
||||
|
@ -76,7 +76,7 @@ func TestBerToDer(t *testing.T) {
|
|||
}
|
||||
|
||||
msg := new(bytes.Buffer)
|
||||
ui := &packer.BasicUi{
|
||||
ui := &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: msg,
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@ import (
|
|||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func TestInstanceInfo(t *testing.T) {
|
||||
|
@ -37,8 +37,8 @@ func TestInstanceInfoPrivateIP(t *testing.T) {
|
|||
state := new(multistep.BasicStateBag)
|
||||
state.Put("config", baseTestConfig)
|
||||
state.Put("driver", &driverMock{cfg: baseTestConfig})
|
||||
state.Put("hook", &packer.MockHook{})
|
||||
state.Put("ui", &packer.BasicUi{
|
||||
state.Put("hook", &packersdk.MockHook{})
|
||||
state.Put("ui", &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
})
|
||||
|
|
|
@ -4,8 +4,8 @@ import (
|
|||
"bytes"
|
||||
"os"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
// TODO(apryde): It would be good not to have to write a key file to disk to
|
||||
|
@ -55,8 +55,8 @@ func testState() multistep.StateBag {
|
|||
state := new(multistep.BasicStateBag)
|
||||
state.Put("config", baseTestConfig)
|
||||
state.Put("driver", &driverMock{cfg: baseTestConfig})
|
||||
state.Put("hook", &packer.MockHook{})
|
||||
state.Put("ui", &packer.BasicUi{
|
||||
state.Put("hook", &packersdk.MockHook{})
|
||||
state.Put("ui", &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
})
|
||||
|
|
|
@ -5,8 +5,8 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func TestStepShutdown_impl(t *testing.T) {
|
||||
|
@ -17,7 +17,7 @@ func TestStepShutdown_noShutdownCommand(t *testing.T) {
|
|||
state := testState(t)
|
||||
step := new(StepShutdown)
|
||||
|
||||
comm := new(packer.MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
state.Put("communicator", comm)
|
||||
state.Put("vmName", "foo")
|
||||
|
||||
|
@ -46,7 +46,7 @@ func TestStepShutdown_shutdownCommand(t *testing.T) {
|
|||
step.Command = "poweroff"
|
||||
step.Timeout = 1 * time.Second
|
||||
|
||||
comm := new(packer.MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
state.Put("communicator", comm)
|
||||
state.Put("vmName", "foo")
|
||||
|
||||
|
@ -83,7 +83,7 @@ func TestStepShutdown_shutdownTimeout(t *testing.T) {
|
|||
step.Command = "poweroff"
|
||||
step.Timeout = 1 * time.Second
|
||||
|
||||
comm := new(packer.MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
state.Put("communicator", comm)
|
||||
state.Put("vmName", "foo")
|
||||
|
||||
|
|
|
@ -4,15 +4,15 @@ import (
|
|||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func testState(t *testing.T) multistep.StateBag {
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("debug", false)
|
||||
state.Put("driver", new(DriverMock))
|
||||
state.Put("ui", &packer.BasicUi{
|
||||
state.Put("ui", &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
})
|
||||
|
|
|
@ -4,8 +4,8 @@ import (
|
|||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func TestStepUploadParallelsTools_impl(t *testing.T) {
|
||||
|
@ -20,7 +20,7 @@ func TestStepUploadParallelsTools(t *testing.T) {
|
|||
step.ParallelsToolsGuestPath = "/tmp/prl-lin.iso"
|
||||
step.ParallelsToolsFlavor = "lin"
|
||||
|
||||
comm := new(packer.MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
state.Put("communicator", comm)
|
||||
|
||||
// Test the run
|
||||
|
@ -45,7 +45,7 @@ func TestStepUploadParallelsTools_interpolate(t *testing.T) {
|
|||
step.ParallelsToolsGuestPath = "/tmp/prl-{{ .Flavor }}.iso"
|
||||
step.ParallelsToolsFlavor = "win"
|
||||
|
||||
comm := new(packer.MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
state.Put("communicator", comm)
|
||||
|
||||
// Test the run
|
||||
|
@ -70,7 +70,7 @@ func TestStepUploadParallelsTools_attach(t *testing.T) {
|
|||
step.ParallelsToolsGuestPath = "/tmp/prl-lin.iso"
|
||||
step.ParallelsToolsFlavor = "lin"
|
||||
|
||||
comm := new(packer.MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
state.Put("communicator", comm)
|
||||
|
||||
// Test the run
|
||||
|
|
|
@ -4,8 +4,8 @@ import (
|
|||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func TestStepUploadVersion_impl(t *testing.T) {
|
||||
|
@ -17,7 +17,7 @@ func TestStepUploadVersion(t *testing.T) {
|
|||
step := new(StepUploadVersion)
|
||||
step.Path = "foopath"
|
||||
|
||||
comm := new(packer.MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
state.Put("communicator", comm)
|
||||
|
||||
driver := state.Get("driver").(*DriverMock)
|
||||
|
@ -45,7 +45,7 @@ func TestStepUploadVersion_noPath(t *testing.T) {
|
|||
step := new(StepUploadVersion)
|
||||
step.Path = ""
|
||||
|
||||
comm := new(packer.MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
state.Put("communicator", comm)
|
||||
|
||||
// Test the run
|
||||
|
|
|
@ -5,14 +5,14 @@ import (
|
|||
"testing"
|
||||
|
||||
parallelscommon "github.com/hashicorp/packer/builder/parallels/common"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func testState(t *testing.T) multistep.StateBag {
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("driver", new(parallelscommon.DriverMock))
|
||||
state.Put("ui", &packer.BasicUi{
|
||||
state.Put("ui", &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
})
|
||||
|
|
|
@ -5,13 +5,13 @@ import (
|
|||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func TestStepHTTPIPDiscover_Run(t *testing.T) {
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("ui", &packer.BasicUi{
|
||||
state.Put("ui", &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
})
|
||||
|
|
|
@ -4,14 +4,14 @@ import (
|
|||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func testState(t *testing.T) multistep.StateBag {
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("driver", new(DriverMock))
|
||||
state.Put("ui", &packer.BasicUi{
|
||||
state.Put("ui", &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
})
|
||||
|
|
|
@ -10,8 +10,8 @@ import (
|
|||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
"github.com/scaleway/scaleway-sdk-go/api/instance/v1"
|
||||
"github.com/scaleway/scaleway-sdk-go/scw"
|
||||
)
|
||||
|
@ -70,7 +70,7 @@ func setup(t *testing.T, fakeImgNames []string, fakeSnapNames []string) (*multis
|
|||
}
|
||||
|
||||
state := multistep.BasicStateBag{}
|
||||
state.Put("ui", &packer.BasicUi{
|
||||
state.Put("ui", &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
})
|
||||
|
|
|
@ -4,16 +4,16 @@ import (
|
|||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func testState(t *testing.T) multistep.StateBag {
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("config", testConfig(t))
|
||||
state.Put("driver", &DriverMock{})
|
||||
state.Put("hook", &packer.MockHook{})
|
||||
state.Put("ui", &packer.BasicUi{
|
||||
state.Put("hook", &packersdk.MockHook{})
|
||||
state.Put("ui", &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
})
|
||||
|
|
|
@ -5,8 +5,8 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func TestStepShutdown_impl(t *testing.T) {
|
||||
|
@ -19,7 +19,7 @@ func TestStepShutdown_noShutdownCommand(t *testing.T) {
|
|||
step.DisableShutdown = false
|
||||
step.ACPIShutdown = false
|
||||
|
||||
comm := new(packer.MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
state.Put("communicator", comm)
|
||||
state.Put("vmName", "foo")
|
||||
|
||||
|
@ -50,7 +50,7 @@ func TestStepShutdown_shutdownCommand(t *testing.T) {
|
|||
step.DisableShutdown = false
|
||||
step.ACPIShutdown = false
|
||||
|
||||
comm := new(packer.MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
state.Put("communicator", comm)
|
||||
state.Put("vmName", "foo")
|
||||
|
||||
|
@ -89,7 +89,7 @@ func TestStepShutdown_shutdownTimeout(t *testing.T) {
|
|||
step.DisableShutdown = false
|
||||
step.ACPIShutdown = false
|
||||
|
||||
comm := new(packer.MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
state.Put("communicator", comm)
|
||||
state.Put("vmName", "foo")
|
||||
|
||||
|
@ -119,7 +119,7 @@ func TestStepShutdown_DisableShutdown(t *testing.T) {
|
|||
step.ACPIShutdown = false
|
||||
step.Timeout = 2 * time.Second
|
||||
|
||||
comm := new(packer.MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
state.Put("communicator", comm)
|
||||
state.Put("vmName", "foo")
|
||||
|
||||
|
@ -148,7 +148,7 @@ func TestStepShutdown_ACPIShutdown(t *testing.T) {
|
|||
step.ACPIShutdown = true
|
||||
step.Timeout = 2 * time.Second
|
||||
|
||||
comm := new(packer.MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
state.Put("communicator", comm)
|
||||
state.Put("vmName", "foo")
|
||||
|
||||
|
|
|
@ -4,14 +4,14 @@ import (
|
|||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func testState(t *testing.T) multistep.StateBag {
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("driver", new(DriverMock))
|
||||
state.Put("ui", &packer.BasicUi{
|
||||
state.Put("ui", &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
})
|
||||
|
|
|
@ -4,8 +4,8 @@ import (
|
|||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func TestStepUploadVersion_impl(t *testing.T) {
|
||||
|
@ -17,7 +17,7 @@ func TestStepUploadVersion(t *testing.T) {
|
|||
step := new(StepUploadVersion)
|
||||
step.Path = "foopath"
|
||||
|
||||
comm := new(packer.MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
state.Put("communicator", comm)
|
||||
|
||||
driver := state.Get("driver").(*DriverMock)
|
||||
|
@ -45,7 +45,7 @@ func TestStepUploadVersion_noPath(t *testing.T) {
|
|||
step := new(StepUploadVersion)
|
||||
step.Path = ""
|
||||
|
||||
comm := new(packer.MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
state.Put("communicator", comm)
|
||||
|
||||
// Test the run
|
||||
|
|
|
@ -5,14 +5,14 @@ import (
|
|||
"testing"
|
||||
|
||||
vboxcommon "github.com/hashicorp/packer/builder/virtualbox/common"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func testState(t *testing.T) multistep.StateBag {
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("driver", new(vboxcommon.DriverMock))
|
||||
state.Put("ui", &packer.BasicUi{
|
||||
state.Put("ui", &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
})
|
||||
|
|
|
@ -8,8 +8,8 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func testLocalOutputDir(t *testing.T) *LocalOutputDir {
|
||||
|
@ -31,7 +31,7 @@ func testStepShutdownState(t *testing.T) multistep.StateBag {
|
|||
}
|
||||
|
||||
state := testState(t)
|
||||
state.Put("communicator", new(packer.MockCommunicator))
|
||||
state.Put("communicator", new(packersdk.MockCommunicator))
|
||||
state.Put("dir", dir)
|
||||
state.Put("vmx_path", "foo")
|
||||
return state
|
||||
|
@ -48,7 +48,7 @@ func TestStepShutdown_command(t *testing.T) {
|
|||
step.Timeout = 10 * time.Second
|
||||
step.Testing = true
|
||||
|
||||
comm := state.Get("communicator").(*packer.MockCommunicator)
|
||||
comm := state.Get("communicator").(*packersdk.MockCommunicator)
|
||||
driver := state.Get("driver").(*DriverMock)
|
||||
driver.IsRunningResult = true
|
||||
|
||||
|
@ -109,7 +109,7 @@ func TestStepShutdown_noCommand(t *testing.T) {
|
|||
state := testStepShutdownState(t)
|
||||
step := new(StepShutdown)
|
||||
|
||||
comm := state.Get("communicator").(*packer.MockCommunicator)
|
||||
comm := state.Get("communicator").(*packersdk.MockCommunicator)
|
||||
driver := state.Get("driver").(*DriverMock)
|
||||
|
||||
// Test the run
|
||||
|
@ -149,7 +149,7 @@ func TestStepShutdown_locks(t *testing.T) {
|
|||
step.Testing = true
|
||||
|
||||
dir := state.Get("dir").(*LocalOutputDir)
|
||||
comm := state.Get("communicator").(*packer.MockCommunicator)
|
||||
comm := state.Get("communicator").(*packersdk.MockCommunicator)
|
||||
driver := state.Get("driver").(*DriverMock)
|
||||
|
||||
// Create some lock files
|
||||
|
|
|
@ -4,14 +4,14 @@ import (
|
|||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func testState(t *testing.T) multistep.StateBag {
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("driver", new(DriverMock))
|
||||
state.Put("ui", &packer.BasicUi{
|
||||
state.Put("ui", &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
})
|
||||
|
|
|
@ -142,7 +142,7 @@ func setupVMwareBuild(t *testing.T, builderConfig map[string]string, provisioner
|
|||
"vmware-iso": func() (packer.Builder, error) { return &Builder{}, nil },
|
||||
},
|
||||
Hook: func(n string) (packersdk.Hook, error) {
|
||||
return &packer.DispatchHook{}, nil
|
||||
return &packersdk.DispatchHook{}, nil
|
||||
},
|
||||
ProvisionerStore: packer.MapOfProvisioner{
|
||||
"shell": func() (packer.Provisioner, error) { return &shell.Provisioner{}, nil },
|
||||
|
|
|
@ -5,14 +5,14 @@ import (
|
|||
"testing"
|
||||
|
||||
vmwcommon "github.com/hashicorp/packer/builder/vmware/common"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func testState(t *testing.T) multistep.StateBag {
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("driver", new(vmwcommon.DriverMock))
|
||||
state.Put("ui", &packer.BasicUi{
|
||||
state.Put("ui", &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
})
|
||||
|
|
|
@ -5,14 +5,14 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/builder/vsphere/driver"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func cleanupTestState(mockVM driver.VirtualMachine) multistep.StateBag {
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("vm", mockVM)
|
||||
state.Put("ui", &packer.BasicUi{
|
||||
state.Put("ui", &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
})
|
||||
|
|
|
@ -4,13 +4,13 @@ import (
|
|||
"bytes"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func basicStateBag(errorBuffer *strings.Builder) *multistep.BasicStateBag {
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("ui", &packer.BasicUi{
|
||||
state.Put("ui", &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
ErrorWriter: errorBuffer,
|
||||
|
|
|
@ -3,13 +3,13 @@ package iso
|
|||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func basicStateBag() *multistep.BasicStateBag {
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("ui", &packer.BasicUi{
|
||||
state.Put("ui", &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
})
|
||||
|
|
|
@ -11,8 +11,8 @@ import (
|
|||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/hashicorp/packer/builder/vsphere/common"
|
||||
"github.com/hashicorp/packer/builder/vsphere/driver"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func TestCreateConfig_Prepare(t *testing.T) {
|
||||
|
@ -307,7 +307,7 @@ func TestStepCreateVM_Cleanup(t *testing.T) {
|
|||
|
||||
// Destroy fail
|
||||
errorBuffer := &strings.Builder{}
|
||||
ui := &packer.BasicUi{
|
||||
ui := &packersdk.BasicUi{
|
||||
Reader: strings.NewReader(""),
|
||||
Writer: ioutil.Discard,
|
||||
ErrorWriter: errorBuffer,
|
||||
|
|
|
@ -7,8 +7,8 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -116,8 +116,8 @@ func TestCreateInstanceMetadata_fromNotExistFile(t *testing.T) {
|
|||
func testState(t *testing.T) multistep.StateBag {
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("config", testConfigStruct(t))
|
||||
state.Put("hook", &packer.MockHook{})
|
||||
state.Put("ui", &packer.BasicUi{
|
||||
state.Put("hook", &packersdk.MockHook{})
|
||||
state.Put("ui", &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
})
|
||||
|
|
|
@ -78,7 +78,7 @@ func testMetaParallel(t *testing.T, builder *ParallelTestBuilder, locked *Locked
|
|||
},
|
||||
},
|
||||
},
|
||||
Ui: &packer.BasicUi{
|
||||
Ui: &packersdk.BasicUi{
|
||||
Writer: &out,
|
||||
ErrorWriter: &err,
|
||||
},
|
||||
|
|
|
@ -15,6 +15,7 @@ import (
|
|||
"github.com/hashicorp/packer/builder/file"
|
||||
"github.com/hashicorp/packer/builder/null"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
"github.com/hashicorp/packer/post-processor/manifest"
|
||||
shell_local_pp "github.com/hashicorp/packer/post-processor/shell-local"
|
||||
filep "github.com/hashicorp/packer/provisioner/file"
|
||||
|
@ -859,7 +860,7 @@ func testMetaFile(t *testing.T) Meta {
|
|||
var out, err bytes.Buffer
|
||||
return Meta{
|
||||
CoreConfig: testCoreConfigBuilder(t),
|
||||
Ui: &packer.BasicUi{
|
||||
Ui: &packersdk.BasicUi{
|
||||
Writer: &out,
|
||||
ErrorWriter: &err,
|
||||
},
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
|
||||
"github.com/hashicorp/packer/builder/file"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
shell_local "github.com/hashicorp/packer/provisioner/shell-local"
|
||||
"github.com/hashicorp/packer/provisioner/sleep"
|
||||
)
|
||||
|
@ -33,7 +34,7 @@ func testMetaSleepFile(t *testing.T) Meta {
|
|||
var out, err bytes.Buffer
|
||||
return Meta{
|
||||
CoreConfig: testCoreConfigSleepBuilder(t),
|
||||
Ui: &packer.BasicUi{
|
||||
Ui: &packersdk.BasicUi{
|
||||
Writer: &out,
|
||||
ErrorWriter: &err,
|
||||
},
|
||||
|
|
|
@ -7,12 +7,13 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
const fixturesDir = "./test-fixtures"
|
||||
|
||||
func fatalCommand(t *testing.T, m Meta) {
|
||||
ui := m.Ui.(*packer.BasicUi)
|
||||
ui := m.Ui.(*packersdk.BasicUi)
|
||||
out := ui.Writer.(*bytes.Buffer)
|
||||
err := ui.ErrorWriter.(*bytes.Buffer)
|
||||
t.Fatalf(
|
||||
|
@ -22,7 +23,7 @@ func fatalCommand(t *testing.T, m Meta) {
|
|||
}
|
||||
|
||||
func outputCommand(t *testing.T, m Meta) (string, string) {
|
||||
ui := m.Ui.(*packer.BasicUi)
|
||||
ui := m.Ui.(*packersdk.BasicUi)
|
||||
out := ui.Writer.(*bytes.Buffer)
|
||||
err := ui.ErrorWriter.(*bytes.Buffer)
|
||||
return out.String(), err.String()
|
||||
|
@ -48,7 +49,7 @@ func testMeta(t *testing.T) Meta {
|
|||
|
||||
return Meta{
|
||||
CoreConfig: packer.TestCoreConfig(t),
|
||||
Ui: &packer.BasicUi{
|
||||
Ui: &packersdk.BasicUi{
|
||||
Writer: &out,
|
||||
ErrorWriter: &err,
|
||||
},
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"github.com/hashicorp/packer/builder/file"
|
||||
"github.com/hashicorp/packer/builder/null"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
"github.com/hashicorp/packer/post-processor/manifest"
|
||||
shell_local_pp "github.com/hashicorp/packer/post-processor/shell-local"
|
||||
filep "github.com/hashicorp/packer/provisioner/file"
|
||||
|
@ -99,7 +100,7 @@ func TestHelperProcess(*testing.T) {
|
|||
}
|
||||
|
||||
func commandMeta() Meta {
|
||||
basicUi := &packer.BasicUi{
|
||||
basicUi := &packersdk.BasicUi{
|
||||
Reader: os.Stdin,
|
||||
Writer: os.Stdout,
|
||||
ErrorWriter: os.Stdout,
|
||||
|
|
|
@ -5,13 +5,13 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestFix(t *testing.T) {
|
||||
s := &strings.Builder{}
|
||||
ui := &packer.BasicUi{
|
||||
ui := &packersdk.BasicUi{
|
||||
Writer: s,
|
||||
}
|
||||
c := &FixCommand{
|
||||
|
|
|
@ -157,7 +157,7 @@ func Test(t TestT, c TestCase) {
|
|||
// Run it! We use a temporary directory for caching and discard
|
||||
// any UI output. We discard since it shows up in logs anyways.
|
||||
log.Printf("[DEBUG] Running 'test' build")
|
||||
ui := &packer.BasicUi{
|
||||
ui := &packersdk.BasicUi{
|
||||
Reader: os.Stdin,
|
||||
Writer: ioutil.Discard,
|
||||
ErrorWriter: ioutil.Discard,
|
||||
|
|
|
@ -5,8 +5,8 @@ import (
|
|||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func TestStepConnect_impl(t *testing.T) {
|
||||
|
@ -31,8 +31,8 @@ func TestStepConnect_none(t *testing.T) {
|
|||
|
||||
func testState(t *testing.T) multistep.StateBag {
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("hook", &packer.MockHook{})
|
||||
state.Put("ui", &packer.BasicUi{
|
||||
state.Put("hook", &packersdk.MockHook{})
|
||||
state.Put("ui", &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
})
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
amazonebsbuilder "github.com/hashicorp/packer/builder/amazon/ebs"
|
||||
"github.com/hashicorp/packer/command"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
fileprovisioner "github.com/hashicorp/packer/provisioner/file"
|
||||
"github.com/hashicorp/packer/provisioner/shell"
|
||||
)
|
||||
|
@ -43,7 +44,7 @@ func TestMetaFile(t *testing.T) command.Meta {
|
|||
var out, err bytes.Buffer
|
||||
return command.Meta{
|
||||
CoreConfig: testCoreConfigBuilder(t),
|
||||
Ui: &packer.BasicUi{
|
||||
Ui: &packersdk.BasicUi{
|
||||
Writer: &out,
|
||||
ErrorWriter: &err,
|
||||
},
|
||||
|
|
2
main.go
2
main.go
|
@ -195,7 +195,7 @@ func wrappedMain() int {
|
|||
return 1
|
||||
}
|
||||
} else {
|
||||
basicUi := &packer.BasicUi{
|
||||
basicUi := &packersdk.BasicUi{
|
||||
Reader: os.Stdin,
|
||||
Writer: os.Stdout,
|
||||
ErrorWriter: os.Stdout,
|
||||
|
|
|
@ -10,7 +10,6 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/common"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
|
@ -19,7 +18,7 @@ import (
|
|||
// testUI returns a test ui plus a function to retrieve the errors written to the ui
|
||||
func testUI() (packersdk.Ui, func() string) {
|
||||
errorBuffer := &strings.Builder{}
|
||||
ui := &packer.BasicUi{
|
||||
ui := &packersdk.BasicUi{
|
||||
Reader: strings.NewReader(""),
|
||||
Writer: ioutil.Discard,
|
||||
ErrorWriter: errorBuffer,
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func testConfig() map[string]interface{} {
|
||||
|
@ -19,7 +20,7 @@ func TestProvisioner_GenerateElevatedRunner(t *testing.T) {
|
|||
config := testConfig()
|
||||
p := new(packer.MockProvisioner)
|
||||
p.Prepare(config)
|
||||
comm := new(packer.MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
p.ProvCommunicator = comm
|
||||
path, err := GenerateElevatedRunner("whoami", p)
|
||||
|
||||
|
|
|
@ -8,8 +8,8 @@ import (
|
|||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func TestStepCreateCD_Impl(t *testing.T) {
|
||||
|
@ -22,7 +22,7 @@ func TestStepCreateCD_Impl(t *testing.T) {
|
|||
|
||||
func testStepCreateCDState(t *testing.T) multistep.StateBag {
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("ui", &packer.BasicUi{
|
||||
state.Put("ui", &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
})
|
||||
|
|
|
@ -12,8 +12,8 @@ import (
|
|||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
const TestFixtures = "test-fixtures"
|
||||
|
@ -28,7 +28,7 @@ func TestStepCreateFloppy_Impl(t *testing.T) {
|
|||
|
||||
func testStepCreateFloppyState(t *testing.T) multistep.StateBag {
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("ui", &packer.BasicUi{
|
||||
state.Put("ui", &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
})
|
||||
|
|
|
@ -19,6 +19,7 @@ import (
|
|||
urlhelper "github.com/hashicorp/go-getter/v2/helper/url"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/tmp"
|
||||
)
|
||||
|
||||
|
@ -242,7 +243,7 @@ func TestStepDownload_download(t *testing.T) {
|
|||
ResultKey: "iso_path",
|
||||
Url: nil,
|
||||
}
|
||||
ui := &packer.BasicUi{
|
||||
ui := &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
PB: &packer.NoopProgressTracker{},
|
||||
|
|
|
@ -9,11 +9,12 @@ import (
|
|||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func testState(t *testing.T) multistep.StateBag {
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("ui", &packer.BasicUi{
|
||||
state.Put("ui", &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
PB: &packer.NoopProgressTracker{},
|
||||
|
|
|
@ -1,6 +1,23 @@
|
|||
package packer
|
||||
|
||||
import "github.com/hashicorp/go-getter"
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
|
||||
"github.com/hashicorp/go-getter"
|
||||
)
|
||||
|
||||
type TTY interface {
|
||||
ReadString() (string, error)
|
||||
Close() error
|
||||
}
|
||||
|
||||
// The Ui interface handles all communication for Packer with the outside
|
||||
// world. This sort of control allows us to strictly control how output
|
||||
|
@ -14,3 +31,122 @@ type Ui interface {
|
|||
// TrackProgress(src string, currentSize, totalSize int64, stream io.ReadCloser) (body io.ReadCloser)
|
||||
getter.ProgressTracker
|
||||
}
|
||||
|
||||
var ErrInterrupted = errors.New("interrupted")
|
||||
|
||||
// BasicUI is an implementation of Ui that reads and writes from a standard Go
|
||||
// reader and writer. It is safe to be called from multiple goroutines. Machine
|
||||
// readable output is simply logged for this UI.
|
||||
type BasicUi struct {
|
||||
Reader io.Reader
|
||||
Writer io.Writer
|
||||
ErrorWriter io.Writer
|
||||
l sync.Mutex
|
||||
interrupted bool
|
||||
TTY TTY
|
||||
PB getter.ProgressTracker
|
||||
}
|
||||
|
||||
var _ Ui = new(BasicUi)
|
||||
|
||||
func (rw *BasicUi) Ask(query string) (string, error) {
|
||||
rw.l.Lock()
|
||||
defer rw.l.Unlock()
|
||||
|
||||
if rw.interrupted {
|
||||
return "", ErrInterrupted
|
||||
}
|
||||
|
||||
if rw.TTY == nil {
|
||||
return "", errors.New("no available tty")
|
||||
}
|
||||
sigCh := make(chan os.Signal, 1)
|
||||
signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM)
|
||||
defer signal.Stop(sigCh)
|
||||
|
||||
log.Printf("ui: ask: %s", query)
|
||||
if query != "" {
|
||||
if _, err := fmt.Fprint(rw.Writer, query+" "); err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
result := make(chan string, 1)
|
||||
go func() {
|
||||
line, err := rw.TTY.ReadString()
|
||||
if err != nil {
|
||||
log.Printf("ui: scan err: %s", err)
|
||||
return
|
||||
}
|
||||
result <- strings.TrimSpace(line)
|
||||
}()
|
||||
|
||||
select {
|
||||
case line := <-result:
|
||||
return line, nil
|
||||
case <-sigCh:
|
||||
// Print a newline so that any further output starts properly
|
||||
// on a new line.
|
||||
fmt.Fprintln(rw.Writer)
|
||||
|
||||
// Mark that we were interrupted so future Ask calls fail.
|
||||
rw.interrupted = true
|
||||
|
||||
return "", ErrInterrupted
|
||||
}
|
||||
}
|
||||
|
||||
func (rw *BasicUi) Say(message string) {
|
||||
rw.l.Lock()
|
||||
defer rw.l.Unlock()
|
||||
|
||||
// Use LogSecretFilter to scrub out sensitive variables
|
||||
message = LogSecretFilter.FilterString(message)
|
||||
|
||||
log.Printf("ui: %s", message)
|
||||
_, err := fmt.Fprint(rw.Writer, message+"\n")
|
||||
if err != nil {
|
||||
log.Printf("[ERR] Failed to write to UI: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (rw *BasicUi) Message(message string) {
|
||||
rw.l.Lock()
|
||||
defer rw.l.Unlock()
|
||||
|
||||
// Use LogSecretFilter to scrub out sensitive variables
|
||||
message = LogSecretFilter.FilterString(message)
|
||||
|
||||
log.Printf("ui: %s", message)
|
||||
_, err := fmt.Fprint(rw.Writer, message+"\n")
|
||||
if err != nil {
|
||||
log.Printf("[ERR] Failed to write to UI: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (rw *BasicUi) Error(message string) {
|
||||
rw.l.Lock()
|
||||
defer rw.l.Unlock()
|
||||
|
||||
writer := rw.ErrorWriter
|
||||
if writer == nil {
|
||||
writer = rw.Writer
|
||||
}
|
||||
|
||||
// Use LogSecretFilter to scrub out sensitive variables
|
||||
message = LogSecretFilter.FilterString(message)
|
||||
|
||||
log.Printf("ui error: %s", message)
|
||||
_, err := fmt.Fprint(writer, message+"\n")
|
||||
if err != nil {
|
||||
log.Printf("[ERR] Failed to write to UI: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (rw *BasicUi) Machine(t string, args ...string) {
|
||||
log.Printf("machine readable: %s %#v", t, args)
|
||||
}
|
||||
|
||||
func (rw *BasicUi) TrackProgress(src string, currentSize, totalSize int64, stream io.ReadCloser) (body io.ReadCloser) {
|
||||
return rw.PB.TrackProgress(src, currentSize, totalSize, stream)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,114 @@
|
|||
package packer
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"log"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// TestUi is a UI that only outputs unformatted output to the given writer.
|
||||
type TestUi struct {
|
||||
Writer io.Writer
|
||||
}
|
||||
|
||||
var _ Ui = new(TestUi)
|
||||
|
||||
func (u *TestUi) Ask(query string) (string, error) {
|
||||
return "", errors.New("Test UI can't ask")
|
||||
}
|
||||
|
||||
func (u *TestUi) Say(message string) {
|
||||
log.Printf(message)
|
||||
}
|
||||
|
||||
func (u *TestUi) Message(message string) {
|
||||
log.Printf(message)
|
||||
}
|
||||
|
||||
func (u *TestUi) Error(message string) {
|
||||
log.Printf(message)
|
||||
}
|
||||
|
||||
func (u *TestUi) Machine(message string, args ...string) {
|
||||
log.Printf("%s, %s", message, strings.Join(args, ", "))
|
||||
}
|
||||
|
||||
func (u *TestUi) TrackProgress(src string, currentSize, totalSize int64, stream io.ReadCloser) (body io.ReadCloser) {
|
||||
return &readCloser{
|
||||
read: func(p []byte) (int, error) {
|
||||
return stream.Read(p)
|
||||
},
|
||||
close: func() error {
|
||||
return stream.Close()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type MockUi struct {
|
||||
AskCalled bool
|
||||
AskQuery string
|
||||
ErrorCalled bool
|
||||
ErrorMessage string
|
||||
MachineCalled bool
|
||||
MachineType string
|
||||
MachineArgs []string
|
||||
MessageCalled bool
|
||||
MessageMessage string
|
||||
SayCalled bool
|
||||
SayMessage string
|
||||
|
||||
TrackProgressCalled bool
|
||||
ProgressBarAddCalled bool
|
||||
ProgressBarCloseCalled bool
|
||||
}
|
||||
|
||||
func (u *MockUi) Ask(query string) (string, error) {
|
||||
u.AskCalled = true
|
||||
u.AskQuery = query
|
||||
return "foo", nil
|
||||
}
|
||||
|
||||
func (u *MockUi) Error(message string) {
|
||||
u.ErrorCalled = true
|
||||
u.ErrorMessage = message
|
||||
}
|
||||
|
||||
func (u *MockUi) Machine(t string, args ...string) {
|
||||
u.MachineCalled = true
|
||||
u.MachineType = t
|
||||
u.MachineArgs = args
|
||||
}
|
||||
|
||||
func (u *MockUi) Message(message string) {
|
||||
u.MessageCalled = true
|
||||
u.MessageMessage = message
|
||||
}
|
||||
|
||||
func (u *MockUi) Say(message string) {
|
||||
u.SayCalled = true
|
||||
u.SayMessage = message
|
||||
}
|
||||
|
||||
func (u *MockUi) TrackProgress(_ string, _, _ int64, stream io.ReadCloser) (body io.ReadCloser) {
|
||||
u.TrackProgressCalled = true
|
||||
|
||||
return &readCloser{
|
||||
read: func(p []byte) (int, error) {
|
||||
u.ProgressBarAddCalled = true
|
||||
return stream.Read(p)
|
||||
},
|
||||
close: func() error {
|
||||
u.ProgressBarCloseCalled = true
|
||||
return stream.Close()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type readCloser struct {
|
||||
read func([]byte) (int, error)
|
||||
close func() error
|
||||
}
|
||||
|
||||
func (c *readCloser) Close() error { return c.close() }
|
||||
func (c *readCloser) Read(p []byte) (int, error) { return c.read(p) }
|
|
@ -412,7 +412,7 @@ PostProcessorRunSeqLoop:
|
|||
}
|
||||
|
||||
if len(errors) > 0 {
|
||||
err = &packersdk.MultiError{errors}
|
||||
err = &packersdk.MultiError{Errors: errors}
|
||||
}
|
||||
|
||||
return artifacts, err
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"reflect"
|
||||
"testing"
|
||||
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/packerbuilderdata"
|
||||
"github.com/hashicorp/packer/version"
|
||||
)
|
||||
|
@ -19,8 +20,8 @@ func testBuild() *CoreBuild {
|
|||
Builder: &MockBuilder{ArtifactId: "b"},
|
||||
BuilderConfig: 42,
|
||||
BuilderType: "foo",
|
||||
hooks: map[string][]Hook{
|
||||
"foo": {&MockHook{}},
|
||||
hooks: map[string][]packersdk.Hook{
|
||||
"foo": {&packersdk.MockHook{}},
|
||||
},
|
||||
Provisioners: []CoreBuildProvisioner{
|
||||
{
|
||||
|
@ -246,7 +247,7 @@ func TestBuild_Run(t *testing.T) {
|
|||
dispatchHook := builder.RunHook
|
||||
dispatchHook.Run(ctx, "foo", nil, nil, 42)
|
||||
|
||||
hook := build.hooks["foo"][0].(*MockHook)
|
||||
hook := build.hooks["foo"][0].(*packersdk.MockHook)
|
||||
if !hook.RunCalled {
|
||||
t.Fatal("should be called")
|
||||
}
|
||||
|
@ -255,7 +256,7 @@ func TestBuild_Run(t *testing.T) {
|
|||
}
|
||||
|
||||
// Verify provisioners run
|
||||
dispatchHook.Run(ctx, HookProvision, nil, new(MockCommunicator), 42)
|
||||
dispatchHook.Run(ctx, packersdk.HookProvision, nil, new(packersdk.MockCommunicator), 42)
|
||||
prov := build.Provisioners[0].Provisioner.(*MockProvisioner)
|
||||
if !prov.ProvCalled {
|
||||
t.Fatal("should be called")
|
||||
|
|
|
@ -642,18 +642,18 @@ func TestSensitiveVars(t *testing.T) {
|
|||
// hardcoded
|
||||
{
|
||||
"sensitive-variables.json",
|
||||
map[string]string{"foo": "bar"},
|
||||
map[string]string{"foo": "bar_extra_sensitive_probably_a_password"},
|
||||
[]string{"foo"},
|
||||
"bar",
|
||||
"the foo jumped over the <sensitive>",
|
||||
false,
|
||||
},
|
||||
// interpolated
|
||||
{
|
||||
"sensitive-variables.json",
|
||||
map[string]string{"foo": "bar",
|
||||
map[string]string{"foo": "bar_extra_sensitive_probably_a_password",
|
||||
"bang": "{{ user `foo`}}"},
|
||||
[]string{"bang"},
|
||||
"bar",
|
||||
"the foo jumped over the <sensitive>",
|
||||
false,
|
||||
},
|
||||
}
|
||||
|
@ -680,13 +680,11 @@ func TestSensitiveVars(t *testing.T) {
|
|||
if (err != nil) != tc.Err {
|
||||
t.Fatalf("err: %s\n\n%s", tc.File, err)
|
||||
}
|
||||
filtered := packersdk.LogSecretFilter.get()
|
||||
if filtered[0] != tc.Expected && len(filtered) != 1 {
|
||||
// Check that filter correctly manipulates strings:
|
||||
filtered := packersdk.LogSecretFilter.FilterString("the foo jumped over the bar_extra_sensitive_probably_a_password")
|
||||
if filtered != tc.Expected {
|
||||
t.Fatalf("not filtering sensitive vars; filtered is %#v", filtered)
|
||||
}
|
||||
|
||||
// clear filter so it doesn't break other tests
|
||||
packersdk.LogSecretFilter.s = make(map[string]struct{})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func helperProcess(s ...string) *exec.Cmd {
|
||||
|
@ -68,7 +69,7 @@ func TestHelperProcess(*testing.T) {
|
|||
log.Printf("[ERR] %s", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
server.RegisterHook(new(packer.MockHook))
|
||||
server.RegisterHook(new(packersdk.MockHook))
|
||||
server.Serve()
|
||||
case "invalid-rpc-address":
|
||||
fmt.Println("lolinvalid")
|
||||
|
|
|
@ -6,12 +6,14 @@ import (
|
|||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func TestProvisionHook_Impl(t *testing.T) {
|
||||
var raw interface{}
|
||||
raw = &ProvisionHook{}
|
||||
if _, ok := raw.(Hook); !ok {
|
||||
if _, ok := raw.(packersdk.Hook); !ok {
|
||||
t.Fatalf("must be a Hook")
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +23,7 @@ func TestProvisionHook(t *testing.T) {
|
|||
pB := &MockProvisioner{}
|
||||
|
||||
ui := testUi()
|
||||
var comm Communicator = new(MockCommunicator)
|
||||
var comm packersdk.Communicator = new(packersdk.MockCommunicator)
|
||||
var data interface{} = nil
|
||||
|
||||
hook := &ProvisionHook{
|
||||
|
@ -47,7 +49,7 @@ func TestProvisionHook_nilComm(t *testing.T) {
|
|||
pB := &MockProvisioner{}
|
||||
|
||||
ui := testUi()
|
||||
var comm Communicator = nil
|
||||
var comm packersdk.Communicator = nil
|
||||
var data interface{} = nil
|
||||
|
||||
hook := &ProvisionHook{
|
||||
|
@ -80,7 +82,7 @@ func TestProvisionHook_cancel(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
err := hook.Run(topCtx, "foo", nil, new(MockCommunicator), nil)
|
||||
err := hook.Run(topCtx, "foo", nil, new(packersdk.MockCommunicator), nil)
|
||||
if err == nil {
|
||||
t.Fatal("should have err")
|
||||
}
|
||||
|
@ -114,7 +116,7 @@ func TestPausedProvisionerProvision(t *testing.T) {
|
|||
}
|
||||
|
||||
ui := testUi()
|
||||
comm := new(MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
prov.Provision(context.Background(), ui, comm, make(map[string]interface{}))
|
||||
if !mock.ProvCalled {
|
||||
t.Fatal("prov should be called")
|
||||
|
@ -144,7 +146,7 @@ func TestPausedProvisionerProvision_waits(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
err := prov.Provision(context.Background(), testUi(), new(MockCommunicator), make(map[string]interface{}))
|
||||
err := prov.Provision(context.Background(), testUi(), new(packersdk.MockCommunicator), make(map[string]interface{}))
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("prov failed: %v", err)
|
||||
|
@ -165,7 +167,7 @@ func TestPausedProvisionerCancel(t *testing.T) {
|
|||
return ctx.Err()
|
||||
}
|
||||
|
||||
err := prov.Provision(topCtx, testUi(), new(MockCommunicator), make(map[string]interface{}))
|
||||
err := prov.Provision(topCtx, testUi(), new(packersdk.MockCommunicator), make(map[string]interface{}))
|
||||
if err == nil {
|
||||
t.Fatal("should have err")
|
||||
}
|
||||
|
@ -197,7 +199,7 @@ func TestDebuggedProvisionerProvision(t *testing.T) {
|
|||
}
|
||||
|
||||
ui := testUi()
|
||||
comm := new(MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
writeReader(ui, "\n")
|
||||
prov.Provision(context.Background(), ui, comm, make(map[string]interface{}))
|
||||
if !mock.ProvCalled {
|
||||
|
@ -225,7 +227,7 @@ func TestDebuggedProvisionerCancel(t *testing.T) {
|
|||
return ctx.Err()
|
||||
}
|
||||
|
||||
err := prov.Provision(topCtx, testUi(), new(MockCommunicator), make(map[string]interface{}))
|
||||
err := prov.Provision(topCtx, testUi(), new(packersdk.MockCommunicator), make(map[string]interface{}))
|
||||
if err == nil {
|
||||
t.Fatal("should have error")
|
||||
}
|
||||
|
@ -266,7 +268,7 @@ func TestRetriedProvisionerProvision(t *testing.T) {
|
|||
}
|
||||
|
||||
ui := testUi()
|
||||
comm := new(MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
err := prov.Provision(context.Background(), ui, comm, make(map[string]interface{}))
|
||||
if err != nil {
|
||||
t.Fatal("should not have errored")
|
||||
|
@ -303,7 +305,7 @@ func TestRetriedProvisionerCancelledProvision(t *testing.T) {
|
|||
}
|
||||
|
||||
ui := testUi()
|
||||
comm := new(MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
err := prov.Provision(ctx, ui, comm, make(map[string]interface{}))
|
||||
if err == nil {
|
||||
t.Fatal("should have errored")
|
||||
|
@ -336,7 +338,7 @@ func TestRetriedProvisionerCancel(t *testing.T) {
|
|||
return ctx.Err()
|
||||
}
|
||||
|
||||
err := prov.Provision(topCtx, testUi(), new(MockCommunicator), make(map[string]interface{}))
|
||||
err := prov.Provision(topCtx, testUi(), new(packersdk.MockCommunicator), make(map[string]interface{}))
|
||||
if err == nil {
|
||||
t.Fatal("should have err")
|
||||
}
|
||||
|
|
|
@ -4,13 +4,12 @@ import (
|
|||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func TestArtifactRPC(t *testing.T) {
|
||||
// Create the interface to test
|
||||
a := new(packer.MockArtifact)
|
||||
a := new(packersdk.MockArtifact)
|
||||
|
||||
// Start the server
|
||||
client, server := testClientServer(t)
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
var testBuildArtifact = &packer.MockArtifact{}
|
||||
var testBuildArtifact = &packersdk.MockArtifact{}
|
||||
|
||||
type testBuild struct {
|
||||
nameCalled bool
|
||||
|
@ -86,7 +86,7 @@ func TestBuild(t *testing.T) {
|
|||
}
|
||||
|
||||
// Test Run
|
||||
ui := new(testUi)
|
||||
ui := new(packersdk.MockUi)
|
||||
artifacts, err := bClient.Run(ctx, ui)
|
||||
if !b.runCalled {
|
||||
t.Fatal("run should be called")
|
||||
|
@ -150,7 +150,7 @@ func TestBuild_cancel(t *testing.T) {
|
|||
|
||||
bClient.Prepare()
|
||||
|
||||
ui := new(testUi)
|
||||
ui := new(packersdk.MockUi)
|
||||
bClient.Run(topCtx, ui)
|
||||
|
||||
// if context cancellation is not propagated, this will timeout
|
||||
|
|
|
@ -6,9 +6,10 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
var testBuilderArtifact = &packer.MockArtifact{}
|
||||
var testBuilderArtifact = &packersdk.MockArtifact{}
|
||||
|
||||
func TestBuilderPrepare(t *testing.T) {
|
||||
b := new(packer.MockBuilder)
|
||||
|
@ -68,7 +69,7 @@ func TestBuilderRun(t *testing.T) {
|
|||
bClient := client.Builder()
|
||||
|
||||
// Test Run
|
||||
hook := &packer.MockHook{}
|
||||
hook := &packersdk.MockHook{}
|
||||
ui := &testUi{}
|
||||
artifact, err := bClient.Run(context.Background(), ui, hook)
|
||||
if err != nil {
|
||||
|
@ -94,7 +95,7 @@ func TestBuilderRun_nilResult(t *testing.T) {
|
|||
server.RegisterBuilder(b)
|
||||
bClient := client.Builder()
|
||||
|
||||
hook := &packer.MockHook{}
|
||||
hook := &packersdk.MockHook{}
|
||||
ui := &testUi{}
|
||||
artifact, err := bClient.Run(context.Background(), ui, hook)
|
||||
if artifact != nil {
|
||||
|
@ -115,7 +116,7 @@ func TestBuilderRun_ErrResult(t *testing.T) {
|
|||
|
||||
b.RunErrResult = true
|
||||
|
||||
hook := &packer.MockHook{}
|
||||
hook := &packersdk.MockHook{}
|
||||
ui := &testUi{}
|
||||
artifact, err := bClient.Run(context.Background(), ui, hook)
|
||||
if artifact != nil {
|
||||
|
@ -143,7 +144,7 @@ func TestBuilderCancel(t *testing.T) {
|
|||
server.RegisterBuilder(b)
|
||||
bClient := client.Builder()
|
||||
|
||||
bClient.Run(topCtx, new(testUi), new(packer.MockHook))
|
||||
bClient.Run(topCtx, new(testUi), new(packersdk.MockHook))
|
||||
|
||||
if !cancelled {
|
||||
t.Fatal("context should have been cancelled")
|
||||
|
|
|
@ -7,13 +7,12 @@ import (
|
|||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func TestCommunicatorRPC(t *testing.T) {
|
||||
// Create the interface to test
|
||||
c := new(packer.MockCommunicator)
|
||||
c := new(packersdk.MockCommunicator)
|
||||
|
||||
// Start the server
|
||||
client, server := testClientServer(t)
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
|
@ -15,7 +14,7 @@ func TestHook_Implements(t *testing.T) {
|
|||
func TestHook_cancelWhileRun(t *testing.T) {
|
||||
topCtx, cancelTopCtx := context.WithCancel(context.Background())
|
||||
|
||||
h := &packer.MockHook{
|
||||
h := &packersdk.MockHook{
|
||||
RunFunc: func(ctx context.Context) error {
|
||||
cancelTopCtx()
|
||||
<-ctx.Done()
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
var testPostProcessorArtifact = new(packer.MockArtifact)
|
||||
var testPostProcessorArtifact = new(packersdk.MockArtifact)
|
||||
|
||||
type TestPostProcessor struct {
|
||||
configCalled bool
|
||||
|
@ -71,7 +71,7 @@ func TestPostProcessorRPC(t *testing.T) {
|
|||
}
|
||||
|
||||
// Test PostProcess
|
||||
a := &packer.MockArtifact{
|
||||
a := &packersdk.MockArtifact{
|
||||
IdValue: "ppTestId",
|
||||
}
|
||||
ui := new(testUi)
|
||||
|
@ -121,7 +121,7 @@ func TestPostProcessorRPC_cancel(t *testing.T) {
|
|||
}
|
||||
|
||||
// Test PostProcess
|
||||
a := &packer.MockArtifact{
|
||||
a := &packersdk.MockArtifact{
|
||||
IdValue: "ppTestId",
|
||||
}
|
||||
ui := new(testUi)
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func TestProvisionerRPC(t *testing.T) {
|
||||
|
@ -38,7 +39,7 @@ func TestProvisionerRPC(t *testing.T) {
|
|||
|
||||
// Test Provision
|
||||
ui := &testUi{}
|
||||
comm := &packer.MockCommunicator{}
|
||||
comm := &packersdk.MockCommunicator{}
|
||||
if err := pClient.Provision(topCtx, ui, comm, make(map[string]interface{})); err == nil {
|
||||
t.Fatalf("Provison should have err")
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"variables": {
|
||||
"foo": "bar"
|
||||
"foo": "bar_extra_sensitive_probably_a_password"
|
||||
},
|
||||
"sensitive-variables": [
|
||||
"foo"
|
||||
|
|
|
@ -33,7 +33,7 @@ func TestCore(t *testing.T, c *CoreConfig) *Core {
|
|||
|
||||
func TestUi(t *testing.T) packersdk.Ui {
|
||||
var buf bytes.Buffer
|
||||
return &BasicUi{
|
||||
return &packersdk.BasicUi{
|
||||
Reader: &buf,
|
||||
Writer: ioutil.Discard,
|
||||
ErrorWriter: ioutil.Discard,
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
package packer
|
||||
|
||||
type TTY interface {
|
||||
ReadString() (string, error)
|
||||
Close() error
|
||||
}
|
119
packer/ui.go
119
packer/ui.go
|
@ -7,10 +7,8 @@ import (
|
|||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
"unicode"
|
||||
|
@ -171,123 +169,6 @@ func (u *TargetedUI) TrackProgress(src string, currentSize, totalSize int64, str
|
|||
return u.Ui.TrackProgress(u.prefixLines(false, src), currentSize, totalSize, stream)
|
||||
}
|
||||
|
||||
// The BasicUI is a UI that reads and writes from a standard Go reader
|
||||
// and writer. It is safe to be called from multiple goroutines. Machine
|
||||
// readable output is simply logged for this UI.
|
||||
type BasicUi struct {
|
||||
Reader io.Reader
|
||||
Writer io.Writer
|
||||
ErrorWriter io.Writer
|
||||
l sync.Mutex
|
||||
interrupted bool
|
||||
TTY TTY
|
||||
PB getter.ProgressTracker
|
||||
}
|
||||
|
||||
var _ packersdk.Ui = new(BasicUi)
|
||||
|
||||
func (rw *BasicUi) Ask(query string) (string, error) {
|
||||
rw.l.Lock()
|
||||
defer rw.l.Unlock()
|
||||
|
||||
if rw.interrupted {
|
||||
return "", ErrInterrupted
|
||||
}
|
||||
|
||||
if rw.TTY == nil {
|
||||
return "", errors.New("no available tty")
|
||||
}
|
||||
sigCh := make(chan os.Signal, 1)
|
||||
signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM)
|
||||
defer signal.Stop(sigCh)
|
||||
|
||||
log.Printf("ui: ask: %s", query)
|
||||
if query != "" {
|
||||
if _, err := fmt.Fprint(rw.Writer, query+" "); err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
result := make(chan string, 1)
|
||||
go func() {
|
||||
line, err := rw.TTY.ReadString()
|
||||
if err != nil {
|
||||
log.Printf("ui: scan err: %s", err)
|
||||
return
|
||||
}
|
||||
result <- strings.TrimSpace(line)
|
||||
}()
|
||||
|
||||
select {
|
||||
case line := <-result:
|
||||
return line, nil
|
||||
case <-sigCh:
|
||||
// Print a newline so that any further output starts properly
|
||||
// on a new line.
|
||||
fmt.Fprintln(rw.Writer)
|
||||
|
||||
// Mark that we were interrupted so future Ask calls fail.
|
||||
rw.interrupted = true
|
||||
|
||||
return "", ErrInterrupted
|
||||
}
|
||||
}
|
||||
|
||||
func (rw *BasicUi) Say(message string) {
|
||||
rw.l.Lock()
|
||||
defer rw.l.Unlock()
|
||||
|
||||
// Use packersdk.LogSecretFilter to scrub out sensitive variables
|
||||
message = packersdk.LogSecretFilter.FilterString(message)
|
||||
|
||||
log.Printf("ui: %s", message)
|
||||
_, err := fmt.Fprint(rw.Writer, message+"\n")
|
||||
if err != nil {
|
||||
log.Printf("[ERR] Failed to write to UI: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (rw *BasicUi) Message(message string) {
|
||||
rw.l.Lock()
|
||||
defer rw.l.Unlock()
|
||||
|
||||
// Use packersdk.LogSecretFilter to scrub out sensitive variables
|
||||
message = packersdk.LogSecretFilter.FilterString(message)
|
||||
|
||||
log.Printf("ui: %s", message)
|
||||
_, err := fmt.Fprint(rw.Writer, message+"\n")
|
||||
if err != nil {
|
||||
log.Printf("[ERR] Failed to write to UI: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (rw *BasicUi) Error(message string) {
|
||||
rw.l.Lock()
|
||||
defer rw.l.Unlock()
|
||||
|
||||
writer := rw.ErrorWriter
|
||||
if writer == nil {
|
||||
writer = rw.Writer
|
||||
}
|
||||
|
||||
// Use packersdk.LogSecretFilter to scrub out sensitive variables
|
||||
message = packersdk.LogSecretFilter.FilterString(message)
|
||||
|
||||
log.Printf("ui error: %s", message)
|
||||
_, err := fmt.Fprint(writer, message+"\n")
|
||||
if err != nil {
|
||||
log.Printf("[ERR] Failed to write to UI: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (rw *BasicUi) Machine(t string, args ...string) {
|
||||
log.Printf("machine readable: %s %#v", t, args)
|
||||
}
|
||||
|
||||
func (rw *BasicUi) TrackProgress(src string, currentSize, totalSize int64, stream io.ReadCloser) (body io.ReadCloser) {
|
||||
return rw.PB.TrackProgress(src, currentSize, totalSize, stream)
|
||||
}
|
||||
|
||||
// MachineReadableUi is a UI that only outputs machine-readable output
|
||||
// to the given Writer.
|
||||
type MachineReadableUi struct {
|
||||
|
|
|
@ -5,11 +5,13 @@ import (
|
|||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
// This reads the output from the bytes.Buffer in our test object
|
||||
// and then resets the buffer.
|
||||
func readWriter(ui *BasicUi) (result string) {
|
||||
func readWriter(ui *packersdk.BasicUi) (result string) {
|
||||
buffer := ui.Writer.(*bytes.Buffer)
|
||||
result = buffer.String()
|
||||
buffer.Reset()
|
||||
|
@ -17,20 +19,20 @@ func readWriter(ui *BasicUi) (result string) {
|
|||
}
|
||||
|
||||
// Reset the input Reader than add some input to it.
|
||||
func writeReader(ui *BasicUi, input string) {
|
||||
func writeReader(ui *packersdk.BasicUi, input string) {
|
||||
buffer := ui.Reader.(*bytes.Buffer)
|
||||
buffer.WriteString(input)
|
||||
}
|
||||
|
||||
func readErrorWriter(ui *BasicUi) (result string) {
|
||||
func readErrorWriter(ui *packersdk.BasicUi) (result string) {
|
||||
buffer := ui.ErrorWriter.(*bytes.Buffer)
|
||||
result = buffer.String()
|
||||
buffer.Reset()
|
||||
return
|
||||
}
|
||||
|
||||
func testUi() *BasicUi {
|
||||
return &BasicUi{
|
||||
func testUi() *packersdk.BasicUi {
|
||||
return &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
ErrorWriter: new(bytes.Buffer),
|
||||
|
@ -147,7 +149,7 @@ func TestTargetedUI(t *testing.T) {
|
|||
func TestColoredUi_ImplUi(t *testing.T) {
|
||||
var raw interface{}
|
||||
raw = &ColoredUi{}
|
||||
if _, ok := raw.(Ui); !ok {
|
||||
if _, ok := raw.(packersdk.Ui); !ok {
|
||||
t.Fatalf("ColoredUi must implement Ui")
|
||||
}
|
||||
}
|
||||
|
@ -155,15 +157,15 @@ func TestColoredUi_ImplUi(t *testing.T) {
|
|||
func TestTargetedUI_ImplUi(t *testing.T) {
|
||||
var raw interface{}
|
||||
raw = &TargetedUI{}
|
||||
if _, ok := raw.(Ui); !ok {
|
||||
if _, ok := raw.(packersdk.Ui); !ok {
|
||||
t.Fatalf("TargetedUI must implement Ui")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBasicUi_ImplUi(t *testing.T) {
|
||||
var raw interface{}
|
||||
raw = &BasicUi{}
|
||||
if _, ok := raw.(Ui); !ok {
|
||||
raw = &packersdk.BasicUi{}
|
||||
if _, ok := raw.(packersdk.Ui); !ok {
|
||||
t.Fatalf("BasicUi must implement Ui")
|
||||
}
|
||||
}
|
||||
|
@ -250,7 +252,7 @@ func TestBasicUi_Ask(t *testing.T) {
|
|||
func TestMachineReadableUi_ImplUi(t *testing.T) {
|
||||
var raw interface{}
|
||||
raw = &MachineReadableUi{}
|
||||
if _, ok := raw.(Ui); !ok {
|
||||
if _, ok := raw.(packersdk.Ui); !ok {
|
||||
t.Fatalf("MachineReadableUi must implement Ui")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,8 +11,8 @@ import (
|
|||
dockerimport "github.com/hashicorp/packer/post-processor/docker-import"
|
||||
)
|
||||
|
||||
func testUi() *packer.BasicUi {
|
||||
return &packer.BasicUi{
|
||||
func testUi() *packersdk.BasicUi {
|
||||
return &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ func TestPostProcessor_ImplementsPostProcessor(t *testing.T) {
|
|||
func TestPostProcessor_PostProcess(t *testing.T) {
|
||||
driver := &docker.MockDriver{}
|
||||
p := &PostProcessor{Driver: driver}
|
||||
artifact := &packer.MockArtifact{
|
||||
artifact := &packersdk.MockArtifact{
|
||||
BuilderIdValue: dockerimport.BuilderId,
|
||||
IdValue: "foo/bar",
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ func TestPostProcessor_PostProcess(t *testing.T) {
|
|||
func TestPostProcessor_PostProcess_portInName(t *testing.T) {
|
||||
driver := &docker.MockDriver{}
|
||||
p := &PostProcessor{Driver: driver}
|
||||
artifact := &packer.MockArtifact{
|
||||
artifact := &packersdk.MockArtifact{
|
||||
BuilderIdValue: dockerimport.BuilderId,
|
||||
IdValue: "localhost:5000/foo/bar",
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ func TestPostProcessor_PostProcess_portInName(t *testing.T) {
|
|||
func TestPostProcessor_PostProcess_tags(t *testing.T) {
|
||||
driver := &docker.MockDriver{}
|
||||
p := &PostProcessor{Driver: driver}
|
||||
artifact := &packer.MockArtifact{
|
||||
artifact := &packersdk.MockArtifact{
|
||||
BuilderIdValue: dockerimport.BuilderId,
|
||||
IdValue: "hashicorp/ubuntu:precise",
|
||||
}
|
||||
|
|
|
@ -28,8 +28,8 @@ func testPP(t *testing.T) *PostProcessor {
|
|||
return &p
|
||||
}
|
||||
|
||||
func testUi() *packer.BasicUi {
|
||||
return &packer.BasicUi{
|
||||
func testUi() *packersdk.BasicUi {
|
||||
return &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ func TestPostProcessor_PostProcess(t *testing.T) {
|
|||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
artifact := &packer.MockArtifact{
|
||||
artifact := &packersdk.MockArtifact{
|
||||
BuilderIdValue: dockerimport.BuilderId,
|
||||
IdValue: "1234567890abcdef",
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ func TestPostProcessor_PostProcess_Force(t *testing.T) {
|
|||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
artifact := &packer.MockArtifact{
|
||||
artifact := &packersdk.MockArtifact{
|
||||
BuilderIdValue: dockerimport.BuilderId,
|
||||
IdValue: "1234567890abcdef",
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ func TestPostProcessor_PostProcess_NoTag(t *testing.T) {
|
|||
t.Fatalf("err %s", err)
|
||||
}
|
||||
|
||||
artifact := &packer.MockArtifact{BuilderIdValue: dockerimport.BuilderId, IdValue: "1234567890abcdef"}
|
||||
artifact := &packersdk.MockArtifact{BuilderIdValue: dockerimport.BuilderId, IdValue: "1234567890abcdef"}
|
||||
|
||||
result, keep, forceOverride, err := p.PostProcess(context.Background(), testUi(), artifact)
|
||||
if _, ok := result.(packersdk.Artifact); !ok {
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
@ -229,7 +230,7 @@ func TestPostProcessor_Configure_checkAccessTokenIsNotRequiredForOverridenVagran
|
|||
}
|
||||
|
||||
func TestPostProcessor_PostProcess_checkArtifactType(t *testing.T) {
|
||||
artifact := &packer.MockArtifact{
|
||||
artifact := &packersdk.MockArtifact{
|
||||
BuilderIdValue: "invalid.builder",
|
||||
}
|
||||
|
||||
|
@ -247,7 +248,7 @@ func TestPostProcessor_PostProcess_checkArtifactType(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestPostProcessor_PostProcess_checkArtifactFileIsBox(t *testing.T) {
|
||||
artifact := &packer.MockArtifact{
|
||||
artifact := &packersdk.MockArtifact{
|
||||
BuilderIdValue: "mitchellh.post-processor.vagrant", // good
|
||||
FilesValue: []string{"invalid.boxfile"}, // should have .box extension
|
||||
}
|
||||
|
@ -278,7 +279,7 @@ func TestPostProcessor_PostProcess_uploadsAndReleases(t *testing.T) {
|
|||
}
|
||||
defer os.Remove(boxfile.Name())
|
||||
|
||||
artifact := &packer.MockArtifact{
|
||||
artifact := &packersdk.MockArtifact{
|
||||
BuilderIdValue: "mitchellh.post-processor.vagrant",
|
||||
FilesValue: []string{boxfile.Name()},
|
||||
}
|
||||
|
@ -325,7 +326,7 @@ func TestPostProcessor_PostProcess_uploadsAndNoRelease(t *testing.T) {
|
|||
}
|
||||
defer os.Remove(boxfile.Name())
|
||||
|
||||
artifact := &packer.MockArtifact{
|
||||
artifact := &packersdk.MockArtifact{
|
||||
BuilderIdValue: "mitchellh.post-processor.vagrant",
|
||||
FilesValue: []string{boxfile.Name()},
|
||||
}
|
||||
|
@ -373,7 +374,7 @@ func TestPostProcessor_PostProcess_uploadsDirectAndReleases(t *testing.T) {
|
|||
}
|
||||
defer os.Remove(boxfile.Name())
|
||||
|
||||
artifact := &packer.MockArtifact{
|
||||
artifact := &packersdk.MockArtifact{
|
||||
BuilderIdValue: "mitchellh.post-processor.vagrant",
|
||||
FilesValue: []string{boxfile.Name()},
|
||||
}
|
||||
|
@ -416,8 +417,8 @@ func TestPostProcessor_PostProcess_uploadsDirectAndReleases(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func testUi() *packer.BasicUi {
|
||||
return &packer.BasicUi{
|
||||
func testUi() *packersdk.BasicUi {
|
||||
return &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func TestAWSProvider_impl(t *testing.T) {
|
||||
|
@ -22,7 +22,7 @@ func TestAWSProvider_KeepInputArtifact(t *testing.T) {
|
|||
func TestAWSProvider_ArtifactId(t *testing.T) {
|
||||
p := new(AWSProvider)
|
||||
ui := testUi()
|
||||
artifact := &packer.MockArtifact{
|
||||
artifact := &packersdk.MockArtifact{
|
||||
IdValue: "us-east-1:ami-1234",
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func TestAzureProvider_impl(t *testing.T) {
|
||||
|
@ -22,7 +22,7 @@ func TestAzureProvider_KeepInputArtifact(t *testing.T) {
|
|||
func TestAzureProvider_ManagedImage(t *testing.T) {
|
||||
p := new(AzureProvider)
|
||||
ui := testUi()
|
||||
artifact := &packer.MockArtifact{
|
||||
artifact := &packersdk.MockArtifact{
|
||||
StringValue: `Azure.ResourceManagement.VMImage:
|
||||
|
||||
OSType: Linux
|
||||
|
@ -58,7 +58,7 @@ ManagedImageLocation: westus`,
|
|||
func TestAzureProvider_VHD(t *testing.T) {
|
||||
p := new(AzureProvider)
|
||||
ui := testUi()
|
||||
artifact := &packer.MockArtifact{
|
||||
artifact := &packersdk.MockArtifact{
|
||||
IdValue: "https://packerbuildswest.blob.core.windows.net/system/Microsoft.Compute/Images/images/packer-osDisk.96ed2120-591d-4900-95b0-ee8e985f2213.vhd",
|
||||
StringValue: `Azure.ResourceManagement.VMImage:
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func TestDigitalOceanProvider_impl(t *testing.T) {
|
||||
|
@ -22,7 +22,7 @@ func TestDigitalOceanProvider_KeepInputArtifact(t *testing.T) {
|
|||
func TestDigitalOceanProvider_ArtifactId(t *testing.T) {
|
||||
p := new(DigitalOceanProvider)
|
||||
ui := testUi()
|
||||
artifact := &packer.MockArtifact{
|
||||
artifact := &packersdk.MockArtifact{
|
||||
IdValue: "San Francisco:42",
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func TestGoogleProvider_impl(t *testing.T) {
|
||||
|
@ -22,7 +22,7 @@ func TestGoogleProvider_KeepInputArtifact(t *testing.T) {
|
|||
func TestGoogleProvider_ArtifactId(t *testing.T) {
|
||||
p := new(GoogleProvider)
|
||||
ui := testUi()
|
||||
artifact := &packer.MockArtifact{
|
||||
artifact := &packersdk.MockArtifact{
|
||||
IdValue: "packer-1234",
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func testConfig() map[string]interface{} {
|
||||
|
@ -25,8 +26,8 @@ func testPP(t *testing.T) *PostProcessor {
|
|||
return &p
|
||||
}
|
||||
|
||||
func testUi() *packer.BasicUi {
|
||||
return &packer.BasicUi{
|
||||
func testUi() *packersdk.BasicUi {
|
||||
return &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
}
|
||||
|
@ -183,7 +184,7 @@ func TestPostProcessorPrepare_ProviderOverrideExists(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestPostProcessorPostProcess_badId(t *testing.T) {
|
||||
artifact := &packer.MockArtifact{
|
||||
artifact := &packersdk.MockArtifact{
|
||||
BuilderIdValue: "invalid.packer",
|
||||
}
|
||||
|
||||
|
@ -214,7 +215,7 @@ func TestPostProcessorPostProcess_vagrantfileUserVariable(t *testing.T) {
|
|||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
a := &packer.MockArtifact{
|
||||
a := &packersdk.MockArtifact{
|
||||
BuilderIdValue: "packer.parallels",
|
||||
}
|
||||
a2, _, _, err := p.PostProcess(context.Background(), testUi(), a)
|
||||
|
|
|
@ -368,13 +368,13 @@ func testProvisionerProvisionDockerWithPlaybookFiles(t *testing.T, templateStrin
|
|||
hooks := map[string][]packersdk.Hook{}
|
||||
hooks[packersdk.HookProvision] = []packersdk.Hook{
|
||||
&packer.ProvisionHook{
|
||||
Provisioners: []*packersdk.HookedProvisioner{
|
||||
Provisioners: []*packer.HookedProvisioner{
|
||||
{Provisioner: ansible, Config: nil, TypeName: ""},
|
||||
{Provisioner: download, Config: nil, TypeName: ""},
|
||||
},
|
||||
},
|
||||
}
|
||||
hook := &packer.DispatchHook{Mapping: hooks}
|
||||
hook := &packersdk.DispatchHook{Mapping: hooks}
|
||||
|
||||
artifact, err := builder.Run(context.Background(), ui, hook)
|
||||
if err != nil {
|
||||
|
|
|
@ -16,6 +16,7 @@ import (
|
|||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep/commonsteps"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
confighelper "github.com/hashicorp/packer/packer-plugin-sdk/template/config"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
@ -346,8 +347,8 @@ func TestAnsibleLongMessages(t *testing.T) {
|
|||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
comm := &packer.MockCommunicator{}
|
||||
ui := &packer.BasicUi{
|
||||
comm := &packersdk.MockCommunicator{}
|
||||
ui := &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
}
|
||||
|
@ -766,8 +767,8 @@ func TestUseProxy(t *testing.T) {
|
|||
p.setupAdapterFunc = l.setupAdapter
|
||||
p.executeAnsibleFunc = l.executeAnsible
|
||||
ctx := context.TODO()
|
||||
comm := new(packer.MockCommunicator)
|
||||
ui := &packer.BasicUi{
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
ui := &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func testConfig() map[string]interface{} {
|
||||
|
@ -241,8 +242,8 @@ func TestProvisioner_createDir(t *testing.T) {
|
|||
config["prevent_sudo"] = !sudo
|
||||
|
||||
p := &Provisioner{}
|
||||
comm := &packer.MockCommunicator{}
|
||||
ui := &packer.BasicUi{
|
||||
comm := &packersdk.MockCommunicator{}
|
||||
ui := &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
}
|
||||
|
@ -272,8 +273,8 @@ func TestProvisioner_removeDir(t *testing.T) {
|
|||
config["prevent_sudo"] = !sudo
|
||||
|
||||
p := &Provisioner{}
|
||||
comm := &packer.MockCommunicator{}
|
||||
ui := &packer.BasicUi{
|
||||
comm := &packersdk.MockCommunicator{}
|
||||
ui := &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func testConfig() map[string]interface{} {
|
||||
|
@ -124,11 +125,11 @@ func TestProvisionerProvision_SendsFile(t *testing.T) {
|
|||
}
|
||||
|
||||
b := bytes.NewBuffer(nil)
|
||||
ui := &packer.BasicUi{
|
||||
ui := &packersdk.BasicUi{
|
||||
Writer: b,
|
||||
PB: &packer.NoopProgressTracker{},
|
||||
}
|
||||
comm := &packer.MockCommunicator{}
|
||||
comm := &packersdk.MockCommunicator{}
|
||||
err = p.Provision(context.Background(), ui, comm, make(map[string]interface{}))
|
||||
if err != nil {
|
||||
t.Fatalf("should successfully provision: %s", err)
|
||||
|
@ -183,11 +184,11 @@ func TestProvisionerProvision_SendsFileMultipleFiles(t *testing.T) {
|
|||
}
|
||||
|
||||
b := bytes.NewBuffer(nil)
|
||||
ui := &packer.BasicUi{
|
||||
ui := &packersdk.BasicUi{
|
||||
Writer: b,
|
||||
PB: &packer.NoopProgressTracker{},
|
||||
}
|
||||
comm := &packer.MockCommunicator{}
|
||||
comm := &packersdk.MockCommunicator{}
|
||||
err = p.Provision(context.Background(), ui, comm, make(map[string]interface{}))
|
||||
if err != nil {
|
||||
t.Fatalf("should successfully provision: %s", err)
|
||||
|
@ -253,11 +254,11 @@ func TestProvisionerProvision_SendsFileMultipleDirs(t *testing.T) {
|
|||
}
|
||||
|
||||
b := bytes.NewBuffer(nil)
|
||||
ui := &packer.BasicUi{
|
||||
ui := &packersdk.BasicUi{
|
||||
Writer: b,
|
||||
PB: &packer.NoopProgressTracker{},
|
||||
}
|
||||
comm := &packer.MockCommunicator{}
|
||||
comm := &packersdk.MockCommunicator{}
|
||||
err = p.Provision(context.Background(), ui, comm, make(map[string]interface{}))
|
||||
if err != nil {
|
||||
t.Fatalf("should successfully provision: %s", err)
|
||||
|
@ -305,11 +306,11 @@ func TestProvisionerProvision_SendsFileMultipleFilesToFolder(t *testing.T) {
|
|||
}
|
||||
|
||||
b := bytes.NewBuffer(nil)
|
||||
ui := &packer.BasicUi{
|
||||
ui := &packersdk.BasicUi{
|
||||
Writer: b,
|
||||
PB: &packer.NoopProgressTracker{},
|
||||
}
|
||||
comm := &packer.MockCommunicator{}
|
||||
comm := &packersdk.MockCommunicator{}
|
||||
err = p.Provision(context.Background(), ui, comm, make(map[string]interface{}))
|
||||
if err != nil {
|
||||
t.Fatalf("should successfully provision: %s", err)
|
||||
|
@ -363,11 +364,11 @@ func TestProvisionDownloadMkdirAll(t *testing.T) {
|
|||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
b := bytes.NewBuffer(nil)
|
||||
ui := &packer.BasicUi{
|
||||
ui := &packersdk.BasicUi{
|
||||
Writer: b,
|
||||
PB: &packer.NoopProgressTracker{},
|
||||
}
|
||||
comm := &packer.MockCommunicator{}
|
||||
comm := &packersdk.MockCommunicator{}
|
||||
err = p.ProvisionDownload(ui, comm)
|
||||
if err != nil {
|
||||
t.Fatalf("should successfully provision: %s", err)
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"github.com/hashicorp/packer/command"
|
||||
"github.com/hashicorp/packer/helper/tests/acc"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
"github.com/hashicorp/packer/provisioner/powershell"
|
||||
windowsshellprovisioner "github.com/hashicorp/packer/provisioner/windows-shell"
|
||||
)
|
||||
|
@ -81,7 +82,7 @@ func (s *PowershellProvisionerAccTest) RunTest(c *command.BuildCommand, args []s
|
|||
}
|
||||
|
||||
if code := c.Run(args); code != 0 {
|
||||
ui := c.Meta.Ui.(*packer.BasicUi)
|
||||
ui := c.Meta.Ui.(*packersdk.BasicUi)
|
||||
out := ui.Writer.(*bytes.Buffer)
|
||||
err := ui.ErrorWriter.(*bytes.Buffer)
|
||||
return fmt.Errorf(
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep/commonsteps"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
@ -349,8 +350,8 @@ func TestProvisionerQuote_EnvironmentVars(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func testUi() *packer.BasicUi {
|
||||
return &packer.BasicUi{
|
||||
func testUi() *packersdk.BasicUi {
|
||||
return &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
ErrorWriter: new(bytes.Buffer),
|
||||
|
@ -371,7 +372,7 @@ func TestProvisionerProvision_ValidExitCodes(t *testing.T) {
|
|||
p.config.PackerBuildName = "vmware"
|
||||
p.config.PackerBuilderType = "iso"
|
||||
p.config.ValidExitCodes = []int{0, 200}
|
||||
comm := new(packer.MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
comm.StartExitStatus = 200
|
||||
p.Prepare(config)
|
||||
err := p.Provision(context.Background(), ui, comm, generatedData())
|
||||
|
@ -394,7 +395,7 @@ func TestProvisionerProvision_InvalidExitCodes(t *testing.T) {
|
|||
p.config.PackerBuildName = "vmware"
|
||||
p.config.PackerBuilderType = "iso"
|
||||
p.config.ValidExitCodes = []int{0, 200}
|
||||
comm := new(packer.MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
comm.StartExitStatus = 201 // Invalid!
|
||||
p.Prepare(config)
|
||||
err := p.Provision(context.Background(), ui, comm, generatedData())
|
||||
|
@ -417,7 +418,7 @@ func TestProvisionerProvision_Inline(t *testing.T) {
|
|||
// Defaults provided by Packer - env vars should not appear in cmd
|
||||
p.config.PackerBuildName = "vmware"
|
||||
p.config.PackerBuilderType = "iso"
|
||||
comm := new(packer.MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
_ = p.Prepare(config)
|
||||
|
||||
err := p.Provision(context.Background(), ui, comm, generatedData())
|
||||
|
@ -468,7 +469,7 @@ func TestProvisionerProvision_Scripts(t *testing.T) {
|
|||
ui := testUi()
|
||||
|
||||
p := new(Provisioner)
|
||||
comm := new(packer.MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
p.Prepare(config)
|
||||
err := p.Provision(context.Background(), ui, comm, generatedData())
|
||||
if err != nil {
|
||||
|
@ -505,7 +506,7 @@ func TestProvisionerProvision_ScriptsWithEnvVars(t *testing.T) {
|
|||
config["remote_path"] = "c:/Windows/Temp/script.ps1"
|
||||
|
||||
p := new(Provisioner)
|
||||
comm := new(packer.MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
p.Prepare(config)
|
||||
err := p.Provision(context.Background(), ui, comm, generatedData())
|
||||
if err != nil {
|
||||
|
@ -550,7 +551,7 @@ func TestProvisionerProvision_SkipClean(t *testing.T) {
|
|||
tc := tc
|
||||
p := new(Provisioner)
|
||||
ui := testUi()
|
||||
comm := new(packer.MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
|
||||
config["skip_clean"] = tc.SkipClean
|
||||
if err := p.Prepare(config); err != nil {
|
||||
|
@ -577,14 +578,14 @@ func TestProvisionerProvision_UploadFails(t *testing.T) {
|
|||
ui := testUi()
|
||||
|
||||
p := new(Provisioner)
|
||||
comm := new(packer.ScriptUploadErrorMockCommunicator)
|
||||
comm := new(packersdk.ScriptUploadErrorMockCommunicator)
|
||||
p.Prepare(config)
|
||||
p.config.StartRetryTimeout = 1 * time.Second
|
||||
err := p.Provision(context.Background(), ui, comm, generatedData())
|
||||
if !strings.Contains(err.Error(), packer.ScriptUploadErrorMockCommunicatorError.Error()) {
|
||||
if !strings.Contains(err.Error(), packersdk.ScriptUploadErrorMockCommunicatorError.Error()) {
|
||||
t.Fatalf("expected Provision() error %q to contain %q",
|
||||
err.Error(),
|
||||
packer.ScriptUploadErrorMockCommunicatorError.Error())
|
||||
packersdk.ScriptUploadErrorMockCommunicatorError.Error())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -790,7 +791,7 @@ func TestProvision_createCommandText(t *testing.T) {
|
|||
config := testConfig()
|
||||
config["remote_path"] = "c:/Windows/Temp/script.ps1"
|
||||
p := new(Provisioner)
|
||||
comm := new(packer.MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
p.communicator = comm
|
||||
_ = p.Prepare(config)
|
||||
|
||||
|
@ -821,7 +822,7 @@ func TestProvision_createCommandText(t *testing.T) {
|
|||
|
||||
func TestProvision_uploadEnvVars(t *testing.T) {
|
||||
p := new(Provisioner)
|
||||
comm := new(packer.MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
p.communicator = comm
|
||||
|
||||
flattenedEnvVars := `$env:PACKER_BUILDER_TYPE="footype"; $env:PACKER_BUILD_NAME="foobuild";`
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/template/interpolate"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
@ -479,7 +480,7 @@ func TestProvisionerProvision_extraArguments(t *testing.T) {
|
|||
ui := &packer.MachineReadableUi{
|
||||
Writer: ioutil.Discard,
|
||||
}
|
||||
comm := new(packer.MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
|
||||
extraArguments := []string{
|
||||
"--some-arg=yup",
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"github.com/hashicorp/packer/provisioner/shell"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
|
||||
"github.com/hashicorp/packer/command"
|
||||
)
|
||||
|
@ -51,7 +52,7 @@ func (s *ShellLocalProvisionerAccTest) IsCompatible(builder string, vmOS string)
|
|||
|
||||
func (s *ShellLocalProvisionerAccTest) RunTest(c *command.BuildCommand, args []string) error {
|
||||
if code := c.Run(args); code != 0 {
|
||||
ui := c.Meta.Ui.(*packer.BasicUi)
|
||||
ui := c.Meta.Ui.(*packersdk.BasicUi)
|
||||
out := ui.Writer.(*bytes.Buffer)
|
||||
err := ui.ErrorWriter.(*bytes.Buffer)
|
||||
return fmt.Errorf(
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/hashicorp/packer/provisioner/shell"
|
||||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
|
||||
"github.com/hashicorp/go-uuid"
|
||||
"github.com/hashicorp/packer/command"
|
||||
|
@ -64,7 +65,7 @@ func (s *ShellProvisionerAccTest) RunTest(c *command.BuildCommand, args []string
|
|||
defer testshelper.CleanupFiles(file)
|
||||
|
||||
if code := c.Run(args); code != 0 {
|
||||
ui := c.Meta.Ui.(*packer.BasicUi)
|
||||
ui := c.Meta.Ui.(*packersdk.BasicUi)
|
||||
out := ui.Writer.(*bytes.Buffer)
|
||||
err := ui.ErrorWriter.(*bytes.Buffer)
|
||||
return fmt.Errorf(
|
||||
|
|
|
@ -79,8 +79,8 @@ func TestProvisionerPrepare_InvalidKey(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func testUi() *packer.BasicUi {
|
||||
return &packer.BasicUi{
|
||||
func testUi() *packersdk.BasicUi {
|
||||
return &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
ErrorWriter: new(bytes.Buffer),
|
||||
|
@ -95,7 +95,7 @@ func TestProvisionerProvision_Success(t *testing.T) {
|
|||
p := new(Provisioner)
|
||||
|
||||
// Defaults provided by Packer
|
||||
comm := new(packer.MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
p.Prepare(config)
|
||||
waitForCommunicatorOld := waitForCommunicator
|
||||
waitForCommunicator = func(context.Context, *Provisioner) error {
|
||||
|
@ -131,7 +131,7 @@ func TestProvisionerProvision_CustomCommand(t *testing.T) {
|
|||
config["restart_command"] = expectedCommand
|
||||
|
||||
// Defaults provided by Packer
|
||||
comm := new(packer.MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
p.Prepare(config)
|
||||
waitForCommunicatorOld := waitForCommunicator
|
||||
waitForCommunicator = func(context.Context, *Provisioner) error {
|
||||
|
@ -159,7 +159,7 @@ func TestProvisionerProvision_RestartCommandFail(t *testing.T) {
|
|||
config := testConfig()
|
||||
ui := testUi()
|
||||
p := new(Provisioner)
|
||||
comm := new(packer.MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
comm.StartStderr = "WinRM terminated"
|
||||
comm.StartExitStatus = 1
|
||||
|
||||
|
@ -177,7 +177,7 @@ func TestProvisionerProvision_WaitForRestartFail(t *testing.T) {
|
|||
p := new(Provisioner)
|
||||
|
||||
// Defaults provided by Packer
|
||||
comm := new(packer.MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
p.Prepare(config)
|
||||
waitForCommunicatorOld := waitForCommunicator
|
||||
waitForCommunicator = func(context.Context, *Provisioner) error {
|
||||
|
@ -198,7 +198,7 @@ func TestProvision_waitForRestartTimeout(t *testing.T) {
|
|||
config["restart_timeout"] = "1ms"
|
||||
ui := testUi()
|
||||
p := new(Provisioner)
|
||||
comm := new(packer.MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
var err error
|
||||
|
||||
p.Prepare(config)
|
||||
|
@ -239,7 +239,7 @@ func TestProvision_waitForCommunicator(t *testing.T) {
|
|||
p := new(Provisioner)
|
||||
|
||||
// Defaults provided by Packer
|
||||
comm := new(packer.MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
p.comm = comm
|
||||
p.ui = ui
|
||||
comm.StartStderr = "WinRM terminated"
|
||||
|
@ -268,7 +268,7 @@ func TestProvision_waitForCommunicatorWithCancel(t *testing.T) {
|
|||
p := new(Provisioner)
|
||||
|
||||
// Defaults provided by Packer
|
||||
comm := new(packer.MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
p.comm = comm
|
||||
p.ui = ui
|
||||
retryableSleep = 5 * time.Second
|
||||
|
@ -312,7 +312,7 @@ func TestProvision_Cancel(t *testing.T) {
|
|||
ui := testUi()
|
||||
p := new(Provisioner)
|
||||
|
||||
comm := new(packer.MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
p.Prepare(config)
|
||||
done := make(chan error)
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
|
||||
"github.com/hashicorp/packer/packer"
|
||||
"github.com/hashicorp/packer/packer-plugin-sdk/multistep/commonsteps"
|
||||
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
||||
)
|
||||
|
||||
func testConfig() map[string]interface{} {
|
||||
|
@ -265,8 +266,8 @@ func TestProvisionerQuote_EnvironmentVars(t *testing.T) {
|
|||
|
||||
}
|
||||
|
||||
func testUi() *packer.BasicUi {
|
||||
return &packer.BasicUi{
|
||||
func testUi() *packersdk.BasicUi {
|
||||
return &packersdk.BasicUi{
|
||||
Reader: new(bytes.Buffer),
|
||||
Writer: new(bytes.Buffer),
|
||||
ErrorWriter: new(bytes.Buffer),
|
||||
|
@ -286,7 +287,7 @@ func TestProvisionerProvision_Inline(t *testing.T) {
|
|||
// Defaults provided by Packer
|
||||
p.config.PackerBuildName = "vmware"
|
||||
p.config.PackerBuilderType = "iso"
|
||||
comm := new(packer.MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
p.Prepare(config)
|
||||
|
||||
err := p.Provision(context.Background(), ui, comm, generatedData())
|
||||
|
@ -337,7 +338,7 @@ func TestProvisionerProvision_Scripts(t *testing.T) {
|
|||
ui := testUi()
|
||||
|
||||
p := new(Provisioner)
|
||||
comm := new(packer.MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
p.Prepare(config)
|
||||
err = p.Provision(context.Background(), ui, comm, generatedData())
|
||||
if err != nil {
|
||||
|
@ -376,7 +377,7 @@ func TestProvisionerProvision_ScriptsWithEnvVars(t *testing.T) {
|
|||
config["environment_vars"] = envVars
|
||||
|
||||
p := new(Provisioner)
|
||||
comm := new(packer.MockCommunicator)
|
||||
comm := new(packersdk.MockCommunicator)
|
||||
p.Prepare(config)
|
||||
err = p.Provision(context.Background(), ui, comm, generatedData())
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue