move TestUi func to sdk

This commit is contained in:
Megan Marsh 2020-12-02 10:50:37 -08:00
parent 16bab1daf1
commit 8558d1241f
24 changed files with 88 additions and 79 deletions

View File

@ -9,7 +9,6 @@ import (
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/ec2/ec2iface" "github.com/aws/aws-sdk-go/service/ec2/ec2iface"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer-plugin-sdk/communicator" "github.com/hashicorp/packer/packer-plugin-sdk/communicator"
"github.com/hashicorp/packer/packer-plugin-sdk/multistep" "github.com/hashicorp/packer/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer" packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
@ -240,7 +239,7 @@ func TestRun(t *testing.T) {
volumeId := aws.String("volume-id") volumeId := aws.String("volume-id")
ec2Mock := defaultEc2Mock(instanceId, spotRequestId, volumeId) ec2Mock := defaultEc2Mock(instanceId, spotRequestId, volumeId)
uiMock := packer.TestUi(t) uiMock := packersdk.TestUi(t)
state := tStateSpot() state := tStateSpot()
state.Put("ec2", ec2Mock) state.Put("ec2", ec2Mock)
@ -332,7 +331,7 @@ func TestRun_NoSpotTags(t *testing.T) {
volumeId := aws.String("volume-id") volumeId := aws.String("volume-id")
ec2Mock := defaultEc2Mock(instanceId, spotRequestId, volumeId) ec2Mock := defaultEc2Mock(instanceId, spotRequestId, volumeId)
uiMock := packer.TestUi(t) uiMock := packersdk.TestUi(t)
state := tStateSpot() state := tStateSpot()
state.Put("ec2", ec2Mock) state.Put("ec2", ec2Mock)

View File

@ -9,8 +9,8 @@ import (
"testing" "testing"
"github.com/hashicorp/packer/builder/azure/common/client" "github.com/hashicorp/packer/builder/azure/common/client"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer-plugin-sdk/multistep" "github.com/hashicorp/packer/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-12-01/compute" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-12-01/compute"
"github.com/Azure/go-autorest/autorest" "github.com/Azure/go-autorest/autorest"
@ -116,7 +116,7 @@ func TestStepCreateImage_Run(t *testing.T) {
state.Put("azureclient", &client.AzureClientSetMock{ state.Put("azureclient", &client.AzureClientSetMock{
ImagesClientMock: ic, ImagesClientMock: ic,
}) })
state.Put("ui", packer.TestUi(t)) state.Put("ui", packersdk.TestUi(t))
state.Put(stateBagKey_Diskset, tt.diskset) state.Put(stateBagKey_Diskset, tt.diskset)
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {

View File

@ -10,8 +10,8 @@ import (
"testing" "testing"
"github.com/hashicorp/packer/builder/azure/common/client" "github.com/hashicorp/packer/builder/azure/common/client"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer-plugin-sdk/multistep" "github.com/hashicorp/packer/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-12-01/compute" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-12-01/compute"
"github.com/Azure/go-autorest/autorest" "github.com/Azure/go-autorest/autorest"
@ -224,7 +224,7 @@ func TestStepCreateNewDisk_Run(t *testing.T) {
DisksClientMock: m, DisksClientMock: m,
GalleryImageVersionsClientMock: giv, GalleryImageVersionsClientMock: giv,
}) })
state.Put("ui", packer.TestUi(t)) state.Put("ui", packersdk.TestUi(t))
if got := s.Run(context.TODO(), state); !reflect.DeepEqual(got, tt.want) { if got := s.Run(context.TODO(), state); !reflect.DeepEqual(got, tt.want) {
t.Errorf("StepCreateNewDisk.Run() = %v, want %v", got, tt.want) t.Errorf("StepCreateNewDisk.Run() = %v, want %v", got, tt.want)

View File

@ -9,8 +9,8 @@ import (
"testing" "testing"
"github.com/hashicorp/packer/builder/azure/common/client" "github.com/hashicorp/packer/builder/azure/common/client"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer-plugin-sdk/multistep" "github.com/hashicorp/packer/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-12-01/compute" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-12-01/compute"
"github.com/Azure/go-autorest/autorest" "github.com/Azure/go-autorest/autorest"
@ -126,7 +126,7 @@ func TestStepCreateSharedImageVersion_Run(t *testing.T) {
state.Put("azureclient", &client.AzureClientSetMock{ state.Put("azureclient", &client.AzureClientSetMock{
GalleryImageVersionsClientMock: m, GalleryImageVersionsClientMock: m,
}) })
state.Put("ui", packer.TestUi(t)) state.Put("ui", packersdk.TestUi(t))
state.Put(stateBagKey_Snapshotset, tt.snapshotset) state.Put(stateBagKey_Snapshotset, tt.snapshotset)
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {

View File

@ -11,8 +11,8 @@ import (
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-12-01/compute" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-12-01/compute"
"github.com/Azure/go-autorest/autorest" "github.com/Azure/go-autorest/autorest"
"github.com/hashicorp/packer/builder/azure/common/client" "github.com/hashicorp/packer/builder/azure/common/client"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer-plugin-sdk/multistep" "github.com/hashicorp/packer/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
) )
func TestStepCreateSnapshot_Run(t *testing.T) { func TestStepCreateSnapshot_Run(t *testing.T) {
@ -101,7 +101,7 @@ func TestStepCreateSnapshot_Run(t *testing.T) {
state.Put("azureclient", &client.AzureClientSetMock{ state.Put("azureclient", &client.AzureClientSetMock{
SnapshotsClientMock: m, SnapshotsClientMock: m,
}) })
state.Put("ui", packer.TestUi(t)) state.Put("ui", packersdk.TestUi(t))
state.Put(stateBagKey_Diskset, tt.diskset) state.Put(stateBagKey_Diskset, tt.diskset)
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
@ -136,7 +136,7 @@ func TestStepCreateSnapshot_Cleanup_skipped(t *testing.T) {
state.Put("azureclient", &client.AzureClientSetMock{ state.Put("azureclient", &client.AzureClientSetMock{
SnapshotsClientMock: m, SnapshotsClientMock: m,
}) })
state.Put("ui", packer.TestUi(t)) state.Put("ui", packersdk.TestUi(t))
s := &StepCreateSnapshotset{ s := &StepCreateSnapshotset{
SkipCleanup: true, SkipCleanup: true,
@ -185,7 +185,7 @@ func TestStepCreateSnapshot_Cleanup(t *testing.T) {
state.Put("azureclient", &client.AzureClientSetMock{ state.Put("azureclient", &client.AzureClientSetMock{
SnapshotsClientMock: m, SnapshotsClientMock: m,
}) })
state.Put("ui", packer.TestUi(t)) state.Put("ui", packersdk.TestUi(t))
s := &StepCreateSnapshotset{ s := &StepCreateSnapshotset{
SkipCleanup: false, SkipCleanup: false,

View File

@ -9,8 +9,8 @@ import (
"testing" "testing"
"github.com/hashicorp/packer/builder/azure/common/client" "github.com/hashicorp/packer/builder/azure/common/client"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer-plugin-sdk/multistep" "github.com/hashicorp/packer/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-12-01/compute" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-12-01/compute"
"github.com/Azure/go-autorest/autorest" "github.com/Azure/go-autorest/autorest"
@ -164,7 +164,7 @@ func TestStepVerifySharedImageDestination_Run(t *testing.T) {
GalleryImagesClientMock: gi, GalleryImagesClientMock: gi,
GalleryImageVersionsClientMock: giv, GalleryImageVersionsClientMock: giv,
}) })
state.Put("ui", packer.TestUi(t)) state.Put("ui", packersdk.TestUi(t))
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
s := &StepVerifySharedImageDestination{ s := &StepVerifySharedImageDestination{

View File

@ -12,8 +12,8 @@ import (
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-12-01/compute" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-12-01/compute"
"github.com/Azure/go-autorest/autorest" "github.com/Azure/go-autorest/autorest"
"github.com/hashicorp/packer/builder/azure/common/client" "github.com/hashicorp/packer/builder/azure/common/client"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer-plugin-sdk/multistep" "github.com/hashicorp/packer/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
) )
func TestStepVerifySharedImageSource_Run(t *testing.T) { func TestStepVerifySharedImageSource_Run(t *testing.T) {
@ -163,7 +163,7 @@ func TestStepVerifySharedImageSource_Run(t *testing.T) {
GalleryImageVersionsClientMock: giv, GalleryImageVersionsClientMock: giv,
GalleryImagesClientMock: gi, GalleryImagesClientMock: gi,
}) })
state.Put("ui", packer.TestUi(t)) state.Put("ui", packersdk.TestUi(t))
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
s := &StepVerifySharedImageSource{ s := &StepVerifySharedImageSource{

View File

@ -18,7 +18,7 @@ import (
// TestUploadDownload verifies that basic upload / download functionality works // TestUploadDownload verifies that basic upload / download functionality works
func TestUploadDownload(t *testing.T) { func TestUploadDownload(t *testing.T) {
ui := packer.TestUi(t) ui := packersdk.TestUi(t)
tpl, err := template.Parse(strings.NewReader(dockerBuilderConfig)) tpl, err := template.Parse(strings.NewReader(dockerBuilderConfig))
if err != nil { if err != nil {
@ -101,7 +101,7 @@ func TestUploadDownload(t *testing.T) {
// need to use github.com/cbednarski/rerun to verify since this problem occurs // need to use github.com/cbednarski/rerun to verify since this problem occurs
// only intermittently. // only intermittently.
func TestLargeDownload(t *testing.T) { func TestLargeDownload(t *testing.T) {
ui := packer.TestUi(t) ui := packersdk.TestUi(t)
tpl, err := template.Parse(strings.NewReader(dockerLargeBuilderConfig)) tpl, err := template.Parse(strings.NewReader(dockerLargeBuilderConfig))
if err != nil { if err != nil {
@ -205,7 +205,7 @@ func TestLargeDownload(t *testing.T) {
// TestFixUploadOwner verifies that owner of uploaded files is the user the container is running as. // TestFixUploadOwner verifies that owner of uploaded files is the user the container is running as.
func TestFixUploadOwner(t *testing.T) { func TestFixUploadOwner(t *testing.T) {
ui := packer.TestUi(t) ui := packersdk.TestUi(t)
tpl, err := template.Parse(strings.NewReader(testFixUploadOwnerTemplate)) tpl, err := template.Parse(strings.NewReader(testFixUploadOwnerTemplate))
if err != nil { if err != nil {

View File

@ -602,7 +602,7 @@ func TestUserVariablesInBootCommand(t *testing.T) {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
ui := packer.TestUi(t) ui := packersdk.TestUi(t)
hook := &packersdk.MockHook{} hook := &packersdk.MockHook{}
driver := &hypervcommon.DriverMock{} driver := &hypervcommon.DriverMock{}

View File

@ -494,7 +494,7 @@ func TestUserVariablesInBootCommand(t *testing.T) {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
ui := packer.TestUi(t) ui := packersdk.TestUi(t)
hook := &packersdk.MockHook{} hook := &packersdk.MockHook{}
driver := &hypervcommon.DriverMock{} driver := &hypervcommon.DriverMock{}

View File

@ -6,8 +6,8 @@ import (
"testing" "testing"
"github.com/Telmate/proxmox-api-go/proxmox" "github.com/Telmate/proxmox-api-go/proxmox"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer-plugin-sdk/multistep" "github.com/hashicorp/packer/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
) )
type converterMock struct { type converterMock struct {
@ -79,7 +79,7 @@ func TestConvertToTemplate(t *testing.T) {
} }
state := new(multistep.BasicStateBag) state := new(multistep.BasicStateBag)
state.Put("ui", packer.TestUi(t)) state.Put("ui", packersdk.TestUi(t))
state.Put("vmRef", proxmox.NewVmRef(vmid)) state.Put("vmRef", proxmox.NewVmRef(vmid))
state.Put("proxmoxClient", converter) state.Put("proxmoxClient", converter)

View File

@ -6,8 +6,8 @@ import (
"testing" "testing"
"github.com/Telmate/proxmox-api-go/proxmox" "github.com/Telmate/proxmox-api-go/proxmox"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer-plugin-sdk/multistep" "github.com/hashicorp/packer/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
) )
type finalizerMock struct { type finalizerMock struct {
@ -157,7 +157,7 @@ func TestTemplateFinalize(t *testing.T) {
} }
state := new(multistep.BasicStateBag) state := new(multistep.BasicStateBag)
state.Put("ui", packer.TestUi(t)) state.Put("ui", packersdk.TestUi(t))
state.Put("config", c.builderConfig) state.Put("config", c.builderConfig)
state.Put("vmRef", proxmox.NewVmRef(1)) state.Put("vmRef", proxmox.NewVmRef(1))
state.Put("proxmoxClient", finalizer) state.Put("proxmoxClient", finalizer)

View File

@ -5,8 +5,8 @@ import (
"testing" "testing"
"github.com/Telmate/proxmox-api-go/proxmox" "github.com/Telmate/proxmox-api-go/proxmox"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer-plugin-sdk/multistep" "github.com/hashicorp/packer/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
) )
type startedVMCleanerMock struct { type startedVMCleanerMock struct {
@ -85,7 +85,7 @@ func TestCleanupStartVM(t *testing.T) {
} }
state := new(multistep.BasicStateBag) state := new(multistep.BasicStateBag)
state.Put("ui", packer.TestUi(t)) state.Put("ui", packersdk.TestUi(t))
state.Put("proxmoxClient", cleaner) state.Put("proxmoxClient", cleaner)
if c.setVmRef { if c.setVmRef {
state.Put("vmRef", proxmox.NewVmRef(1)) state.Put("vmRef", proxmox.NewVmRef(1))

View File

@ -7,9 +7,9 @@ import (
"testing" "testing"
"github.com/Telmate/proxmox-api-go/proxmox" "github.com/Telmate/proxmox-api-go/proxmox"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer-plugin-sdk/bootcommand" "github.com/hashicorp/packer/packer-plugin-sdk/bootcommand"
"github.com/hashicorp/packer/packer-plugin-sdk/multistep" "github.com/hashicorp/packer/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
) )
type commandTyperMock struct { type commandTyperMock struct {
@ -128,7 +128,7 @@ func TestTypeBootCommand(t *testing.T) {
} }
state := new(multistep.BasicStateBag) state := new(multistep.BasicStateBag)
state.Put("ui", packer.TestUi(t)) state.Put("ui", packersdk.TestUi(t))
state.Put("config", c.builderConfig) state.Put("config", c.builderConfig)
state.Put("http_port", int(0)) state.Put("http_port", int(0))
state.Put("vmRef", proxmox.NewVmRef(1)) state.Put("vmRef", proxmox.NewVmRef(1))

View File

@ -6,8 +6,8 @@ import (
"testing" "testing"
"github.com/Telmate/proxmox-api-go/proxmox" "github.com/Telmate/proxmox-api-go/proxmox"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer-plugin-sdk/multistep" "github.com/hashicorp/packer/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
) )
type finalizerMock struct { type finalizerMock struct {
@ -116,7 +116,7 @@ func TestISOTemplateFinalize(t *testing.T) {
} }
state := new(multistep.BasicStateBag) state := new(multistep.BasicStateBag)
state.Put("ui", packer.TestUi(t)) state.Put("ui", packersdk.TestUi(t))
state.Put("iso-config", c.builderConfig) state.Put("iso-config", c.builderConfig)
state.Put("vmRef", proxmox.NewVmRef(1)) state.Put("vmRef", proxmox.NewVmRef(1))
state.Put("proxmoxClient", finalizer) state.Put("proxmoxClient", finalizer)

View File

@ -6,9 +6,9 @@ import (
"io" "io"
"testing" "testing"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer-plugin-sdk/multistep" "github.com/hashicorp/packer/packer-plugin-sdk/multistep"
"github.com/hashicorp/packer/packer-plugin-sdk/multistep/commonsteps" "github.com/hashicorp/packer/packer-plugin-sdk/multistep/commonsteps"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
) )
type uploaderMock struct { type uploaderMock struct {
@ -105,7 +105,7 @@ func TestUploadISO(t *testing.T) {
m := &uploaderMock{fail: c.failUpload} m := &uploaderMock{fail: c.failUpload}
state := new(multistep.BasicStateBag) state := new(multistep.BasicStateBag)
state.Put("ui", packer.TestUi(t)) state.Put("ui", packersdk.TestUi(t))
state.Put("iso-config", c.builderConfig) state.Put("iso-config", c.builderConfig)
state.Put(downloadPathKey, c.downloadPath) state.Put(downloadPathKey, c.downloadPath)
state.Put("proxmoxClient", m) state.Put("proxmoxClient", m)

View File

@ -4,14 +4,14 @@ import (
"context" "context"
"testing" "testing"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer-plugin-sdk/multistep" "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/assert"
) )
func copyTestState(t *testing.T, d *DriverMock) multistep.StateBag { func copyTestState(t *testing.T, d *DriverMock) multistep.StateBag {
state := new(multistep.BasicStateBag) state := new(multistep.BasicStateBag)
state.Put("ui", packer.TestUi(t)) state.Put("ui", packersdk.TestUi(t))
state.Put("driver", d) state.Put("driver", d)
state.Put("iso_path", "example_source.qcow2") state.Put("iso_path", "example_source.qcow2")

View File

@ -4,10 +4,10 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer-plugin-sdk/communicator" "github.com/hashicorp/packer/packer-plugin-sdk/communicator"
"github.com/hashicorp/packer/packer-plugin-sdk/multistep" "github.com/hashicorp/packer/packer-plugin-sdk/multistep"
"github.com/hashicorp/packer/packer-plugin-sdk/multistep/commonsteps" "github.com/hashicorp/packer/packer-plugin-sdk/multistep/commonsteps"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -92,7 +92,7 @@ func Test_UserOverrides(t *testing.T) {
step := &stepRun{ step := &stepRun{
atLeastVersion2: true, atLeastVersion2: true,
ui: packer.TestUi(t), ui: packersdk.TestUi(t),
} }
args, err := step.getCommandArgs(tc.Config, state) args, err := step.getCommandArgs(tc.Config, state)
if err != nil { if err != nil {
@ -130,7 +130,7 @@ func Test_DriveAndDeviceArgs(t *testing.T) {
map[string]interface{}{}, map[string]interface{}{},
&stepRun{ &stepRun{
atLeastVersion2: true, atLeastVersion2: true,
ui: packer.TestUi(t), ui: packersdk.TestUi(t),
}, },
[]string{ []string{
"-display", "gtk", "-display", "gtk",
@ -155,7 +155,7 @@ func Test_DriveAndDeviceArgs(t *testing.T) {
&stepRun{ &stepRun{
DiskImage: true, DiskImage: true,
atLeastVersion2: true, atLeastVersion2: true,
ui: packer.TestUi(t), ui: packersdk.TestUi(t),
}, },
[]string{ []string{
"-display", "gtk", "-display", "gtk",
@ -183,7 +183,7 @@ func Test_DriveAndDeviceArgs(t *testing.T) {
&stepRun{ &stepRun{
DiskImage: true, DiskImage: true,
atLeastVersion2: true, atLeastVersion2: true,
ui: packer.TestUi(t), ui: packersdk.TestUi(t),
}, },
[]string{ []string{
"-display", "gtk", "-display", "gtk",
@ -212,7 +212,7 @@ func Test_DriveAndDeviceArgs(t *testing.T) {
}, },
&stepRun{ &stepRun{
atLeastVersion2: true, atLeastVersion2: true,
ui: packer.TestUi(t), ui: packersdk.TestUi(t),
}, },
[]string{ []string{
"-display", "gtk", "-display", "gtk",
@ -244,7 +244,7 @@ func Test_DriveAndDeviceArgs(t *testing.T) {
}, },
&stepRun{ &stepRun{
atLeastVersion2: true, atLeastVersion2: true,
ui: packer.TestUi(t), ui: packersdk.TestUi(t),
}, },
[]string{ []string{
"-display", "gtk", "-display", "gtk",
@ -274,7 +274,7 @@ func Test_DriveAndDeviceArgs(t *testing.T) {
}, },
&stepRun{ &stepRun{
atLeastVersion2: true, atLeastVersion2: true,
ui: packer.TestUi(t), ui: packersdk.TestUi(t),
}, },
[]string{ []string{
"-display", "gtk", "-display", "gtk",
@ -294,7 +294,7 @@ func Test_DriveAndDeviceArgs(t *testing.T) {
}, },
&stepRun{ &stepRun{
atLeastVersion2: true, atLeastVersion2: true,
ui: packer.TestUi(t), ui: packersdk.TestUi(t),
}, },
[]string{ []string{
"-display", "gtk", "-display", "gtk",
@ -314,7 +314,7 @@ func Test_DriveAndDeviceArgs(t *testing.T) {
}, },
&stepRun{ &stepRun{
atLeastVersion2: true, atLeastVersion2: true,
ui: packer.TestUi(t), ui: packersdk.TestUi(t),
}, },
[]string{ []string{
"-display", "gtk", "-display", "gtk",
@ -338,7 +338,7 @@ func Test_DriveAndDeviceArgs(t *testing.T) {
}, },
&stepRun{ &stepRun{
atLeastVersion2: false, atLeastVersion2: false,
ui: packer.TestUi(t), ui: packersdk.TestUi(t),
}, },
[]string{ []string{
"-boot", "once=d", "-boot", "once=d",
@ -360,7 +360,7 @@ func Test_DriveAndDeviceArgs(t *testing.T) {
}, },
&stepRun{ &stepRun{
atLeastVersion2: true, atLeastVersion2: true,
ui: packer.TestUi(t), ui: packersdk.TestUi(t),
}, },
[]string{ []string{
"-display", "gtk", "-display", "gtk",
@ -386,7 +386,7 @@ func Test_DriveAndDeviceArgs(t *testing.T) {
&stepRun{ &stepRun{
DiskImage: true, DiskImage: true,
atLeastVersion2: true, atLeastVersion2: true,
ui: packer.TestUi(t), ui: packersdk.TestUi(t),
}, },
[]string{ []string{
"-display", "gtk", "-display", "gtk",
@ -436,7 +436,7 @@ func Test_OptionalConfigOptionsGetSet(t *testing.T) {
state := runTestState(t, c) state := runTestState(t, c)
step := &stepRun{ step := &stepRun{
atLeastVersion2: true, atLeastVersion2: true,
ui: packer.TestUi(t), ui: packersdk.TestUi(t),
} }
args, err := step.getCommandArgs(c, state) args, err := step.getCommandArgs(c, state)
if err != nil { if err != nil {
@ -475,7 +475,7 @@ func Test_Defaults(t *testing.T) {
{ {
&Config{}, &Config{},
map[string]interface{}{}, map[string]interface{}{},
&stepRun{ui: packer.TestUi(t)}, &stepRun{ui: packersdk.TestUi(t)},
[]string{"-boot", "once=d"}, []string{"-boot", "once=d"},
"Boot value should default to once=d", "Boot value should default to once=d",
}, },
@ -484,7 +484,7 @@ func Test_Defaults(t *testing.T) {
map[string]interface{}{}, map[string]interface{}{},
&stepRun{ &stepRun{
DiskImage: true, DiskImage: true,
ui: packer.TestUi(t), ui: packersdk.TestUi(t),
}, },
[]string{"-boot", "c"}, []string{"-boot", "c"},
"Boot value should be set to c when DiskImage is set on step", "Boot value should be set to c when DiskImage is set on step",
@ -495,7 +495,7 @@ func Test_Defaults(t *testing.T) {
QMPSocketPath: "/path/to/socket", QMPSocketPath: "/path/to/socket",
}, },
map[string]interface{}{}, map[string]interface{}{},
&stepRun{ui: packer.TestUi(t)}, &stepRun{ui: packersdk.TestUi(t)},
[]string{"-qmp", "unix:/path/to/socket,server,nowait"}, []string{"-qmp", "unix:/path/to/socket,server,nowait"},
"Args should contain -qmp when qmp_enable is set", "Args should contain -qmp when qmp_enable is set",
}, },
@ -504,7 +504,7 @@ func Test_Defaults(t *testing.T) {
QMPEnable: true, QMPEnable: true,
}, },
map[string]interface{}{}, map[string]interface{}{},
&stepRun{ui: packer.TestUi(t)}, &stepRun{ui: packersdk.TestUi(t)},
[]string{"-qmp", "unix:,server,nowait"}, []string{"-qmp", "unix:,server,nowait"},
"Args contain -qmp even when socket path isn't set, if qmp enabled", "Args contain -qmp even when socket path isn't set, if qmp enabled",
}, },
@ -513,14 +513,14 @@ func Test_Defaults(t *testing.T) {
VMName: "partyname", VMName: "partyname",
}, },
map[string]interface{}{}, map[string]interface{}{},
&stepRun{ui: packer.TestUi(t)}, &stepRun{ui: packersdk.TestUi(t)},
[]string{"-name", "partyname"}, []string{"-name", "partyname"},
"Name is set from config", "Name is set from config",
}, },
{ {
&Config{}, &Config{},
map[string]interface{}{}, map[string]interface{}{},
&stepRun{ui: packer.TestUi(t)}, &stepRun{ui: packersdk.TestUi(t)},
[]string{"-name", ""}, []string{"-name", ""},
"Name is set from config, even when name is blank (which won't " + "Name is set from config, even when name is blank (which won't " +
"happen for real thanks to defaulting in build prepare)", "happen for real thanks to defaulting in build prepare)",
@ -531,7 +531,7 @@ func Test_Defaults(t *testing.T) {
MachineType: "fancymachine", MachineType: "fancymachine",
}, },
map[string]interface{}{}, map[string]interface{}{},
&stepRun{ui: packer.TestUi(t)}, &stepRun{ui: packersdk.TestUi(t)},
[]string{"-machine", "type=fancymachine"}, []string{"-machine", "type=fancymachine"},
"Don't add accelerator tag when no accelerator is set.", "Don't add accelerator tag when no accelerator is set.",
}, },
@ -541,7 +541,7 @@ func Test_Defaults(t *testing.T) {
MachineType: "fancymachine", MachineType: "fancymachine",
}, },
map[string]interface{}{}, map[string]interface{}{},
&stepRun{ui: packer.TestUi(t)}, &stepRun{ui: packersdk.TestUi(t)},
[]string{"-machine", "type=fancymachine,accel=kvm"}, []string{"-machine", "type=fancymachine,accel=kvm"},
"Add accelerator tag when accelerator is set.", "Add accelerator tag when accelerator is set.",
}, },
@ -550,7 +550,7 @@ func Test_Defaults(t *testing.T) {
NetBridge: "fakebridge", NetBridge: "fakebridge",
}, },
map[string]interface{}{}, map[string]interface{}{},
&stepRun{ui: packer.TestUi(t)}, &stepRun{ui: packersdk.TestUi(t)},
[]string{"-netdev", "bridge,id=user.0,br=fakebridge"}, []string{"-netdev", "bridge,id=user.0,br=fakebridge"},
"Add netbridge tag when netbridge is set.", "Add netbridge tag when netbridge is set.",
}, },
@ -563,7 +563,7 @@ func Test_Defaults(t *testing.T) {
}, },
}, },
map[string]interface{}{}, map[string]interface{}{},
&stepRun{ui: packer.TestUi(t)}, &stepRun{ui: packersdk.TestUi(t)},
[]string{"-netdev", "user,id=user.0"}, []string{"-netdev", "user,id=user.0"},
"No host forwarding when no net bridge and no communicator", "No host forwarding when no net bridge and no communicator",
}, },
@ -581,7 +581,7 @@ func Test_Defaults(t *testing.T) {
map[string]interface{}{ map[string]interface{}{
"commHostPort": 1111, "commHostPort": 1111,
}, },
&stepRun{ui: packer.TestUi(t)}, &stepRun{ui: packersdk.TestUi(t)},
[]string{"-netdev", "user,id=user.0,hostfwd=tcp::1111-:4567"}, []string{"-netdev", "user,id=user.0,hostfwd=tcp::1111-:4567"},
"Host forwarding when a communicator is configured", "Host forwarding when a communicator is configured",
}, },
@ -592,7 +592,7 @@ func Test_Defaults(t *testing.T) {
map[string]interface{}{ map[string]interface{}{
"vnc_port": 5959, "vnc_port": 5959,
}, },
&stepRun{ui: packer.TestUi(t)}, &stepRun{ui: packersdk.TestUi(t)},
[]string{"-vnc", "1.1.1.1:5959"}, []string{"-vnc", "1.1.1.1:5959"},
"no VNC password should be set", "no VNC password should be set",
}, },
@ -604,7 +604,7 @@ func Test_Defaults(t *testing.T) {
map[string]interface{}{ map[string]interface{}{
"vnc_port": 5959, "vnc_port": 5959,
}, },
&stepRun{ui: packer.TestUi(t)}, &stepRun{ui: packersdk.TestUi(t)},
[]string{"-vnc", "1.1.1.1:5959,password"}, []string{"-vnc", "1.1.1.1:5959,password"},
"VNC password should be set", "VNC password should be set",
}, },
@ -613,7 +613,7 @@ func Test_Defaults(t *testing.T) {
MemorySize: 2345, MemorySize: 2345,
}, },
map[string]interface{}{}, map[string]interface{}{},
&stepRun{ui: packer.TestUi(t)}, &stepRun{ui: packersdk.TestUi(t)},
[]string{"-m", "2345M"}, []string{"-m", "2345M"},
"Memory is set, with unit M", "Memory is set, with unit M",
}, },
@ -622,7 +622,7 @@ func Test_Defaults(t *testing.T) {
CpuCount: 2, CpuCount: 2,
}, },
map[string]interface{}{}, map[string]interface{}{},
&stepRun{ui: packer.TestUi(t)}, &stepRun{ui: packersdk.TestUi(t)},
[]string{"-smp", "cpus=2,sockets=2"}, []string{"-smp", "cpus=2,sockets=2"},
"both cpus and sockets are set to config's CpuCount", "both cpus and sockets are set to config's CpuCount",
}, },
@ -631,7 +631,7 @@ func Test_Defaults(t *testing.T) {
CpuCount: 2, CpuCount: 2,
}, },
map[string]interface{}{}, map[string]interface{}{},
&stepRun{ui: packer.TestUi(t)}, &stepRun{ui: packersdk.TestUi(t)},
[]string{"-smp", "cpus=2,sockets=2"}, []string{"-smp", "cpus=2,sockets=2"},
"both cpus and sockets are set to config's CpuCount", "both cpus and sockets are set to config's CpuCount",
}, },
@ -642,7 +642,7 @@ func Test_Defaults(t *testing.T) {
map[string]interface{}{ map[string]interface{}{
"floppy_path": "/path/to/floppy", "floppy_path": "/path/to/floppy",
}, },
&stepRun{ui: packer.TestUi(t)}, &stepRun{ui: packersdk.TestUi(t)},
[]string{"-fda", "/path/to/floppy"}, []string{"-fda", "/path/to/floppy"},
"floppy path should be set under fda flag, when it exists", "floppy path should be set under fda flag, when it exists",
}, },
@ -655,7 +655,7 @@ func Test_Defaults(t *testing.T) {
map[string]interface{}{}, map[string]interface{}{},
&stepRun{ &stepRun{
atLeastVersion2: true, atLeastVersion2: true,
ui: packer.TestUi(t), ui: packersdk.TestUi(t),
}, },
[]string{"-display", "fakedisplay"}, []string{"-display", "fakedisplay"},
"Display option should value config display", "Display option should value config display",
@ -667,7 +667,7 @@ func Test_Defaults(t *testing.T) {
map[string]interface{}{}, map[string]interface{}{},
&stepRun{ &stepRun{
atLeastVersion2: true, atLeastVersion2: true,
ui: packer.TestUi(t), ui: packersdk.TestUi(t),
}, },
[]string{"-display", "gtk"}, []string{"-display", "gtk"},
"Display option should default to gtk", "Display option should default to gtk",

View File

@ -5,14 +5,14 @@ import (
"testing" "testing"
"time" "time"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/packer-plugin-sdk/communicator" "github.com/hashicorp/packer/packer-plugin-sdk/communicator"
"github.com/hashicorp/packer/packer-plugin-sdk/multistep" "github.com/hashicorp/packer/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
) )
func Test_Shutdown_Null_success(t *testing.T) { func Test_Shutdown_Null_success(t *testing.T) {
state := new(multistep.BasicStateBag) state := new(multistep.BasicStateBag)
state.Put("ui", packer.TestUi(t)) state.Put("ui", packersdk.TestUi(t))
driverMock := new(DriverMock) driverMock := new(DriverMock)
driverMock.WaitForShutdownState = true driverMock.WaitForShutdownState = true
state.Put("driver", driverMock) state.Put("driver", driverMock)
@ -37,7 +37,7 @@ func Test_Shutdown_Null_success(t *testing.T) {
func Test_Shutdown_Null_failure(t *testing.T) { func Test_Shutdown_Null_failure(t *testing.T) {
state := new(multistep.BasicStateBag) state := new(multistep.BasicStateBag)
state.Put("ui", packer.TestUi(t)) state.Put("ui", packersdk.TestUi(t))
driverMock := new(DriverMock) driverMock := new(DriverMock)
driverMock.WaitForShutdownState = false driverMock.WaitForShutdownState = false
state.Put("driver", driverMock) state.Put("driver", driverMock)
@ -61,7 +61,7 @@ func Test_Shutdown_Null_failure(t *testing.T) {
func Test_Shutdown_NoShutdownCommand(t *testing.T) { func Test_Shutdown_NoShutdownCommand(t *testing.T) {
state := new(multistep.BasicStateBag) state := new(multistep.BasicStateBag)
state.Put("ui", packer.TestUi(t)) state.Put("ui", packersdk.TestUi(t))
driverMock := new(DriverMock) driverMock := new(DriverMock)
state.Put("driver", driverMock) state.Put("driver", driverMock)

View File

@ -96,7 +96,7 @@ func readFloppyOutput(path string) (string, error) {
} }
func setupVMwareBuild(t *testing.T, builderConfig map[string]string, provisionerConfig map[string]string) error { func setupVMwareBuild(t *testing.T, builderConfig map[string]string, provisionerConfig map[string]string) error {
ui := packer.TestUi(t) ui := packersdk.TestUi(t)
// create builder config and update with user-supplied options // create builder config and update with user-supplied options
cfgBuilder := map[string]string{} cfgBuilder := map[string]string{}

View File

@ -1,9 +1,21 @@
package packer package packer
import ( import (
"bytes"
"io" "io"
"io/ioutil"
"testing"
) )
func TestUi(t *testing.T) Ui {
var buf bytes.Buffer
return &BasicUi{
Reader: &buf,
Writer: ioutil.Discard,
ErrorWriter: ioutil.Discard,
}
}
type MockUi struct { type MockUi struct {
AskCalled bool AskCalled bool
AskQuery string AskQuery string

View File

@ -10,7 +10,6 @@ import (
"testing" "testing"
"github.com/hashicorp/packer/builder/file" "github.com/hashicorp/packer/builder/file"
"github.com/hashicorp/packer/packer"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer" packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
"github.com/hashicorp/packer/packer-plugin-sdk/template" "github.com/hashicorp/packer/packer-plugin-sdk/template"
) )
@ -47,7 +46,7 @@ func TestChecksumSHA1(t *testing.T) {
func setup(t *testing.T) (packersdk.Ui, packersdk.Artifact, error) { func setup(t *testing.T) (packersdk.Ui, packersdk.Artifact, error) {
// Create fake UI and Cache // Create fake UI and Cache
ui := packer.TestUi(t) ui := packersdk.TestUi(t)
// Create config for file builder // Create config for file builder
const fileConfig = `{"builders":[{"type":"file","target":"package.txt","content":"Hello world!"}]}` const fileConfig = `{"builders":[{"type":"file","target":"package.txt","content":"Hello world!"}]}`

View File

@ -10,7 +10,6 @@ import (
"testing" "testing"
"github.com/hashicorp/packer/builder/file" "github.com/hashicorp/packer/builder/file"
"github.com/hashicorp/packer/packer"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer" packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
"github.com/hashicorp/packer/packer-plugin-sdk/template" "github.com/hashicorp/packer/packer-plugin-sdk/template"
) )
@ -187,7 +186,7 @@ func TestCompressInterpolation(t *testing.T) {
func setup(t *testing.T) (packersdk.Ui, packersdk.Artifact, error) { func setup(t *testing.T) (packersdk.Ui, packersdk.Artifact, error) {
// Create fake UI and Cache // Create fake UI and Cache
ui := packer.TestUi(t) ui := packersdk.TestUi(t)
// Create config for file builder // Create config for file builder
const fileConfig = `{"builders":[{"type":"file","target":"package.txt","content":"Hello world!"}]}` const fileConfig = `{"builders":[{"type":"file","target":"package.txt","content":"Hello world!"}]}`

View File

@ -329,7 +329,7 @@ func testProvisionerProvisionDockerWithPlaybookFiles(t *testing.T, templateStrin
t.Skip("This test is only run with PACKER_ACC=1") t.Skip("This test is only run with PACKER_ACC=1")
} }
ui := packer.TestUi(t) ui := packersdk.TestUi(t)
tpl, err := template.Parse(strings.NewReader(templateString)) tpl, err := template.Parse(strings.NewReader(templateString))
if err != nil { if err != nil {