1
1
package main
2
2
3
3
import (
4
+ "log"
4
5
"os"
5
6
"testing"
6
7
7
8
"github.com/stretchr/testify/assert"
8
9
)
9
10
11
+ func init () {
12
+ err := os .Setenv ("HOME" , "/home/testuser" )
13
+ if err != nil {
14
+ log .Fatalf ("Setenv failed" )
15
+ }
16
+ }
17
+
10
18
func TestGetEditorDefault (t * testing.T ) {
11
19
expected := "vi"
12
20
outcome := getEditor ()
@@ -24,10 +32,6 @@ func TestGetEditorWithEnvVariable(t *testing.T) {
24
32
}
25
33
26
34
func TestGetNotesDir (t * testing.T ) {
27
- err := os .Setenv ("HOME" , "/home/testuser" )
28
- if err != nil {
29
- t .Fatalf ("Setenv failed" )
30
- }
31
35
expected := "/home/testuser/dotfiles/notes"
32
36
outcome := getNotesDir ()
33
37
assert .Equal (t , expected , outcome )
@@ -41,6 +45,8 @@ func TestGetNotesDirWithCustomEnvVariable(t *testing.T) {
41
45
expected := "/some/other/path"
42
46
outcome := getNotesDir ()
43
47
assert .Equal (t , expected , outcome )
48
+
49
+ _ = os .Unsetenv ("NOTESDIR" )
44
50
}
45
51
46
52
func TestGetNotesDirUsesCustomEnvVariableOverHomeEnvVariable (t * testing.T ) {
@@ -55,6 +61,8 @@ func TestGetNotesDirUsesCustomEnvVariableOverHomeEnvVariable(t *testing.T) {
55
61
expected := "/some/other/path"
56
62
outcome := getNotesDir ()
57
63
assert .Equal (t , expected , outcome )
64
+
65
+ _ = os .Unsetenv ("NOTESDIR" )
58
66
}
59
67
60
68
func TestGetNotesDirUsesCustomEnvVariableWithoutTrailingSlash (t * testing.T ) {
@@ -65,6 +73,8 @@ func TestGetNotesDirUsesCustomEnvVariableWithoutTrailingSlash(t *testing.T) {
65
73
expected := "/some/other/path"
66
74
outcome := getNotesDir ()
67
75
assert .Equal (t , expected , outcome )
76
+
77
+ _ = os .Unsetenv ("NOTESDIR" )
68
78
}
69
79
70
80
func TestFindNotes (t * testing.T ) {
@@ -108,3 +118,9 @@ func TestFindNotesCaseInsensitivity(t *testing.T) {
108
118
result := findNotes (notes , "match" )
109
119
assert .Equal (t , 1 , len (result ))
110
120
}
121
+
122
+ func TestGetNote (t * testing.T ) {
123
+ expected := "/home/testuser/dotfiles/notes/git.txt"
124
+ outcome := getNote ("git" )
125
+ assert .Equal (t , expected , outcome )
126
+ }
0 commit comments