-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper_test.go
66 lines (62 loc) · 1.19 KB
/
helper_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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package toolsconfig
import (
"os"
"reflect"
"testing"
"github.com/stretchr/testify/require"
)
func Test_defaultConfigFileName(t *testing.T) {
type args struct {
dir string
file string
}
userHomedir, err := os.UserHomeDir()
require.NoError(t, err)
tests := []struct {
name string
args args
want string
wantErr bool
}{
{
name: "relative path",
args: args{
dir: ".",
file: "testfile",
},
want: "testfile",
wantErr: false,
},
{
name: "absolute path",
args: args{
dir: "/tmp",
file: "testfile",
},
want: "/tmp/testfile",
wantErr: false,
},
{
name: "homedir path",
args: args{
dir: ".toolsconfig",
file: "testfile",
},
want: userHomedir + "/.toolsconfig/testfile",
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := configFileName(tt.args.dir, tt.args.file)
if (err != nil) != tt.wantErr {
t.Errorf("defaultConfigFileName() error = %v, wantErr %v", err, tt.wantErr)
return
}
require.NotNil(t, got)
if !reflect.DeepEqual(*got, tt.want) {
t.Errorf("defaultConfigFileName() got = %v, want %v", got, tt.want)
}
})
}
}