-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathroot_test.go
46 lines (39 loc) · 1.04 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
package cmd
import (
"os/user"
"path/filepath"
"testing"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
)
func TestRootCmd(t *testing.T) {
t.Run("ToOptions", func(t *testing.T) {
t.Run("WithConfigHome", func(t *testing.T) {
f := &RootFlags{
ConfigHome: "/path/to/config",
}
options, err := f.ToOptions()
assert.NoError(t, err)
assert.Equal(t, "/path/to/config", options.ConfigHome)
})
})
t.Run("Complete", func(t *testing.T) {
t.Run("WithConfigHome", func(t *testing.T) {
o := &RootOptions{
ConfigHome: "/path/to/config",
}
err := o.Complete()
assert.NoError(t, err)
assert.Equal(t, "/path/to/config", o.ConfigHome)
})
t.Run("WithoutConfigHome", func(t *testing.T) {
currentUser, err := user.Current()
assert.NoError(t, err)
o := &RootOptions{}
err = o.Complete()
assert.NoError(t, err)
assert.Equal(t, filepath.Join(currentUser.HomeDir, ".kitops"), o.ConfigHome)
assert.Equal(t, filepath.Join(currentUser.HomeDir, ".kitops"), viper.GetString("config"))
})
})
}