github.phpd.cn/hashicorp/packer@v1.3.2/builder/amazon/common/artifact_test.go (about)

     1  package common
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  
     7  	"github.com/hashicorp/packer/packer"
     8  )
     9  
    10  func TestArtifact_Impl(t *testing.T) {
    11  	var _ packer.Artifact = new(Artifact)
    12  }
    13  
    14  func TestArtifactId(t *testing.T) {
    15  	expected := `east:foo,west:bar`
    16  
    17  	amis := make(map[string]string)
    18  	amis["east"] = "foo"
    19  	amis["west"] = "bar"
    20  
    21  	a := &Artifact{
    22  		Amis: amis,
    23  	}
    24  
    25  	result := a.Id()
    26  	if result != expected {
    27  		t.Fatalf("bad: %s", result)
    28  	}
    29  }
    30  
    31  func TestArtifactState_atlasMetadata(t *testing.T) {
    32  	a := &Artifact{
    33  		Amis: map[string]string{
    34  			"east": "foo",
    35  			"west": "bar",
    36  		},
    37  	}
    38  
    39  	actual := a.State("atlas.artifact.metadata")
    40  	expected := map[string]string{
    41  		"region.east": "foo",
    42  		"region.west": "bar",
    43  	}
    44  	if !reflect.DeepEqual(actual, expected) {
    45  		t.Fatalf("bad: %#v", actual)
    46  	}
    47  }
    48  
    49  func TestArtifactString(t *testing.T) {
    50  	expected := `AMIs were created:
    51  east: foo
    52  west: bar
    53  `
    54  
    55  	amis := make(map[string]string)
    56  	amis["east"] = "foo"
    57  	amis["west"] = "bar"
    58  
    59  	a := &Artifact{Amis: amis}
    60  	result := a.String()
    61  	if result != expected {
    62  		t.Fatalf("bad: %s", result)
    63  	}
    64  }