github.com/zignig/go-ipfs@v0.0.0-20141111235910-c9e5fdf55a52/net/service/request_test.go (about) 1 package service 2 3 import ( 4 "bytes" 5 "testing" 6 ) 7 8 func TestMarshaling(t *testing.T) { 9 10 test := func(d1 []byte, rid1 RequestID) { 11 d2, err := wrapData(d1, rid1) 12 if err != nil { 13 t.Error(err) 14 } 15 16 d3, rid2, err := unwrapData(d2) 17 if err != nil { 18 t.Error(err) 19 } 20 21 d4, err := wrapData(d3, rid1) 22 if err != nil { 23 t.Error(err) 24 } 25 26 if !bytes.Equal(rid2, rid1) { 27 t.Error("RequestID fail") 28 } 29 30 if !bytes.Equal(d1, d3) { 31 t.Error("unmarshalled data should be the same") 32 } 33 34 if !bytes.Equal(d2, d4) { 35 t.Error("marshalled data should be the same") 36 } 37 } 38 39 test([]byte("foo"), []byte{1, 2, 3, 4}) 40 test([]byte("bar"), nil) 41 }