-
Notifications
You must be signed in to change notification settings - Fork 35
/
profile_test.go
83 lines (65 loc) · 1.5 KB
/
profile_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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"os"
"path/filepath"
"testing"
)
func Test_profileOpenClose(t *testing.T) {
if profileDb_ != nil {
t.Error("profileDb_ should be nil")
}
pwd, _ := os.Getwd()
homeDir_ = filepath.Join(pwd, "homedirtest")
err := profileOpen()
if err != nil {
t.Errorf("Expected no error, got %s", err)
}
if profileDb_ == nil {
t.Error("profileDb_ should be set")
}
profileClose()
if profileDb_ != nil {
t.Error("profileDb_ should be nil")
}
profileDelete()
}
func Test_profileFolder(t *testing.T) {
setup(t)
defer teardown(t)
profileFolder := profileFolder()
stat, err := os.Stat(profileFolder)
if err != nil {
t.Error(err)
}
if !stat.IsDir() {
t.Errorf("config folder is not a directory: %s", profileFolder)
}
}
func Test_handleConfigCommand_noArgs(t *testing.T) {
setup(t)
defer teardown(t)
var opts CommandLineOptions
var err error
err = handleConfigCommand(&opts, []string{})
if err != nil {
t.Error("Expected no error")
}
err = handleConfigCommand(&opts, []string{"testing", "123"})
if err != nil {
t.Errorf("Expected no error, got %s", err)
}
if config_.String("testing") != "123" {
t.Error("Value not set correctly")
}
handleConfigCommand(&opts, []string{"testing", "abcd"})
if config_.String("testing") != "abcd" {
t.Error("Value has not been changed")
}
err = handleConfigCommand(&opts, []string{"testing"})
if err != nil {
t.Errorf("Expected no error, got %s", err)
}
if config_.HasKey("testing") {
t.Error("Key has not been deleted")
}
}