github.com/hashicorp/packer@v1.14.3/fix/fixer_createtime_test.go (about)

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