Skip to content

Commit

Permalink
Add test for quiet
Browse files Browse the repository at this point in the history
  • Loading branch information
carlpett authored and frapposelli committed Mar 23, 2018
1 parent 856306a commit 59feff9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
10 changes: 6 additions & 4 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ var (
date = "1961-02-13T20:06:35Z"
)

func setQuiet() error {
log.SetLevel(log.WarnLevel)
return nil
}

func newCli() *flags.Parser {
opts := cliOpts{
VersionFlag: func() error {
Expand All @@ -40,10 +45,7 @@ func newCli() *flags.Parser {
Message: fmt.Sprintf("version %s\ncommit %s\ndate %s\n", version, commit, date),
}
},
Quiet: func() error {
log.SetLevel(log.WarnLevel)
return nil
},
Quiet: setQuiet,
}
parser := flags.NewParser(&opts, flags.HelpFlag|flags.PassDoubleDash)
parser.LongDescription = "What would Henry Rollins do?"
Expand Down
11 changes: 11 additions & 0 deletions cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ func TestCliListSuccess(t *testing.T) {
}
}

func TestCliQuiet(t *testing.T) {
initial := log.GetLevel()
defer log.SetLevel(initial)

err := setQuiet()
assert.NoError(t, err)

after := log.GetLevel()
assert.Equal(t, log.WarnLevel, after)
}

func TestCliCheck(t *testing.T) {
parser := newCli()
var out = &bytes.Buffer{}
Expand Down

0 comments on commit 59feff9

Please sign in to comment.