Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Pavol Loffay <[email protected]>
  • Loading branch information
pavolloffay committed Jun 3, 2019
1 parent 367a109 commit c4a2b1f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/docs/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func Command(v *viper.Viper) *cobra.Command {
case "rst":
doc.GenReSTTree(cmd, "./")
default:
return errors.New("undefined format")
return errors.New(fmt.Sprintf("undefined value of %v, possible values are: %v", formatFlag, formats))
}

return nil
Expand Down
14 changes: 10 additions & 4 deletions cmd/docs/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,25 @@ func TestCommand(t *testing.T) {
tests := []struct{
file string
flag string
err string
}{
{file: "docs.md"},
{file: "docs.1", flag: "--format=man"},
{file: "docs.rst", flag: "--format=rst"},
{flag: "--format=foo", err: "undefined value of format, possible values are: [md man rst]"},
}
for _, test := range tests {
v := viper.New()
cmd := Command(v)
cmd.ParseFlags([]string{test.flag})
cmd.RunE(cmd, []string{})
f, err := ioutil.ReadFile(test.file)
require.NoError(t, err)
assert.True(t, strings.Contains(string(f), "documentation"))
err := cmd.Execute()
if err == nil {
f, err := ioutil.ReadFile(test.file)
require.NoError(t, err)
assert.True(t, strings.Contains(string(f), "documentation"))
} else {
assert.Equal(t, test.err, err.Error())
}
}
}

Expand Down

0 comments on commit c4a2b1f

Please sign in to comment.