-
Notifications
You must be signed in to change notification settings - Fork 3
/
log_test.go
64 lines (58 loc) · 1.38 KB
/
log_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
package util
import (
"reflect"
"testing"
)
func TestArgListToMap(t *testing.T) {
// single arg passed
result := ArgListToMap(1)
expected := map[string]interface{}{
"unknown": 1,
}
if !reflect.DeepEqual(result, expected) {
t.Log("expected:", expected)
t.Log("actual:", result)
t.Fatal("unexpected result")
}
// odd number of args
result = ArgListToMap("foo", 1, 2)
expected = map[string]interface{}{
"unknown": 2, "foo": 1,
}
if !reflect.DeepEqual(result, expected) {
t.Log("expected:", expected)
t.Log("actual:", result)
t.Fatal("unexpected result")
}
// normal case
result = ArgListToMap("foo", "bar", "fizz", "buzz")
expected = map[string]interface{}{
"foo": "bar", "fizz": "buzz",
}
if !reflect.DeepEqual(result, expected) {
t.Log("expected:", expected)
t.Log("actual:", result)
t.Fatal("unexpected result")
}
// int as key
result = ArgListToMap("foo", "bar", 1, "buzz")
expected = map[string]interface{}{
"foo": "bar", "1": "buzz",
}
if !reflect.DeepEqual(result, expected) {
t.Log("expected:", expected)
t.Log("actual:", result)
t.Fatal("unexpected result")
}
// duplicate keys
// last value is kept
result = ArgListToMap("foo", "bar", "foo", "buzz")
expected = map[string]interface{}{
"foo": "buzz",
}
if !reflect.DeepEqual(result, expected) {
t.Log("expected:", expected)
t.Log("actual:", result)
t.Fatal("unexpected result")
}
}