-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaumbry_test.go
56 lines (44 loc) · 1012 Bytes
/
aumbry_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
package aumbry
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
. "github.com/franela/goblin"
)
type SampleConfig struct {
Database struct {
Host string
Port int
}
}
func Test(t *testing.T) {
g := Goblin(t)
g.Describe("Yaml", func() {
var tmpFile *os.File
var options map[string]string
g.BeforeEach(func() {
tmpFile, _ = ioutil.TempFile(os.TempDir(), "aumbry")
dn, fn := filepath.Split(tmpFile.Name())
options = make(map[string]string)
options["CONFIG_FILENAME"] = fn
options["CONFIG_SEARCH_PATH"] = dn
sample := "---\n" +
"top: tester\n" +
"database:\n" +
" host: 0.0.0.0\n" +
" port: 1234"
ioutil.WriteFile(tmpFile.Name(), []byte(sample), os.ModeExclusive)
})
g.AfterEach(func() {
os.Remove(tmpFile.Name())
})
g.It("Should load from a file", func() {
var cfg SampleConfig
a := New(YamlFile, &cfg, options)
a.Load()
g.Assert(cfg.Database.Host).Equal("0.0.0.0")
g.Assert(cfg.Database.Port).Equal(1234)
})
})
}