github.com/timsutton/packer@v1.3.2/command/fix_test.go (about) 1 package command 2 3 import ( 4 "path/filepath" 5 "strings" 6 "testing" 7 8 "github.com/hashicorp/packer/packer" 9 "github.com/stretchr/testify/assert" 10 ) 11 12 func TestFix(t *testing.T) { 13 s := &strings.Builder{} 14 ui := &packer.BasicUi{ 15 Writer: s, 16 } 17 c := &FixCommand{ 18 Meta: testMeta(t), 19 } 20 21 c.Ui = ui 22 23 args := []string{filepath.Join(testFixture("fix"), "template.json")} 24 if code := c.Run(args); code != 0 { 25 fatalCommand(t, c.Meta) 26 } 27 expected := `{ 28 "builders": [ 29 { 30 "type": "dummy" 31 } 32 ], 33 "push": { 34 "name": "foo/bar" 35 } 36 }` 37 assert.Equal(t, expected, strings.TrimSpace(s.String())) 38 } 39 40 func TestFix_invalidTemplate(t *testing.T) { 41 c := &FixCommand{ 42 Meta: testMeta(t), 43 } 44 45 args := []string{filepath.Join(testFixture("fix-invalid"), "template.json")} 46 if code := c.Run(args); code != 1 { 47 fatalCommand(t, c.Meta) 48 } 49 } 50 51 func TestFix_invalidTemplateDisableValidation(t *testing.T) { 52 c := &FixCommand{ 53 Meta: testMeta(t), 54 } 55 56 args := []string{ 57 "-validate=false", 58 filepath.Join(testFixture("fix-invalid"), "template.json"), 59 } 60 if code := c.Run(args); code != 0 { 61 fatalCommand(t, c.Meta) 62 } 63 }