-
Notifications
You must be signed in to change notification settings - Fork 3
/
config_test.go
40 lines (32 loc) · 885 Bytes
/
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
package blox
import (
"testing"
"github.com/stretchr/testify/assert"
)
const base = `{
build_dir: string | *"_build"
data_dir: string | *"data"
schemata_dir: string | *"schemata"
static_dir: string | *"static"
}`
func TestGetString(t *testing.T) {
runtime, err := NewConfig(base)
if err != nil {
t.Fatal("Failed to create a NewRuntime, which should never happen")
}
err = runtime.LoadConfigString(`{
data_dir: "my-data-dir"
}`)
assert.Equal(t, nil, err)
// test non-existent key
_, err = runtime.GetString("data_dir_non_exist")
assert.NotEqual(t, nil, err)
// test defaulted key
schDir, err := runtime.GetString("schemata_dir")
assert.Equal(t, nil, err)
assert.Equal(t, "schemata", schDir)
// test parsed key
configString, err := runtime.GetString("data_dir")
assert.Equal(t, nil, err)
assert.Equal(t, "my-data-dir", configString)
}