-
Notifications
You must be signed in to change notification settings - Fork 8
/
main_test.go
38 lines (31 loc) · 972 Bytes
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"bytes"
"os"
"testing"
"github.com/goodhosts/cli/cmd"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)
// Run exported in tests to let subcommands call the main run
// Setup takes args slice and resets logrus and returns args to pass to App.Run
func setup(args ...string) ([]string, *bytes.Buffer) {
out := &bytes.Buffer{}
logrus.SetOutput(out)
a := os.Args[0:1]
a = append(a, args...)
return a, out
}
func TestVersion(t *testing.T) {
// test version passed in run()
args, out := setup("version")
assert.Nil(t, run(args))
assert.Equal(t, "goodhosts dev@none built on unknown", out.String())
// test that version@commit + date work
args, out = setup("version")
cmd.Version("test-version", "test-commit", "test-date")
assert.Nil(t, cmd.App.Run(args))
assert.Equal(t, "goodhosts test-version@test-commit built on test-date", out.String())
// reset for future tests
cmd.Version("dev", "none", "unknown")
}