Skip to content

Commit

Permalink
Release v1.29.1
Browse files Browse the repository at this point in the history
Contains the following fix:
* streaming: Handle nil items in containers (#541)
  • Loading branch information
witriew authored Sep 1, 2021
2 parents efbbb99 + f7066fb commit 58a0fa2
Show file tree
Hide file tree
Showing 26 changed files with 255 additions and 87 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.29.1] - 2021-08-31
### Fixed
- Streaming encodes now handle `nil` items properly in containers.

## [1.29.0] - 2021-08-30
This release includes support for (de)serializing Thrift structs directly
to/from IO streams without converting them to the intermediate `wire.Value`
Expand Down Expand Up @@ -418,6 +422,7 @@ this release.
### Added
- Initial release.

[1.29.1]: https://github.com/thriftrw/thriftrw-go/compare/v1.29.0...v1.29.1
[1.29.0]: https://github.com/thriftrw/thriftrw-go/compare/v1.28.0...v1.29.0
[1.28.0]: https://github.com/thriftrw/thriftrw-go/compare/v1.27.0...v1.28.0
[1.27.0]: https://github.com/thriftrw/thriftrw-go/compare/v1.26.0...v1.27.0
Expand Down
29 changes: 23 additions & 6 deletions gen/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
package gen

import (
"bytes"
"encoding/json"
"testing"

tc "go.uber.org/thriftrw/gen/internal/tests/containers"
te "go.uber.org/thriftrw/gen/internal/tests/enums"
ts "go.uber.org/thriftrw/gen/internal/tests/structs"
"go.uber.org/thriftrw/protocol/binary"
"go.uber.org/thriftrw/wire"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -1278,7 +1280,7 @@ func TestContainerValidate(t *testing.T) {
{4, 5, 6},
},
},
wantError: "invalid [2]: value is nil",
wantError: "invalid list '[][]byte', index [2]: value is nil",
},
{
desc: "nil second element of array",
Expand All @@ -1289,14 +1291,14 @@ func TestContainerValidate(t *testing.T) {
{StartPoint: &ts.Point{X: 5, Y: 6}, EndPoint: &ts.Point{X: 7, Y: 8}},
},
},
wantError: "invalid [1]: value is nil",
wantError: "invalid list '[]*Edge', index [1]: value is nil",
},
{
desc: "nil set item",
value: &tc.ContainersOfContainers{
SetOfLists: [][]string{{}, nil},
},
wantError: "invalid set item: value is nil",
wantError: "invalid set '[]string': contains nil value",
},
{
desc: "nil map key",
Expand All @@ -1309,7 +1311,7 @@ func TestContainerValidate(t *testing.T) {
{Key: nil, Value: "foo"},
},
},
wantError: "invalid map key: value is nil",
wantError: "invalid map '[]struct{Key []byte; Value string}': key is nil",
},
{
desc: "nil map value",
Expand All @@ -1319,12 +1321,12 @@ func TestContainerValidate(t *testing.T) {
"foo": nil,
},
},
wantError: "invalid [foo]: value is nil",
wantError: "invalid map 'map[string][]byte', key [foo]: value is nil",
},
}

for _, tt := range tests {
t.Run(tt.desc, func(t *testing.T) {
t.Run(tt.desc+"/wire", func(t *testing.T) {
value, err := tt.value.ToWire()
if err == nil {
err = wire.EvaluateValue(value) // lazy error
Expand All @@ -1334,6 +1336,21 @@ func TestContainerValidate(t *testing.T) {
assert.Equal(t, tt.wantError, err.Error())
}
})

t.Run(tt.desc+"/streaming", func(t *testing.T) {
stt, ok := tt.value.(streamingThriftType)
require.True(t, ok)

var buf bytes.Buffer
sw := binary.Default.Writer(&buf)
defer func() {
assert.NoError(t, sw.Close())
}()

err := stt.Encode(sw)
require.Error(t, err)
assert.Equal(t, tt.wantError, err.Error())
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion gen/internal/tests/collision/collision.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gen/internal/tests/constants/constants.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 58a0fa2

Please sign in to comment.