github.com/mmcquillan/packer@v1.1.1-0.20171009221028-c85cf0483a5d/command/fix_test.go (about)

     1  package command
     2  
     3  import (
     4  	"path/filepath"
     5  	"testing"
     6  )
     7  
     8  func TestFix_noArgs(t *testing.T) {
     9  	c := &PushCommand{Meta: testMeta(t)}
    10  	code := c.Run(nil)
    11  	if code != 1 {
    12  		t.Fatalf("bad: %#v", code)
    13  	}
    14  }
    15  
    16  func TestFix_multiArgs(t *testing.T) {
    17  	c := &PushCommand{Meta: testMeta(t)}
    18  	code := c.Run([]string{"one", "two"})
    19  	if code != 1 {
    20  		t.Fatalf("bad: %#v", code)
    21  	}
    22  }
    23  
    24  func TestFix(t *testing.T) {
    25  	c := &FixCommand{
    26  		Meta: testMeta(t),
    27  	}
    28  
    29  	args := []string{filepath.Join(testFixture("fix"), "template.json")}
    30  	if code := c.Run(args); code != 0 {
    31  		fatalCommand(t, c.Meta)
    32  	}
    33  }
    34  
    35  func TestFix_invalidTemplate(t *testing.T) {
    36  	c := &FixCommand{
    37  		Meta: testMeta(t),
    38  	}
    39  
    40  	args := []string{filepath.Join(testFixture("fix-invalid"), "template.json")}
    41  	if code := c.Run(args); code != 1 {
    42  		fatalCommand(t, c.Meta)
    43  	}
    44  }
    45  
    46  func TestFix_invalidTemplateDisableValidation(t *testing.T) {
    47  	c := &FixCommand{
    48  		Meta: testMeta(t),
    49  	}
    50  
    51  	args := []string{
    52  		"-validate=false",
    53  		filepath.Join(testFixture("fix-invalid"), "template.json"),
    54  	}
    55  	if code := c.Run(args); code != 0 {
    56  		fatalCommand(t, c.Meta)
    57  	}
    58  }