forked from ktr0731/evans
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcache_test.go
55 lines (47 loc) · 1.1 KB
/
cache_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
package cache
import (
"io"
"os"
"testing"
)
func TestMain(m *testing.M) {
// Create a temp dir to reserve dir name. But remove it, and create again later.
dir := os.TempDir()
oldCacheDir := os.Getenv("XDG_CACHE_HOME")
os.Setenv("XDG_CACHE_HOME", dir)
code := m.Run()
os.Setenv("XDG_CACHE_HOME", oldCacheDir)
os.Exit(code)
}
func TestCache(t *testing.T) {
t.Run("Get creates a new one", func(t *testing.T) {
_, err := Get()
if err != nil {
t.Fatalf("Get must not return an error, but got '%s'", err)
}
})
t.Run("the file is empty", func(t *testing.T) {
oldDecodeTOML := decodeTOML
defer func() {
decodeTOML = oldDecodeTOML
}()
// Do nothing.
decodeTOML = func(r io.Reader, v interface{}) error {
return nil
}
_, err := Get()
if err != nil {
t.Fatalf("Get must not return an error, but got '%s'", err)
}
})
t.Run("Save", func(t *testing.T) {
c, err := Get()
if err != nil {
t.Fatalf("Get must not return an error, but got '%s'", err)
}
c.Version = "5.0.0"
if err := c.Save(); err != nil {
t.Fatalf("must not return an error, but got '%s'", err)
}
})
}