github.com/kaixiang/packer@v0.5.2-0.20140114230416-1f5786b0d7f1/command/fix/fixer_createtime_test.go (about)

     1  package fix
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  )
     7  
     8  func TestFixerCreateTime_Impl(t *testing.T) {
     9  	var raw interface{}
    10  	raw = new(FixerCreateTime)
    11  	if _, ok := raw.(Fixer); !ok {
    12  		t.Fatalf("must be a Fixer")
    13  	}
    14  }
    15  
    16  func TestFixerCreateTime_Fix(t *testing.T) {
    17  	var f FixerCreateTime
    18  
    19  	input := map[string]interface{}{
    20  		"builders": []interface{}{
    21  			map[string]string{
    22  				"type":     "foo",
    23  				"ami_name": "{{.CreateTime}} foo",
    24  			},
    25  		},
    26  	}
    27  
    28  	expected := map[string]interface{}{
    29  		"builders": []map[string]interface{}{
    30  			map[string]interface{}{
    31  				"type":     "foo",
    32  				"ami_name": "{{timestamp}} foo",
    33  			},
    34  		},
    35  	}
    36  
    37  	output, err := f.Fix(input)
    38  	if err != nil {
    39  		t.Fatalf("err: %s", err)
    40  	}
    41  
    42  	if !reflect.DeepEqual(output, expected) {
    43  		t.Fatalf("unexpected: %#v\nexpected: %#v\n", output, expected)
    44  	}
    45  }