-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwriter_test.go
88 lines (78 loc) · 2.48 KB
/
writer_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
84
85
86
87
88
package ini
import "testing"
func TestAddNewSection(t *testing.T) {
conf := make(Config)
section := "section"
if conf.HasSection(section) {
t.Errorf("%#v has a section called %q", section)
}
err := conf.AddSection("section")
assertErrorIsNil(err, t)
if !conf.HasSection(section) {
t.Errorf("%#v still has no section called %q", section)
}
}
func TestAddExistingSection(t *testing.T) {
conf := &Config{"section": make(map[string]string)}
err := conf.AddSection("section")
assertErrorIsNotNil(err, t)
if err != DuplicateSectionError {
t.Errorf("expected DuplicateSectionError, got %v", err)
}
}
func TestRemoveNonExistingSection(t *testing.T) {
conf := make(Config)
err := conf.RemoveSection("doesnotexist")
assertErrorIsNotNil(err, t)
if err != NoSectionError {
t.Errorf("expected NoSectionError, got %v", err)
}
}
func TestRemoveExistingSection(t *testing.T) {
conf := &Config{
"section": {"prop": "val"},
"section2": make(map[string]string)}
err := conf.RemoveSection("section")
assertErrorIsNil(err, t)
expectedConf := &Config{"section2": make(map[string]string)}
assertConfigMapsEqual(conf, expectedConf, t)
}
func TestRemovePropertyFromNonExistingSection(t *testing.T) {
conf := make(Config)
err := conf.RemoveProperty("section", "prop")
assertErrorIsNotNil(err, t)
if err != NoSectionError {
t.Errorf("expected NoSectionError, got %v", err)
}
}
func TestRemoveNonExistingProperty(t *testing.T) {
conf := &Config{"section": make(map[string]string)}
err := conf.RemoveProperty("section", "doesnotexist")
assertErrorIsNotNil(err, t)
expectedError := NoPropertyError{"doesnotexist"}
if err != expectedError {
t.Errorf("expected %#v, got %#v", expectedError, err)
}
}
func TestRemoveExistingProperty(t *testing.T) {
conf := &Config{"section": {"prop": "value"}}
err := conf.RemoveProperty("section", "prop")
assertErrorIsNil(err, t)
expectedConf := &Config{"section": make(map[string]string)}
assertConfigMapsEqual(conf, expectedConf, t)
}
func TestSetPropertyValueMissingSection(t *testing.T) {
conf := make(Config)
err := conf.Set("section", "property", "value")
assertErrorIsNotNil(err, t)
if err != NoSectionError {
t.Errorf("expected NoSectionError, got %v", err)
}
}
func TestSetPropertyValueExistingSection(t *testing.T) {
conf := &Config{"section": make(map[string]string)}
err := conf.Set("section", "property", "value")
assertErrorIsNil(err, t)
expectedConf := &Config{"section": {"property": "value"}}
assertConfigMapsEqual(conf, expectedConf, t)
}