github.com/mitchellh/packer@v1.3.2/builder/docker/artifact_import_test.go (about)

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