github.com/sneal/packer@v0.5.2/builder/docker/artifact_import_test.go (about)

     1  package docker
     2  
     3  import (
     4  	"errors"
     5  	"github.com/mitchellh/packer/packer"
     6  	"testing"
     7  )
     8  
     9  func TestImportArtifact_impl(t *testing.T) {
    10  	var _ packer.Artifact = new(ImportArtifact)
    11  }
    12  
    13  func TestImportArtifactBuilderId(t *testing.T) {
    14  	a := &ImportArtifact{BuilderIdValue: "foo"}
    15  	if a.BuilderId() != "foo" {
    16  		t.Fatalf("bad: %#v", a.BuilderId())
    17  	}
    18  }
    19  
    20  func TestImportArtifactFiles(t *testing.T) {
    21  	a := &ImportArtifact{}
    22  	if a.Files() != nil {
    23  		t.Fatalf("bad: %#v", a.Files())
    24  	}
    25  }
    26  
    27  func TestImportArtifactId(t *testing.T) {
    28  	a := &ImportArtifact{IdValue: "foo"}
    29  	if a.Id() != "foo" {
    30  		t.Fatalf("bad: %#v", a.Id())
    31  	}
    32  }
    33  
    34  func TestImportArtifactDestroy(t *testing.T) {
    35  	d := new(MockDriver)
    36  	a := &ImportArtifact{
    37  		Driver:  d,
    38  		IdValue: "foo",
    39  	}
    40  
    41  	// No error
    42  	if err := a.Destroy(); err != nil {
    43  		t.Fatalf("err: %s", err)
    44  	}
    45  	if !d.DeleteImageCalled {
    46  		t.Fatal("delete image should be called")
    47  	}
    48  	if d.DeleteImageId != "foo" {
    49  		t.Fatalf("bad: %#v", d.DeleteImageId)
    50  	}
    51  
    52  	// With an error
    53  	d.DeleteImageErr = errors.New("foo")
    54  	if err := a.Destroy(); err != d.DeleteImageErr {
    55  		t.Fatalf("err: %#v", err)
    56  	}
    57  }