-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpath_test.go
73 lines (63 loc) · 1.51 KB
/
path_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
package goconf_test
import (
"testing"
"github.com/ah-its-andy/goconf"
"github.com/stretchr/testify/assert"
)
func TestCombinePathShouldPassed(t *testing.T) {
paths := []string{"a", "b", "c"}
expected := "a.b.c"
actual := goconf.CombinePath(paths...)
assert.Equal(t, expected, actual)
}
func TestCombinePathShouldPanic(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Errorf("The code did not panic")
}
}()
goconf.CombinePath()
}
func TestGetSectionKeyShouldPassed(t *testing.T) {
path := "a.b.c"
expected := "c"
actual := goconf.GetSectionKey(path)
assert.Equal(t, expected, actual)
}
func TestGetSectionNoKeyDelimiterShouldPassed(t *testing.T) {
path := "a:b"
expected := "a:b"
actual := goconf.GetSectionKey(path)
assert.Equal(t, expected, actual)
assert.NotSame(t, &expected, &actual)
}
func TestGetSectionShouldPanic(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Errorf("The code did not panic")
}
}()
goconf.GetSectionKey("")
}
func TestGetParentPathShouldPassed(t *testing.T) {
path := "a.b.c"
expected := "a.b"
actual, ok := goconf.GetParentPath(path)
assert.True(t, ok)
assert.Equal(t, expected, actual)
}
func TestGetParentFalseShouldPassed(t *testing.T) {
path := "a"
expected := ""
actual, ok := goconf.GetParentPath(path)
assert.False(t, ok)
assert.Equal(t, expected, actual)
}
func TestGetParentShouldPanic(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Errorf("The code did not panic")
}
}()
goconf.GetParentPath("")
}