forked from goraz/onion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfolder_layer_test.go
61 lines (51 loc) · 1.48 KB
/
folder_layer_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
package onion
import (
"bytes"
"io"
"os"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestFolderLayer(t *testing.T) {
Convey("FolderLayer test ", t, func() {
// Make sure there is two ile available in the tmp file system
tmp := os.TempDir()
dir := tmp + "/onion_folder"
So(os.MkdirAll(dir, 0744), ShouldBeNil)
path := dir + "/test.json"
data := `{"str" : "string_data","bool" : true,"integer" : 10 ,"nested" : {"key1" : "string","key2" : 100}}`
buf := bytes.NewBufferString(data)
f, err := os.Create(path)
So(err, ShouldBeNil)
_, err = io.Copy(f, buf)
So(err, ShouldBeNil)
defer func() {
_ = os.Remove(path)
}()
So(f.Close(), ShouldBeNil)
Convey("Check if the folder is loaded correctly ", func() {
fl := NewFolderLayer(dir, "test")
o := New()
err := o.AddLayer(fl)
So(err, ShouldBeNil)
So(o.GetStringDefault("str", ""), ShouldEqual, "string_data")
So(o.GetStringDefault("nested.key1", ""), ShouldEqual, "string")
So(o.GetIntDefault("nested.key2", 0), ShouldEqual, 100)
So(o.GetBoolDefault("bool", false), ShouldBeTrue)
a := New() // Just for test load again
So(a.AddLayer(fl), ShouldBeNil)
})
Convey("Check for the invalid ext", func() {
fl := NewFolderLayer(dir, "nofile")
o := New()
err = o.AddLayer(fl)
So(err, ShouldNotBeNil)
})
Convey("Check for the invalid config file name", func() {
fl := NewFolderLayer(dir, "[^")
o := New()
err = o.AddLayer(fl)
So(err, ShouldNotBeNil)
})
})
}