2014-01-19 22:48:06 -05:00
|
|
|
package docker
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"testing"
|
2018-01-22 20:21:10 -05:00
|
|
|
|
2020-11-19 15:17:11 -05:00
|
|
|
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
2014-01-19 22:48:06 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestImportArtifact_impl(t *testing.T) {
|
2020-11-19 15:17:11 -05:00
|
|
|
var _ packersdk.Artifact = new(ImportArtifact)
|
2014-01-19 22:48:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestImportArtifactBuilderId(t *testing.T) {
|
|
|
|
a := &ImportArtifact{BuilderIdValue: "foo"}
|
|
|
|
if a.BuilderId() != "foo" {
|
|
|
|
t.Fatalf("bad: %#v", a.BuilderId())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestImportArtifactFiles(t *testing.T) {
|
|
|
|
a := &ImportArtifact{}
|
|
|
|
if a.Files() != nil {
|
|
|
|
t.Fatalf("bad: %#v", a.Files())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestImportArtifactId(t *testing.T) {
|
|
|
|
a := &ImportArtifact{IdValue: "foo"}
|
|
|
|
if a.Id() != "foo" {
|
|
|
|
t.Fatalf("bad: %#v", a.Id())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestImportArtifactDestroy(t *testing.T) {
|
|
|
|
d := new(MockDriver)
|
|
|
|
a := &ImportArtifact{
|
|
|
|
Driver: d,
|
|
|
|
IdValue: "foo",
|
|
|
|
}
|
|
|
|
|
|
|
|
// No error
|
|
|
|
if err := a.Destroy(); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
if !d.DeleteImageCalled {
|
|
|
|
t.Fatal("delete image should be called")
|
|
|
|
}
|
|
|
|
if d.DeleteImageId != "foo" {
|
|
|
|
t.Fatalf("bad: %#v", d.DeleteImageId)
|
|
|
|
}
|
|
|
|
|
|
|
|
// With an error
|
|
|
|
d.DeleteImageErr = errors.New("foo")
|
|
|
|
if err := a.Destroy(); err != d.DeleteImageErr {
|
|
|
|
t.Fatalf("err: %#v", err)
|
|
|
|
}
|
|
|
|
}
|