-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathipctransit_test.go
66 lines (62 loc) · 1.51 KB
/
ipctransit_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
package ipctransit
import (
"fmt"
"os"
// "reflect"
"testing"
)
var Test_qname string = "ipc-transit-test-queue"
func TestSendRcv(t *testing.T) {
defer func() {
os.Remove(defaultTransitPath + Test_qname)
}()
// How to create this message: http://play.golang.org/p/13OSJHd5xe
// Info about seemingly fully dynamic marshal/unmarshal: http://stackoverflow.com/questions/19482612/go-golang-array-type-inside-struct-missing-type-composite-literal
sendMessage := map[string]interface{}{
"Name": "Wednesday",
"Age": 6,
"Parents": map[string]interface{}{
"bee": "boo",
"foo": map[string]interface{}{
"hi": []string{"a", "b"},
},
},
}
sendErr := Send(sendMessage, Test_qname)
if sendErr != nil {
t.Error(sendErr)
return
}
m, receiveErr := Receive(Test_qname)
if receiveErr != nil {
t.Error(receiveErr)
return
}
msg := m.(map[string]interface{})
for k, v := range msg {
//fmt.Println(k, " -> ", reflect.TypeOf(v))
switch vv := v.(type) {
case string:
if k == "Name" {
if v != "Wednesday" {
t.Error(receiveErr)
}
}
//fmt.Println(k, "is string", vv)
case float64:
if k == "Age" {
if v != 6.0 { //very strange, even though it's an int in the json, it unmarshalled as a float
t.Error(receiveErr)
}
}
//fmt.Println(k, "is float64", vv)
case map[string]interface{}:
//fmt.Println(k, "is an array:")
// for i, u := range vv {
// fmt.Println(i, u)
// }
default:
fmt.Println(k, "is of a type I don't know how to handle", vv)
}
}
}