Skip to content

Commit

Permalink
Check the wire representation by changing the deser target
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed Jun 26, 2024
1 parent f161ffc commit 48791f3
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions dispatchproto/any_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,28 @@ func TestAnyTextMarshaler(t *testing.T) {
if err != nil {
t.Fatal(err)
}

var v2 *textMarshaler // (pointer)
if err := boxed.Unmarshal(&v2); err != nil {
t.Fatal(err)
} else if v2.value != v.value {
t.Errorf("unexpected serialized value: %v", v2.value)
}

var v3 textMarshaler // (not a pointer)
if err := boxed.Unmarshal(&v3); err != nil {
t.Fatal(err)
} else if v3.value != v.value {
t.Errorf("unexpected serialized value: %v", v3.value)
}

// Check a string is sent on the wire.
var v4 string
if err := boxed.Unmarshal(&v4); err != nil {
t.Fatal(err)
} else if v4 != v.value {
t.Errorf("unexpected serialized value: %v", v4)
}
}

func TestAnyBinaryMarshaler(t *testing.T) {
Expand All @@ -161,18 +171,28 @@ func TestAnyBinaryMarshaler(t *testing.T) {
if err != nil {
t.Fatal(err)
}

var v2 *binaryMarshaler // (pointer)
if err := boxed.Unmarshal(&v2); err != nil {
t.Fatal(err)
} else if !bytes.Equal(v2.value, v.value) {
t.Errorf("unexpected serialized value: %v", v2.value)
}

var v3 binaryMarshaler // (not a pointer)
if err := boxed.Unmarshal(&v3); err != nil {
t.Fatal(err)
} else if !bytes.Equal(v3.value, v.value) {
t.Errorf("unexpected serialized value: %v", v3.value)
}

// Check bytes are sent on the wire.
var v4 []byte
if err := boxed.Unmarshal(&v4); err != nil {
t.Fatal(err)
} else if !bytes.Equal(v4, v.value) {
t.Errorf("unexpected serialized value: %v", v4)
}
}

func TestOverflow(t *testing.T) {
Expand Down

0 comments on commit 48791f3

Please sign in to comment.