mirror of
https://github.com/status-im/consul.git
synced 2025-02-02 08:56:43 +00:00
Encode/Decode test
This commit is contained in:
parent
f37f5fde54
commit
ad445f5ac2
@ -1 +1,34 @@
|
|||||||
package structs
|
package structs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestEncodeDecode(t *testing.T) {
|
||||||
|
arg := &RegisterRequest{
|
||||||
|
Datacenter: "foo",
|
||||||
|
Node: "bar",
|
||||||
|
Address: "baz",
|
||||||
|
Service: &NodeService{
|
||||||
|
Service: "test",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
buf, err := Encode(RegisterRequestType, arg)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var out RegisterRequest
|
||||||
|
err = Decode(buf[1:], &out)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(arg.Service, out.Service) {
|
||||||
|
t.Fatalf("bad: %#v %#v", arg.Service, out.Service)
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(arg, &out) {
|
||||||
|
t.Fatalf("bad: %#v %#v", arg, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user