github.com/goonzoid/gcli@v0.2.3-0.20150926213610-155587606ea1/command/validate_test.go (about) 1 package command 2 3 import ( 4 "fmt" 5 "path/filepath" 6 "testing" 7 8 "github.com/mitchellh/cli" 9 ) 10 11 func TestValidateCommand_implement(t *testing.T) { 12 var _ cli.Command = &ValidateCommand{} 13 } 14 15 func TestValidateCommand(t *testing.T) { 16 17 fixture := "./fixtures" 18 19 tests := []struct { 20 input string 21 exitCode int 22 }{ 23 { 24 input: "valid-design.toml", 25 exitCode: ExitCodeOK, 26 }, 27 28 { 29 input: "invalid-design.toml", 30 exitCode: ExitCodeFailed, 31 }, 32 } 33 34 for i, tt := range tests { 35 ui := new(cli.MockUi) 36 c := &ValidateCommand{ 37 Meta: Meta{ 38 UI: ui, 39 }, 40 } 41 input := filepath.Join(fixture, tt.input) 42 if code := c.Run([]string{input}); code != tt.exitCode { 43 t.Fatalf("#%d bad status code: %d, expects %d\n\n%s", i, code, tt.exitCode, ui.ErrorWriter.String()) 44 } 45 fmt.Println(ui.ErrorWriter.String()) 46 } 47 }