-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcombined_test.go
More file actions
76 lines (63 loc) · 1.71 KB
/
combined_test.go
File metadata and controls
76 lines (63 loc) · 1.71 KB
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
// (c) 2022 Rick Arnold. Licensed under the BSD license (see LICENSE).
package props
import (
"reflect"
"sort"
"testing"
)
func TestCombined(t *testing.T) {
c := &Combined{}
val, ok := c.Get("non.init")
if ok || val != "" {
t.Errorf("want: false, ''; got: %t, '%s'", ok, val)
}
p1 := NewProperties()
p1.Set("props.test.val1", "abc")
p1.Set("props.test.val2", "")
p2 := NewProperties()
p2.Set("props.test.val1", "def")
p2.Set("props.test.val2", "")
p2.Set("props.test.val3", "ghi")
c.Sources = []PropertyGetter{p1, p2}
val, ok = c.Get("props.test.val1")
if !ok || val != "abc" {
t.Errorf("want: true, 'abc'; got: %t, '%s'", ok, val)
}
val, ok = c.Get("props.test.val2")
if !ok || val != "" {
t.Errorf("want: true, ''; got: %t, '%s'", ok, val)
}
val, ok = c.Get("props.test.val3")
if !ok || val != "ghi" {
t.Errorf("want: true, 'ghi'; got %t, '%s'", ok, val)
}
val, ok = c.Get("props.test.val4")
if ok || val != "" {
t.Errorf("want: false, ''; got %t, '%s'", ok, val)
}
val = c.GetDefault("props.test.val1", "other")
if val != "abc" {
t.Errorf("want: 'abc'; got '%s'", val)
}
val = c.GetDefault("props.test.val4", "other")
if val != "other" {
t.Errorf("want: 'other'; got: '%s'", val)
}
}
func TestCombinedNames(t *testing.T) {
c := &Combined{}
p1 := NewProperties()
p1.Set("props.test.val1", "abc")
p1.Set("props.test.val2", "")
p2 := NewProperties()
p2.Set("props.test.val1", "def")
p2.Set("props.test.val2", "")
p2.Set("props.test.val3", "ghi")
c.Sources = []PropertyGetter{p1, p2}
want := []string{"props.test.val1", "props.test.val2", "props.test.val3"}
got := c.Names()
sort.Strings(got)
if !reflect.DeepEqual(got, want) {
t.Errorf("want: %v; got %v", want, got)
}
}