/
config_test.go
84 lines (60 loc) · 1.31 KB
/
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
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
// Copyright 2012 GAEGo Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package config
import (
"github.com/gaego/context"
"testing"
)
func checkErr(t *testing.T, err error) {
if err != nil {
t.Errorf(`err: %v, want nil`, err)
}
}
func tearDown() {
context.Close()
}
func TestGetOrInsert(t *testing.T) {
defer context.Close()
c := context.NewContext(nil)
// Set it.
m := map[string]string{
"A": "1",
}
cnfg, err := GetOrInsert(c, "first", m)
// Confirm.
checkErr(t, err)
if x := cnfg.Values["A"]; x != "1" {
t.Errorf(`config["A"]: %v, want %v`, x, "1")
}
// The orginal map should be returned.
m = map[string]string{
"A": "2",
}
cnfg, err = GetOrInsert(c, "first", m)
// Confirm.
checkErr(t, err)
if x := cnfg.Values["A"]; x != "1" {
t.Errorf(`config["A"]: %v, want %v`, x, "1")
}
}
func TestEdit(t *testing.T) {
defer context.Close()
c := context.NewContext(nil)
// Set it.
m := map[string]string{
"A": "1",
}
cnfg, err := GetOrInsert(c, "first", m)
// Change it.
cnfg.Values["A"] = "2"
// Save it.
err = cnfg.Put(c)
checkErr(t, err)
// Confirm.
cnfg, err = Get(c, "first")
checkErr(t, err)
if x := cnfg.Values["A"]; x != "2" {
t.Errorf(`cnfg["A"]: %v, want %v`, x, "2")
}
}