/
root_test.go
49 lines (37 loc) · 1.05 KB
/
root_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
39
40
41
42
43
44
45
46
47
48
49
package cmd
import (
"bytes"
"testing"
"github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
"github.com/stretchr/testify/require"
)
func executeCommand(root *cobra.Command, args ...string) (output string, err error) {
_, output, err = executeCommandC(root, args...)
return output, err
}
func executeCommandC(root *cobra.Command, args ...string) (c *cobra.Command, output string, err error) {
buf := new(bytes.Buffer)
root.SetOutput(buf)
root.SetArgs(args)
c, err = root.ExecuteC()
return c, buf.String(), err
}
func TestGetPathNoXDG(t *testing.T) {
actual := Config.GetConfigFolder("")
expected, err := homedir.Dir()
expected += "/.config/stripe"
require.Nil(t, err)
require.Equal(t, actual, expected)
}
func TestGetPathXDG(t *testing.T) {
actual := Config.GetConfigFolder("/some/xdg/path")
expected := "/some/xdg/path/stripe"
require.Equal(t, actual, expected)
}
func TestHelpFlag(t *testing.T) {
Execute()
output, err := executeCommand(rootCmd, "--help")
require.Contains(t, output, "Stripe commands:")
require.NoError(t, err)
}