-
Notifications
You must be signed in to change notification settings - Fork 22
/
store_test.go
75 lines (59 loc) · 1.09 KB
/
store_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
package store
import (
"os"
"testing"
)
type Cat struct {
Name string
Big bool
}
type Settings struct {
Age int
Cats []Cat
RandomString string
}
func equal(a, b Settings) bool {
if a.Age != b.Age {
return false
}
if a.RandomString != b.RandomString {
return false
}
if len(a.Cats) != len(b.Cats) {
return false
}
for i, cat := range a.Cats {
if cat != b.Cats[i] {
return false
}
}
return true
}
func TestSaveLoad(t *testing.T) {
Init("store_test")
settings := Settings{
Age: 42,
Cats: []Cat{
Cat{"Rudolph", true},
Cat{"Patrick", false},
Cat{"Jeremy", true},
},
RandomString: "gophers are gonna conquer the world",
}
settingsFile := "path/to/preferences.toml"
err := Save(settingsFile, &settings)
if err != nil {
t.Fatalf("failed to save preferences: %s\n", err)
return
}
defer os.Remove(buildPlatformPath(settingsFile))
var newSettings Settings
err = Load(settingsFile, &newSettings)
if err != nil {
t.Fatalf("failed to load preferences: %s\n", err)
return
}
if !equal(settings, newSettings) {
t.Fatalf("broken")
}
}