fix docker acceptance tests. Turns out they were broken on the main branch too; needed to move noop progress bar into the sdk to be used in the builder testui.

This commit is contained in:
Megan Marsh 2020-12-03 14:58:07 -08:00
parent 8f51a8bfae
commit 352f064b55
12 changed files with 213 additions and 344 deletions

View File

@ -35,5 +35,8 @@ func (a *ExportArtifact) State(name string) interface{} {
} }
func (a *ExportArtifact) Destroy() error { func (a *ExportArtifact) Destroy() error {
return os.Remove(a.path) if a.path != "" {
return os.Remove(a.path)
}
return nil
} }

View File

@ -1,99 +1,107 @@
package docker package docker
import ( import (
"context"
"crypto/sha256" "crypto/sha256"
"encoding/json"
"fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec" "os/exec"
"strings"
"testing" "testing"
"github.com/hashicorp/packer/packer" builderT "github.com/hashicorp/packer/packer-plugin-sdk/acctest"
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/provisioner/file"
"github.com/hashicorp/packer/provisioner/shell"
) )
// RenderConfig helps create dynamic packer template configs for parsing by
// builderT without having to write the config to a file.
func RenderConfig(builderConfig map[string]interface{}, provisionerConfig []map[string]interface{}) string {
// set up basic build template
t := map[string][]map[string]interface{}{
"builders": {
// Setup basic docker config
map[string]interface{}{
"type": "test",
"image": "ubuntu",
"discard": true,
},
},
"provisioners": []map[string]interface{}{},
}
// apply special builder overrides
for k, v := range builderConfig {
t["builders"][0][k] = v
}
// Apply special provisioner overrides
for _, v := range provisionerConfig {
t["provisioners"] = append(t["provisioners"], v)
}
j, _ := json.Marshal(t)
return string(j)
}
// 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 := packersdk.TestUi(t)
tpl, err := template.Parse(strings.NewReader(dockerBuilderConfig))
if err != nil {
t.Fatalf("Unable to parse config: %s", err)
}
if os.Getenv("PACKER_ACC") == "" { if os.Getenv("PACKER_ACC") == "" {
t.Skip("This test is only run with PACKER_ACC=1") t.Skip("This test is only run with PACKER_ACC=1")
} }
dockerBuilderExtraConfig := map[string]interface{}{
"run_command": []string{"-d", "-i", "-t", "{{.Image}}", "/bin/sh"},
}
dockerProvisionerConfig := []map[string]interface{}{
{
"type": "file",
"source": "test-fixtures/onecakes/strawberry",
"destination": "/strawberry-cake",
},
{
"type": "file",
"source": "/strawberry-cake",
"destination": "my-strawberry-cake",
"direction": "download",
},
}
configString := RenderConfig(dockerBuilderExtraConfig, dockerProvisionerConfig)
// this should be a precheck
cmd := exec.Command("docker", "-v") cmd := exec.Command("docker", "-v")
cmd.Run() err := cmd.Run()
if !cmd.ProcessState.Success() { if err != nil {
t.Error("docker command not found; please make sure docker is installed") t.Error("docker command not found; please make sure docker is installed")
} }
// Setup the builder builderT.Test(t, builderT.TestCase{
builder := &Builder{} Builder: &Builder{},
_, warnings, err := builder.Prepare(tpl.Builders["docker"].Config) Template: configString,
if err != nil { Check: func(a []packersdk.Artifact) error {
t.Fatalf("Error preparing configuration %s", err) // Verify that the thing we downloaded is the same thing we sent up.
} // Complain loudly if it isn't.
if len(warnings) > 0 { inputFile, err := ioutil.ReadFile("test-fixtures/onecakes/strawberry")
t.Fatal("Encountered configuration warnings; aborting") if err != nil {
} return fmt.Errorf("Unable to read input file: %s", err)
}
// Setup the provisioners outputFile, err := ioutil.ReadFile("my-strawberry-cake")
upload := &file.Provisioner{} if err != nil {
err = upload.Prepare(tpl.Provisioners[0].Config) return fmt.Errorf("Unable to read output file: %s", err)
if err != nil { }
t.Fatalf("Error preparing upload: %s", err) if sha256.Sum256(inputFile) != sha256.Sum256(outputFile) {
} return fmt.Errorf("Input and output files do not match\n"+
download := &file.Provisioner{} "Input:\n%s\nOutput:\n%s\n", inputFile, outputFile)
err = download.Prepare(tpl.Provisioners[1].Config) }
if err != nil { return nil
t.Fatalf("Error preparing download: %s", err)
}
// Preemptive cleanup. Honestly I don't know why you would want to get rid
// of my strawberry cake. It's so tasty! Do you not like cake? Are you a
// cake-hater? Or are you keeping all the cake all for yourself? So selfish!
defer os.Remove("my-strawberry-cake")
// Add hooks so the provisioners run during the build
hooks := map[string][]packersdk.Hook{}
hooks[packersdk.HookProvision] = []packersdk.Hook{
&packer.ProvisionHook{
Provisioners: []*packer.HookedProvisioner{
{Provisioner: upload, Config: nil, TypeName: ""},
{Provisioner: download, Config: nil, TypeName: ""},
},
}, },
} Teardown: func() error {
hook := &packersdk.DispatchHook{Mapping: hooks} // Cleanup. Honestly I don't know why you would want to get rid
// of my strawberry cake. It's so tasty! Do you not like cake? Are you a
// Run things // cake-hater? Or are you keeping all the cake all for yourself? So selfish!
artifact, err := builder.Run(context.Background(), ui, hook) os.Remove("my-strawberry-cake")
if err != nil { return nil
t.Fatalf("Error running build %s", err) },
} })
// Preemptive cleanup
defer artifact.Destroy()
// Verify that the thing we downloaded is the same thing we sent up.
// Complain loudly if it isn't.
inputFile, err := ioutil.ReadFile("test-fixtures/onecakes/strawberry")
if err != nil {
t.Fatalf("Unable to read input file: %s", err)
}
outputFile, err := ioutil.ReadFile("my-strawberry-cake")
if err != nil {
t.Fatalf("Unable to read output file: %s", err)
}
if sha256.Sum256(inputFile) != sha256.Sum256(outputFile) {
t.Fatalf("Input and output files do not match\n"+
"Input:\n%s\nOutput:\n%s\n", inputFile, outputFile)
}
} }
// TestLargeDownload verifies that files are the appropriate size after being // TestLargeDownload verifies that files are the appropriate size after being
@ -101,276 +109,133 @@ 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 := packersdk.TestUi(t)
tpl, err := template.Parse(strings.NewReader(dockerLargeBuilderConfig))
if err != nil {
t.Fatalf("Unable to parse config: %s", err)
}
if os.Getenv("PACKER_ACC") == "" { if os.Getenv("PACKER_ACC") == "" {
t.Skip("This test is only run with PACKER_ACC=1") t.Skip("This test is only run with PACKER_ACC=1")
} }
dockerProvisionerConfig := []map[string]interface{}{
{
"type": "shell",
"inline": []string{
"dd if=/dev/urandom of=/tmp/cupcake bs=1M count=2",
"dd if=/dev/urandom of=/tmp/bigcake bs=1M count=100",
"sync",
"md5sum /tmp/cupcake /tmp/bigcake",
},
},
{
"type": "file",
"source": "/tmp/cupcake",
"destination": "cupcake",
"direction": "download",
},
{
"type": "file",
"source": "/tmp/bigcake",
"destination": "bigcake",
"direction": "download",
},
}
configString := RenderConfig(map[string]interface{}{}, dockerProvisionerConfig)
// this should be a precheck
cmd := exec.Command("docker", "-v") cmd := exec.Command("docker", "-v")
cmd.Run() err := cmd.Run()
if !cmd.ProcessState.Success() { if err != nil {
t.Error("docker command not found; please make sure docker is installed") t.Error("docker command not found; please make sure docker is installed")
} }
// Setup the builder builderT.Test(t, builderT.TestCase{
builder := &Builder{} Builder: &Builder{},
_, warnings, err := builder.Prepare(tpl.Builders["docker"].Config) Template: configString,
if err != nil { Check: func(a []packersdk.Artifact) error {
t.Fatalf("Error preparing configuration %s", err) // Verify that the things we downloaded are the right size. Complain loudly
} // if they are not.
if len(warnings) > 0 { //
t.Fatal("Encountered configuration warnings; aborting") // cupcake should be 2097152 bytes
} // bigcake should be 104857600 bytes
cupcake, err := os.Stat("cupcake")
if err != nil {
t.Fatalf("Unable to stat cupcake file: %s", err)
}
cupcakeExpected := int64(2097152)
if cupcake.Size() != cupcakeExpected {
t.Errorf("Expected cupcake to be %d bytes; found %d", cupcakeExpected, cupcake.Size())
}
// Setup the provisioners bigcake, err := os.Stat("bigcake")
shell := &shell.Provisioner{} if err != nil {
err = shell.Prepare(tpl.Provisioners[0].Config) t.Fatalf("Unable to stat bigcake file: %s", err)
if err != nil { }
t.Fatalf("Error preparing shell provisioner: %s", err) bigcakeExpected := int64(104857600)
} if bigcake.Size() != bigcakeExpected {
downloadCupcake := &file.Provisioner{} t.Errorf("Expected bigcake to be %d bytes; found %d", bigcakeExpected, bigcake.Size())
err = downloadCupcake.Prepare(tpl.Provisioners[1].Config) }
if err != nil {
t.Fatalf("Error preparing downloadCupcake: %s", err)
}
downloadBigcake := &file.Provisioner{}
err = downloadBigcake.Prepare(tpl.Provisioners[2].Config)
if err != nil {
t.Fatalf("Error preparing downloadBigcake: %s", err)
}
// Preemptive cleanup. // TODO if we can, calculate a sha inside the container and compare to the
defer os.Remove("cupcake") // one we get after we pull it down. We will probably have to parse the log
defer os.Remove("bigcake") // or ui output to do this because we use /dev/urandom to create the file.
// Add hooks so the provisioners run during the build // if sha256.Sum256(inputFile) != sha256.Sum256(outputFile) {
hooks := map[string][]packersdk.Hook{} // t.Fatalf("Input and output files do not match\n"+
hooks[packersdk.HookProvision] = []packersdk.Hook{ // "Input:\n%s\nOutput:\n%s\n", inputFile, outputFile)
&packer.ProvisionHook{ // }
Provisioners: []*packer.HookedProvisioner{ return nil
{Provisioner: shell, Config: nil, TypeName: ""},
{Provisioner: downloadCupcake, Config: nil, TypeName: ""},
{Provisioner: downloadBigcake, Config: nil, TypeName: ""},
},
}, },
} Teardown: func() error {
hook := &packersdk.DispatchHook{Mapping: hooks} os.Remove("cupcake")
os.Remove("bigcake")
// Run things return nil
artifact, err := builder.Run(context.Background(), ui, hook) },
if err != nil { })
t.Fatalf("Error running build %s", err)
}
// Preemptive cleanup
defer artifact.Destroy()
// Verify that the things we downloaded are the right size. Complain loudly
// if they are not.
//
// cupcake should be 2097152 bytes
// bigcake should be 104857600 bytes
cupcake, err := os.Stat("cupcake")
if err != nil {
t.Fatalf("Unable to stat cupcake file: %s", err)
}
cupcakeExpected := int64(2097152)
if cupcake.Size() != cupcakeExpected {
t.Errorf("Expected cupcake to be %d bytes; found %d", cupcakeExpected, cupcake.Size())
}
bigcake, err := os.Stat("bigcake")
if err != nil {
t.Fatalf("Unable to stat bigcake file: %s", err)
}
bigcakeExpected := int64(104857600)
if bigcake.Size() != bigcakeExpected {
t.Errorf("Expected bigcake to be %d bytes; found %d", bigcakeExpected, bigcake.Size())
}
// TODO if we can, calculate a sha inside the container and compare to the
// one we get after we pull it down. We will probably have to parse the log
// or ui output to do this because we use /dev/urandom to create the file.
// if sha256.Sum256(inputFile) != sha256.Sum256(outputFile) {
// t.Fatalf("Input and output files do not match\n"+
// "Input:\n%s\nOutput:\n%s\n", inputFile, outputFile)
// }
} }
// 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 := packersdk.TestUi(t)
tpl, err := template.Parse(strings.NewReader(testFixUploadOwnerTemplate))
if err != nil {
t.Fatalf("Unable to parse config: %s", err)
}
if os.Getenv("PACKER_ACC") == "" { if os.Getenv("PACKER_ACC") == "" {
t.Skip("This test is only run with PACKER_ACC=1") t.Skip("This test is only run with PACKER_ACC=1")
} }
cmd := exec.Command("docker", "-v") cmd := exec.Command("docker", "-v")
cmd.Run() err := cmd.Run()
if !cmd.ProcessState.Success() { if err != nil {
t.Error("docker command not found; please make sure docker is installed") t.Error("docker command not found; please make sure docker is installed")
} }
// Setup the builder dockerBuilderExtraConfig := map[string]interface{}{
builder := &Builder{} "run_command": []string{"-d", "-i", "-t", "-u", "42", "{{.Image}}", "/bin/sh"},
_, warnings, err := builder.Prepare(tpl.Builders["docker"].Config)
if err != nil {
t.Fatalf("Error preparing configuration %s", err)
}
if len(warnings) > 0 {
t.Fatal("Encountered configuration warnings; aborting")
} }
// Setup the provisioners testFixUploadOwnerProvisionersTemplate := []map[string]interface{}{
fileProvisioner := &file.Provisioner{} {
err = fileProvisioner.Prepare(tpl.Provisioners[0].Config) "type": "file",
if err != nil { "source": "test-fixtures/onecakes/strawberry",
t.Fatalf("Error preparing single file upload provisioner: %s", err) "destination": "/tmp/strawberry-cake",
} },
{
dirProvisioner := &file.Provisioner{} "type": "file",
err = dirProvisioner.Prepare(tpl.Provisioners[1].Config) "source": "test-fixtures/manycakes",
if err != nil { "destination": "/tmp/",
t.Fatalf("Error preparing directory upload provisioner: %s", err) },
} {
"type": "shell",
shellProvisioner := &shell.Provisioner{} "inline": "touch /tmp/testUploadOwner",
err = shellProvisioner.Prepare(tpl.Provisioners[2].Config) },
if err != nil { {
t.Fatalf("Error preparing shell provisioner: %s", err) "type": "shell",
} "inline": []string{
"[ $(stat -c %u /tmp/strawberry-cake) -eq 42 ] || (echo 'Invalid owner of /tmp/strawberry-cake' && exit 1)",
verifyProvisioner := &shell.Provisioner{} "[ $(stat -c %u /tmp/testUploadOwner) -eq 42 ] || (echo 'Invalid owner of /tmp/testUploadOwner' && exit 1)",
err = verifyProvisioner.Prepare(tpl.Provisioners[3].Config) "find /tmp/manycakes | xargs -n1 -IFILE /bin/sh -c '[ $(stat -c %u FILE) -eq 42 ] || (echo \"Invalid owner of FILE\" && exit 1)'",
if err != nil {
t.Fatalf("Error preparing verification provisioner: %s", err)
}
// Add hooks so the provisioners run during the build
hooks := map[string][]packersdk.Hook{}
hooks[packersdk.HookProvision] = []packersdk.Hook{
&packer.ProvisionHook{
Provisioners: []*packer.HookedProvisioner{
{Provisioner: fileProvisioner, Config: nil, TypeName: ""},
{Provisioner: dirProvisioner, Config: nil, TypeName: ""},
{Provisioner: shellProvisioner, Config: nil, TypeName: ""},
{Provisioner: verifyProvisioner, Config: nil, TypeName: ""},
}, },
}, },
} }
hook := &packersdk.DispatchHook{Mapping: hooks}
artifact, err := builder.Run(context.Background(), ui, hook) configString := RenderConfig(dockerBuilderExtraConfig, testFixUploadOwnerProvisionersTemplate)
if err != nil { builderT.Test(t, builderT.TestCase{
t.Fatalf("Error running build %s", err) Builder: &Builder{},
} Template: configString,
defer artifact.Destroy() })
} }
const dockerBuilderConfig = `
{
"builders": [
{
"type": "docker",
"image": "ubuntu",
"discard": true,
"run_command": ["-d", "-i", "-t", "{{.Image}}", "/bin/sh"]
}
],
"provisioners": [
{
"type": "file",
"source": "test-fixtures/onecakes/strawberry",
"destination": "/strawberry-cake"
},
{
"type": "file",
"source": "/strawberry-cake",
"destination": "my-strawberry-cake",
"direction": "download"
}
]
}
`
const dockerLargeBuilderConfig = `
{
"builders": [
{
"type": "docker",
"image": "ubuntu",
"discard": true
}
],
"provisioners": [
{
"type": "shell",
"inline": [
"dd if=/dev/urandom of=/tmp/cupcake bs=1M count=2",
"dd if=/dev/urandom of=/tmp/bigcake bs=1M count=100",
"sync",
"md5sum /tmp/cupcake /tmp/bigcake"
]
},
{
"type": "file",
"source": "/tmp/cupcake",
"destination": "cupcake",
"direction": "download"
},
{
"type": "file",
"source": "/tmp/bigcake",
"destination": "bigcake",
"direction": "download"
}
]
}
`
const testFixUploadOwnerTemplate = `
{
"builders": [
{
"type": "docker",
"image": "ubuntu",
"discard": true,
"run_command": ["-d", "-i", "-t", "-u", "42", "{{.Image}}", "/bin/sh"]
}
],
"provisioners": [
{
"type": "file",
"source": "test-fixtures/onecakes/strawberry",
"destination": "/tmp/strawberry-cake"
},
{
"type": "file",
"source": "test-fixtures/manycakes",
"destination": "/tmp/"
},
{
"type": "shell",
"inline": "touch /tmp/testUploadOwner"
},
{
"type": "shell",
"inline": [
"[ $(stat -c %u /tmp/strawberry-cake) -eq 42 ] || (echo 'Invalid owner of /tmp/strawberry-cake' && exit 1)",
"[ $(stat -c %u /tmp/testUploadOwner) -eq 42 ] || (echo 'Invalid owner of /tmp/testUploadOwner' && exit 1)",
"find /tmp/manycakes | xargs -n1 -IFILE /bin/sh -c '[ $(stat -c %u FILE) -eq 42 ] || (echo \"Invalid owner of FILE\" && exit 1)'"
]
}
]
}
`

View File

@ -200,7 +200,7 @@ func wrappedMain() int {
Reader: os.Stdin, Reader: os.Stdin,
Writer: os.Stdout, Writer: os.Stdout,
ErrorWriter: os.Stdout, ErrorWriter: os.Stdout,
PB: &packer.NoopProgressTracker{}, PB: &packersdk.NoopProgressTracker{},
} }
ui = basicUi ui = basicUi
if !inPlugin { if !inPlugin {

View File

@ -163,10 +163,12 @@ func Test(t TestT, c TestCase) {
// Run it! We use a temporary directory for caching and discard // Run it! We use a temporary directory for caching and discard
// any UI output. We discard since it shows up in logs anyways. // any UI output. We discard since it shows up in logs anyways.
log.Printf("[DEBUG] Running 'test' build") log.Printf("[DEBUG] Running 'test' build")
// ui := packersdk.TestUi(t)
ui := &packersdk.BasicUi{ ui := &packersdk.BasicUi{
Reader: os.Stdin, Reader: os.Stdin,
Writer: ioutil.Discard, Writer: ioutil.Discard,
ErrorWriter: ioutil.Discard, ErrorWriter: ioutil.Discard,
PB: &packersdk.NoopProgressTracker{},
} }
artifacts, err := build.Run(context.Background(), ui) artifacts, err := build.Run(context.Background(), ui)
if err != nil { if err != nil {

View File

@ -17,7 +17,6 @@ import (
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
urlhelper "github.com/hashicorp/go-getter/v2/helper/url" urlhelper "github.com/hashicorp/go-getter/v2/helper/url"
"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" packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
"github.com/hashicorp/packer/packer-plugin-sdk/tmp" "github.com/hashicorp/packer/packer-plugin-sdk/tmp"
@ -246,7 +245,7 @@ func TestStepDownload_download(t *testing.T) {
ui := &packersdk.BasicUi{ ui := &packersdk.BasicUi{
Reader: new(bytes.Buffer), Reader: new(bytes.Buffer),
Writer: new(bytes.Buffer), Writer: new(bytes.Buffer),
PB: &packer.NoopProgressTracker{}, PB: &packersdk.NoopProgressTracker{},
} }
dir := createTempDir(t) dir := createTempDir(t)

View File

@ -7,7 +7,6 @@ import (
"os" "os"
"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" packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
) )
@ -17,7 +16,7 @@ func testState(t *testing.T) multistep.StateBag {
state.Put("ui", &packersdk.BasicUi{ state.Put("ui", &packersdk.BasicUi{
Reader: new(bytes.Buffer), Reader: new(bytes.Buffer),
Writer: new(bytes.Buffer), Writer: new(bytes.Buffer),
PB: &packer.NoopProgressTracker{}, PB: &packersdk.NoopProgressTracker{},
}) })
return state return state
} }

View File

@ -150,3 +150,12 @@ func (rw *BasicUi) Machine(t string, args ...string) {
func (rw *BasicUi) TrackProgress(src string, currentSize, totalSize int64, stream io.ReadCloser) (body io.ReadCloser) { func (rw *BasicUi) TrackProgress(src string, currentSize, totalSize int64, stream io.ReadCloser) (body io.ReadCloser) {
return rw.PB.TrackProgress(src, currentSize, totalSize, stream) return rw.PB.TrackProgress(src, currentSize, totalSize, stream)
} }
// NoopProgressTracker is a progress tracker
// that displays nothing.
type NoopProgressTracker struct{}
// TrackProgress returns stream
func (*NoopProgressTracker) TrackProgress(_ string, _, _ int64, stream io.ReadCloser) io.ReadCloser {
return stream
}

View File

@ -13,6 +13,7 @@ func TestUi(t *testing.T) Ui {
Reader: &buf, Reader: &buf,
Writer: ioutil.Discard, Writer: ioutil.Discard,
ErrorWriter: ioutil.Discard, ErrorWriter: ioutil.Discard,
PB: &NoopProgressTracker{},
} }
} }

View File

@ -1,12 +0,0 @@
package packer
import "io"
// NoopProgressTracker is a progress tracker
// that displays nothing.
type NoopProgressTracker struct{}
// TrackProgress returns stream
func (*NoopProgressTracker) TrackProgress(_ string, _, _ int64, stream io.ReadCloser) io.ReadCloser {
return stream
}

View File

@ -1,3 +1,7 @@
package packer package packer
type UiProgressBar = NoopProgressTracker import (
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
)
type UiProgressBar = packersdk.NoopProgressTracker

View File

@ -31,7 +31,7 @@ const (
) )
type NoopUi struct { type NoopUi struct {
PB NoopProgressTracker PB packersdk.NoopProgressTracker
} }
var _ packersdk.Ui = new(NoopUi) var _ packersdk.Ui = new(NoopUi)
@ -173,7 +173,7 @@ func (u *TargetedUI) TrackProgress(src string, currentSize, totalSize int64, str
// to the given Writer. // to the given Writer.
type MachineReadableUi struct { type MachineReadableUi struct {
Writer io.Writer Writer io.Writer
PB NoopProgressTracker PB packersdk.NoopProgressTracker
} }
var _ packersdk.Ui = new(MachineReadableUi) var _ packersdk.Ui = new(MachineReadableUi)

View File

@ -10,7 +10,6 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/hashicorp/packer/packer"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer" packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
) )
@ -127,7 +126,7 @@ func TestProvisionerProvision_SendsFile(t *testing.T) {
b := bytes.NewBuffer(nil) b := bytes.NewBuffer(nil)
ui := &packersdk.BasicUi{ ui := &packersdk.BasicUi{
Writer: b, Writer: b,
PB: &packer.NoopProgressTracker{}, PB: &packersdk.NoopProgressTracker{},
} }
comm := &packersdk.MockCommunicator{} comm := &packersdk.MockCommunicator{}
err = p.Provision(context.Background(), ui, comm, make(map[string]interface{})) err = p.Provision(context.Background(), ui, comm, make(map[string]interface{}))
@ -186,7 +185,7 @@ func TestProvisionerProvision_SendsFileMultipleFiles(t *testing.T) {
b := bytes.NewBuffer(nil) b := bytes.NewBuffer(nil)
ui := &packersdk.BasicUi{ ui := &packersdk.BasicUi{
Writer: b, Writer: b,
PB: &packer.NoopProgressTracker{}, PB: &packersdk.NoopProgressTracker{},
} }
comm := &packersdk.MockCommunicator{} comm := &packersdk.MockCommunicator{}
err = p.Provision(context.Background(), ui, comm, make(map[string]interface{})) err = p.Provision(context.Background(), ui, comm, make(map[string]interface{}))
@ -256,7 +255,7 @@ func TestProvisionerProvision_SendsFileMultipleDirs(t *testing.T) {
b := bytes.NewBuffer(nil) b := bytes.NewBuffer(nil)
ui := &packersdk.BasicUi{ ui := &packersdk.BasicUi{
Writer: b, Writer: b,
PB: &packer.NoopProgressTracker{}, PB: &packersdk.NoopProgressTracker{},
} }
comm := &packersdk.MockCommunicator{} comm := &packersdk.MockCommunicator{}
err = p.Provision(context.Background(), ui, comm, make(map[string]interface{})) err = p.Provision(context.Background(), ui, comm, make(map[string]interface{}))
@ -308,7 +307,7 @@ func TestProvisionerProvision_SendsFileMultipleFilesToFolder(t *testing.T) {
b := bytes.NewBuffer(nil) b := bytes.NewBuffer(nil)
ui := &packersdk.BasicUi{ ui := &packersdk.BasicUi{
Writer: b, Writer: b,
PB: &packer.NoopProgressTracker{}, PB: &packersdk.NoopProgressTracker{},
} }
comm := &packersdk.MockCommunicator{} comm := &packersdk.MockCommunicator{}
err = p.Provision(context.Background(), ui, comm, make(map[string]interface{})) err = p.Provision(context.Background(), ui, comm, make(map[string]interface{}))
@ -366,7 +365,7 @@ func TestProvisionDownloadMkdirAll(t *testing.T) {
b := bytes.NewBuffer(nil) b := bytes.NewBuffer(nil)
ui := &packersdk.BasicUi{ ui := &packersdk.BasicUi{
Writer: b, Writer: b,
PB: &packer.NoopProgressTracker{}, PB: &packersdk.NoopProgressTracker{},
} }
comm := &packersdk.MockCommunicator{} comm := &packersdk.MockCommunicator{}
err = p.ProvisionDownload(ui, comm) err = p.ProvisionDownload(ui, comm)