Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

failing test for backwards compatibility with omitempty #35

Closed
wants to merge 1 commit into from

Conversation

ebuchman
Copy link
Contributor

@ebuchman ebuchman commented Oct 5, 2017

Failing test illustrating unexpected behaviour with omitempty and binary encoding

Copy link
Contributor

@odeke-em odeke-em left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ebuchman the test seems to be failing with
reflect_test.go:842: Varint overflow
which doesn't seem to have a dependence on if we use ",omitempty" or not, please see

diff --git a/reflect_test.go b/reflect_test.go
index 965eb06..919292a 100644
--- a/reflect_test.go
+++ b/reflect_test.go
@@ -812,7 +812,7 @@ type MyStruct1 struct {
 
 type MyStruct2 struct {
 	A string `json:"a"`
-	B string `json:"b,omitempty"`
+	B string `json:"b"`
 }
 
 func TestReadOmitEmptyJSON(t *testing.T) {
@@ -835,6 +835,8 @@ func TestReadOmitEmptyBinary(t *testing.T) {
 	s2 := new(MyStruct2)
 
 	b := BinaryBytes(s)
+	bs := BinaryBytes(&MyStruct2{A: "hi"})
+	t.Logf("\nb: %x\nbs:%x\n", b, bs)
 	err := ReadBinaryBytes(b, s2)
 	if err != nil {
 		t.Fatal(err)

which fails the same, with

--- FAIL: TestReadOmitEmptyBinary (0.00s)
	reflect_test.go:839: 
		b: 0101026869
		bs:010102686900
	reflect_test.go:842: Varint overflow
FAIL
exit status 1
FAIL	github.com/tendermint/go-wire	0.010s

@ebuchman
Copy link
Contributor Author

Yep so this is expected behaviour of go-wire - it's not extensible like JSON or protobuf are. We should document that better.

@ebuchman ebuchman closed this Oct 10, 2017
liamsi pushed a commit that referenced this pull request Jul 3, 2018
liamsi pushed a commit that referenced this pull request Jul 3, 2018
@liamsi liamsi deleted the omit-empty branch October 30, 2018 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants