-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_test.go
64 lines (51 loc) · 1.41 KB
/
config_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
package main
import (
"os"
"testing"
)
func TestConfigStorage_LoadFromEmptyFile(t *testing.T) {
storage := NewConfigStorage("")
config := storage.Load()
if len(config.Github.Username) > 0 {
t.Errorf("I expected to get empty usename")
}
}
func TestConfigStorage_LoadFromUnexistingFile(t *testing.T) {
storage := NewConfigStorage("")
config := storage.Load()
if len(config.Github.Username) > 0 {
t.Errorf("I expected to get empty usename")
}
}
func TestConfigStorage_Load(t *testing.T) {
storage := NewConfigStorage("testdata/not-empty-config.json")
config := storage.Load()
if config.Github.Username != "john" {
t.Errorf("I expected to get username \"john\" but got \"%s\"", config.Github.Username)
}
}
func TestConfigStorage_SaveEmptyFileName(t *testing.T) {
storage := NewConfigStorage("")
config := &Config{}
err := storage.Save(config)
if err != nil {
t.Errorf("I got unexpected error '%s'", err)
}
}
func TestConfigStorage_SaveWithNewFileName(t *testing.T) {
fileName := "testdata/test.json"
storage := NewConfigStorage(fileName)
config := &Config{Github: GithubConfig{
Username: "jack",
Token: "daniels",
}}
err := storage.Save(config)
defer os.Remove(fileName)
if err != nil {
t.Errorf("I got unexpected error '%s'", err)
}
config = storage.Load()
if config.Github.Username != "jack" {
t.Errorf("I expected to get username \"jack\" but got \"%s\"", config.Github.Username)
}
}