File: config_test.go

package info (click to toggle)
tendermint-go-config 0.0~git20160626.0.e64b424-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid, stretch
  • size: 88 kB
  • ctags: 28
  • sloc: sh: 23; makefile: 2
file content (86 lines) | stat: -rw-r--r-- 1,596 bytes parent folder | download
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
package config

import (
	"testing"

	"github.com/BurntSushi/toml"
	. "github.com/tendermint/go-common"
)

var (
	stringTable = map[string]string{
		"astring":                  "a",
		"subfield1.astring":        "b",
		"subfield1.subsub.astring": "b",
		"subfield2.astring":        "c",
	}

	intTable = map[string]int{
		"anint": 42,
	}

	boolTable = map[string]bool{
		"abool": false,
	}
)

var testTxt = Fmt(`

# This is a TOML config file.
# For more information, see https://github.com/toml-lang/toml


astring = "%s"
anint = %d
abool = %v

[subfield1]
	astring = "%s"
	[subfield1.subsub]
	astring = "%s"


[subfield2]
astring = "%s"
`, stringTable["astring"], intTable["anint"], boolTable["abool"], stringTable["subfield1.astring"],
	stringTable["subfield1.subsub.astring"],
	stringTable["subfield2.astring"])

func TestConfig(t *testing.T) {
	var configData = make(map[string]interface{})
	err := toml.Unmarshal([]byte(testTxt), &configData)
	if err != nil {
		t.Fatal(err)
	}

	cfg := NewMapConfig(configData)

	for k, v := range stringTable {
		if x := cfg.GetString(k); x != v {
			t.Fatalf("Got %v. Expected %v", x, v)
		}
	}

	for k, v := range intTable {
		if x := cfg.GetInt(k); x != v {
			t.Fatalf("Got %v. Expected %v", x, v)
		}
	}

	for k, v := range boolTable {
		if x := cfg.GetBool(k); x != v {
			t.Fatalf("Got %v. Expected %v", x, v)
		}
	}

}

func TestSetConfig(t *testing.T) {
	var configData = make(map[string]interface{})

	cfg := NewMapConfig(configData)
	cfg.Set("abc.def", "x")
	if x := cfg.GetString("abc.def"); x != "x" {
		t.Fatalf("Got %v, expected 1", x)
	}
}