Update vendored deps, including AWS SDK, openpgp, ftp, ...

This commit is contained in:
Andrey Smirnov
2018-04-05 17:46:45 +03:00
parent cef4fefc40
commit 0e6ee35942
1497 changed files with 450721 additions and 68034 deletions
@@ -202,7 +202,7 @@ func (d *Decoder) decodeBinary(b []byte, v reflect.Value) error {
return nil
}
if v.Kind() != reflect.Slice {
if v.Kind() != reflect.Slice && v.Kind() != reflect.Array {
return &UnmarshalTypeError{Value: "binary", Type: v.Type()}
}
@@ -220,7 +220,7 @@ func (d *Decoder) decodeBinary(b []byte, v reflect.Value) error {
switch v.Type().Elem().Kind() {
case reflect.Uint8:
// Fallback to reflection copy for type aliased of []byte type
if v.IsNil() || v.Cap() < len(b) {
if v.Kind() != reflect.Array && (v.IsNil() || v.Cap() < len(b)) {
v.Set(reflect.MakeSlice(v.Type(), len(b), len(b)))
} else if v.Len() != len(b) {
v.SetLen(len(b))
@@ -229,10 +229,17 @@ func (d *Decoder) decodeBinary(b []byte, v reflect.Value) error {
v.Index(i).SetUint(uint64(b[i]))
}
default:
if v.Kind() == reflect.Array && v.Type().Elem().Kind() == reflect.Uint8 {
reflect.Copy(v, reflect.ValueOf(b))
if v.Kind() == reflect.Array {
switch v.Type().Elem().Kind() {
case reflect.Uint8:
reflect.Copy(v, reflect.ValueOf(b))
default:
return &UnmarshalTypeError{Value: "binary", Type: v.Type()}
}
break
}
return &UnmarshalTypeError{Value: "binary", Type: v.Type()}
}
@@ -251,6 +258,8 @@ func (d *Decoder) decodeBool(b *bool, v reflect.Value) error {
}
func (d *Decoder) decodeBinarySet(bs [][]byte, v reflect.Value) error {
isArray := false
switch v.Kind() {
case reflect.Slice:
// Make room for the slice elements if needed
@@ -260,6 +269,7 @@ func (d *Decoder) decodeBinarySet(bs [][]byte, v reflect.Value) error {
}
case reflect.Array:
// Limited to capacity of existing array.
isArray = true
case reflect.Interface:
set := make([][]byte, len(bs))
for i, b := range bs {
@@ -274,7 +284,9 @@ func (d *Decoder) decodeBinarySet(bs [][]byte, v reflect.Value) error {
}
for i := 0; i < v.Cap() && i < len(bs); i++ {
v.SetLen(i + 1)
if !isArray {
v.SetLen(i + 1)
}
u, elem := indirect(v.Index(i), false)
if u != nil {
return u.UnmarshalDynamoDBAttributeValue(&dynamodb.AttributeValue{BS: bs})
@@ -363,6 +375,8 @@ func (d *Decoder) decodeNumberToInterface(n *string) (interface{}, error) {
}
func (d *Decoder) decodeNumberSet(ns []*string, v reflect.Value) error {
isArray := false
switch v.Kind() {
case reflect.Slice:
// Make room for the slice elements if needed
@@ -372,6 +386,7 @@ func (d *Decoder) decodeNumberSet(ns []*string, v reflect.Value) error {
}
case reflect.Array:
// Limited to capacity of existing array.
isArray = true
case reflect.Interface:
if d.UseNumber {
set := make([]Number, len(ns))
@@ -396,7 +411,9 @@ func (d *Decoder) decodeNumberSet(ns []*string, v reflect.Value) error {
}
for i := 0; i < v.Cap() && i < len(ns); i++ {
v.SetLen(i + 1)
if !isArray {
v.SetLen(i + 1)
}
u, elem := indirect(v.Index(i), false)
if u != nil {
return u.UnmarshalDynamoDBAttributeValue(&dynamodb.AttributeValue{NS: ns})
@@ -410,6 +427,8 @@ func (d *Decoder) decodeNumberSet(ns []*string, v reflect.Value) error {
}
func (d *Decoder) decodeList(avList []*dynamodb.AttributeValue, v reflect.Value) error {
isArray := false
switch v.Kind() {
case reflect.Slice:
// Make room for the slice elements if needed
@@ -419,6 +438,7 @@ func (d *Decoder) decodeList(avList []*dynamodb.AttributeValue, v reflect.Value)
}
case reflect.Array:
// Limited to capacity of existing array.
isArray = true
case reflect.Interface:
s := make([]interface{}, len(avList))
for i, av := range avList {
@@ -434,7 +454,10 @@ func (d *Decoder) decodeList(avList []*dynamodb.AttributeValue, v reflect.Value)
// If v is not a slice, array
for i := 0; i < v.Cap() && i < len(avList); i++ {
v.SetLen(i + 1)
if !isArray {
v.SetLen(i + 1)
}
if err := d.decode(avList[i], v.Index(i), tag{}); err != nil {
return err
}
@@ -526,6 +549,8 @@ func (d *Decoder) decodeString(s *string, v reflect.Value, fieldTag tag) error {
}
func (d *Decoder) decodeStringSet(ss []*string, v reflect.Value) error {
isArray := false
switch v.Kind() {
case reflect.Slice:
// Make room for the slice elements if needed
@@ -534,6 +559,7 @@ func (d *Decoder) decodeStringSet(ss []*string, v reflect.Value) error {
}
case reflect.Array:
// Limited to capacity of existing array.
isArray = true
case reflect.Interface:
set := make([]string, len(ss))
for i, s := range ss {
@@ -548,7 +574,9 @@ func (d *Decoder) decodeStringSet(ss []*string, v reflect.Value) error {
}
for i := 0; i < v.Cap() && i < len(ss); i++ {
v.SetLen(i + 1)
if !isArray {
v.SetLen(i + 1)
}
u, elem := indirect(v.Index(i), false)
if u != nil {
return u.UnmarshalDynamoDBAttributeValue(&dynamodb.AttributeValue{SS: ss})
@@ -10,7 +10,6 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/stretchr/testify/assert"
)
func TestUnmarshalErrorTypes(t *testing.T) {
@@ -390,12 +389,22 @@ func TestUnmarshalUnmashaler(t *testing.T) {
}
err := Unmarshal(av, u)
assert.NoError(t, err)
if err != nil {
t.Errorf("expect no error, got %v", err)
}
assert.Equal(t, "value", u.Value)
assert.Equal(t, 123, u.Value2)
assert.Equal(t, true, u.Value3)
assert.Equal(t, testDate, u.Value4)
if e, a := "value", u.Value; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := 123, u.Value2; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := true, u.Value3; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := testDate, u.Value4; e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
func TestDecodeUseNumber(t *testing.T) {
@@ -412,13 +421,20 @@ func TestDecodeUseNumber(t *testing.T) {
d.UseNumber = true
})
err := decoder.Decode(av, &u)
assert.NoError(t, err)
if err != nil {
t.Errorf("expect no error, got %v", err)
}
assert.Equal(t, "value", u["abc"])
n, ok := u["def"].(Number)
assert.True(t, ok)
assert.Equal(t, "123", n.String())
assert.Equal(t, true, u["ghi"])
if e, a := "value", u["abc"]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
n := u["def"].(Number)
if e, a := "123", n.String(); e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := true, u["ghi"]; e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
func TestDecodeUseNumberNumberSet(t *testing.T) {
@@ -437,13 +453,18 @@ func TestDecodeUseNumberNumberSet(t *testing.T) {
d.UseNumber = true
})
err := decoder.Decode(av, &u)
assert.NoError(t, err)
if err != nil {
t.Errorf("expect no error, got %v", err)
}
ns, ok := u["ns"].([]Number)
assert.True(t, ok)
ns := u["ns"].([]Number)
assert.Equal(t, "123", ns[0].String())
assert.Equal(t, "321", ns[1].String())
if e, a := "123", ns[0].String(); e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := "321", ns[1].String(); e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
func TestDecodeEmbeddedPointerStruct(t *testing.T) {
@@ -471,12 +492,20 @@ func TestDecodeEmbeddedPointerStruct(t *testing.T) {
decoder := NewDecoder()
a := A{}
err := decoder.Decode(av, &a)
assert.NoError(t, err)
assert.Equal(t, 321, a.Aint)
if err != nil {
t.Errorf("expect no error, got %v", err)
}
if e, a := 321, a.Aint; e != a {
t.Errorf("expect %v, got %v", e, a)
}
// Embedded pointer struct can be created automatically.
assert.Equal(t, 123, a.Bint)
if e, a := 123, a.Bint; e != a {
t.Errorf("expect %v, got %v", e, a)
}
// But not for absent fields.
assert.Nil(t, a.C)
if a.C != nil {
t.Errorf("expect nil, got %v", a.C)
}
}
func TestDecodeBooleanOverlay(t *testing.T) {
@@ -491,8 +520,12 @@ func TestDecodeBooleanOverlay(t *testing.T) {
var v BooleanOverlay
err := decoder.Decode(av, &v)
assert.NoError(t, err)
assert.Equal(t, BooleanOverlay(true), v)
if err != nil {
t.Errorf("expect no error, got %v", err)
}
if e, a := BooleanOverlay(true), v; e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
func TestDecodeUnixTime(t *testing.T) {
@@ -524,8 +557,12 @@ func TestDecodeUnixTime(t *testing.T) {
actual := A{}
err := Unmarshal(input, &actual)
assert.NoError(t, err)
assert.Equal(t, expect, actual)
if err != nil {
t.Errorf("expect no error, got %v", err)
}
if e, a := expect, actual; e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
func TestDecodeAliasedUnixTime(t *testing.T) {
@@ -552,6 +589,10 @@ func TestDecodeAliasedUnixTime(t *testing.T) {
actual := A{}
err := Unmarshal(input, &actual)
assert.NoError(t, err)
assert.Equal(t, expect, actual)
if err != nil {
t.Errorf("expect no error, got %v", err)
}
if expect != actual {
t.Errorf("expect %v, got %v", expect, actual)
}
}
@@ -362,7 +362,10 @@ func (e *Encoder) encodeMap(av *dynamodb.AttributeValue, v reflect.Value, fieldT
func (e *Encoder) encodeSlice(av *dynamodb.AttributeValue, v reflect.Value, fieldTag tag) error {
switch v.Type().Elem().Kind() {
case reflect.Uint8:
b := v.Bytes()
slice := reflect.MakeSlice(byteSliceType, v.Len(), v.Len())
reflect.Copy(slice, v)
b := slice.Bytes()
if len(b) == 0 {
encodeNull(av)
return nil
@@ -2,13 +2,13 @@ package dynamodbattribute
import (
"fmt"
"reflect"
"testing"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/stretchr/testify/assert"
)
func TestMarshalErrorTypes(t *testing.T) {
@@ -73,9 +73,13 @@ func TestMarshalMashaler(t *testing.T) {
}
actual, err := Marshal(m)
assert.NoError(t, err)
if err != nil {
t.Errorf("expect nil, got %v", err)
}
assert.Equal(t, expect, actual)
if e, a := expect, actual; !reflect.DeepEqual(e, a) {
t.Errorf("expect %v, got %v", e, a)
}
}
type testOmitEmptyElemListStruct struct {
@@ -99,8 +103,12 @@ func TestMarshalListOmitEmptyElem(t *testing.T) {
m := testOmitEmptyElemListStruct{Values: []string{"abc", "", "123"}}
actual, err := Marshal(m)
assert.NoError(t, err)
assert.Equal(t, expect, actual)
if err != nil {
t.Errorf("expect nil, got %v", err)
}
if e, a := expect, actual; !reflect.DeepEqual(e, a) {
t.Errorf("expect %v, got %v", e, a)
}
}
func TestMarshalMapOmitEmptyElem(t *testing.T) {
@@ -121,8 +129,12 @@ func TestMarshalMapOmitEmptyElem(t *testing.T) {
}}
actual, err := Marshal(m)
assert.NoError(t, err)
assert.Equal(t, expect, actual)
if err != nil {
t.Errorf("expect nil, got %v", err)
}
if e, a := expect, actual; !reflect.DeepEqual(e, a) {
t.Errorf("expect %v, got %v", e, a)
}
}
type testOmitEmptyScalar struct {
@@ -141,8 +153,12 @@ func TestMarshalOmitEmpty(t *testing.T) {
m := testOmitEmptyScalar{IntPtrSetZero: aws.Int(0)}
actual, err := Marshal(m)
assert.NoError(t, err)
assert.Equal(t, expect, actual)
if err != nil {
t.Errorf("expect nil, got %v", err)
}
if e, a := expect, actual; !reflect.DeepEqual(e, a) {
t.Errorf("expect %v, got %v", e, a)
}
}
func TestEncodeEmbeddedPointerStruct(t *testing.T) {
@@ -158,12 +174,20 @@ func TestEncodeEmbeddedPointerStruct(t *testing.T) {
*C
}
a := A{Aint: 321, B: &B{123}}
assert.Equal(t, 321, a.Aint)
assert.Equal(t, 123, a.Bint)
assert.Nil(t, a.C)
if e, a := 321, a.Aint; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if e, a := 123, a.Bint; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if a.C != nil {
t.Errorf("expect nil, got %v", a.C)
}
actual, err := Marshal(a)
assert.NoError(t, err)
if err != nil {
t.Errorf("expect nil, got %v", err)
}
expect := &dynamodb.AttributeValue{
M: map[string]*dynamodb.AttributeValue{
"Aint": {
@@ -174,7 +198,9 @@ func TestEncodeEmbeddedPointerStruct(t *testing.T) {
},
},
}
assert.Equal(t, expect, actual)
if e, a := expect, actual; !reflect.DeepEqual(e, a) {
t.Errorf("expect %v, got %v", e, a)
}
}
func TestEncodeUnixTime(t *testing.T) {
@@ -191,7 +217,9 @@ func TestEncodeUnixTime(t *testing.T) {
}
actual, err := Marshal(a)
assert.NoError(t, err)
if err != nil {
t.Errorf("expect nil, got %v", err)
}
expect := &dynamodb.AttributeValue{
M: map[string]*dynamodb.AttributeValue{
"Normal": {
@@ -205,7 +233,9 @@ func TestEncodeUnixTime(t *testing.T) {
},
},
}
assert.Equal(t, expect, actual)
if e, a := expect, actual; !reflect.DeepEqual(e, a) {
t.Errorf("expect %v, got %v", e, a)
}
}
type AliasedTime time.Time
@@ -222,7 +252,9 @@ func TestEncodeAliasedUnixTime(t *testing.T) {
}
actual, err := Marshal(a)
assert.NoError(t, err)
if err != nil {
t.Errorf("expect no err, got %v", err)
}
expect := &dynamodb.AttributeValue{
M: map[string]*dynamodb.AttributeValue{
"Normal": {
@@ -233,5 +265,7 @@ func TestEncodeAliasedUnixTime(t *testing.T) {
},
},
}
assert.Equal(t, expect, actual)
if e, a := expect, actual; !reflect.DeepEqual(e, a) {
t.Errorf("expect %v, got %v", e, a)
}
}
@@ -3,8 +3,6 @@ package dynamodbattribute
import (
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
type testUnionValues struct {
@@ -77,9 +75,13 @@ func TestUnionStructFields(t *testing.T) {
fields := unionStructFields(v.Type(), MarshalOptions{SupportJSONTags: true})
for j, f := range fields {
expected := c.expect[j]
assert.Equal(t, expected.Name, f.Name, "case %d, field %d", i, j)
if e, a := expected.Name, f.Name; e != a {
t.Errorf("%d:%d expect %v, got %v", i, j, e, f)
}
actual := v.FieldByIndex(f.Index).Interface()
assert.EqualValues(t, expected.Value, actual, "case %d, field %d", i, j)
if e, a := expected.Value, actual; !reflect.DeepEqual(e, a) {
t.Errorf("%d:%d expect %v, got %v", i, j, e, f)
}
}
}
}
@@ -102,9 +104,13 @@ func TestFieldByName(t *testing.T) {
for _, c := range cases {
f, ok := fieldByName(fields, c.Name)
assert.Equal(t, c.Found, ok)
if e, a := c.Found, ok; e != a {
t.Errorf("expect %v, got %v", e, a)
}
if ok {
assert.Equal(t, c.FieldName, f.Name)
if e, a := c.FieldName, f.Name; e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
}
}
@@ -493,6 +493,53 @@ func Test_New_UnmarshalListError(t *testing.T) {
}
}
// see github issue #1594
func TestDecodeArrayType(t *testing.T) {
cases := []struct {
to, from interface{}
}{
{
&[2]int{1, 2},
&[2]int{},
},
{
&[2]int64{1, 2},
&[2]int64{},
},
{
&[2]byte{1, 2},
&[2]byte{},
},
{
&[2]bool{true, false},
&[2]bool{},
},
{
&[2]string{"1", "2"},
&[2]string{},
},
{
&[2][]string{{"1", "2"}},
&[2][]string{},
},
}
for _, c := range cases {
marshaled, err := Marshal(c.to)
if err != nil {
t.Errorf("expected no error, but received %v", err)
}
if err = Unmarshal(marshaled, c.from); err != nil {
t.Errorf("expected no error, but received %v", err)
}
if !reflect.DeepEqual(c.to, c.from) {
t.Errorf("expected %v, but received %v", c.to, c.from)
}
}
}
func compareObjects(t *testing.T, expected interface{}, actual interface{}) {
if !reflect.DeepEqual(expected, actual) {
ev := reflect.ValueOf(expected)
@@ -7,7 +7,6 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/stretchr/testify/assert"
)
type testBinarySetStruct struct {
@@ -376,14 +375,18 @@ func assertConvertTest(t *testing.T, i int, actual, expected interface{}, err, e
i++
if expectedErr != nil {
if err != nil {
assert.Equal(t, expectedErr, err, "case %d", i)
if e, a := expectedErr, err; !reflect.DeepEqual(e, a) {
t.Errorf("case %d expect %v, got %v", i, e, a)
}
} else {
assert.Fail(t, "", "case %d, expected error, %v", i)
t.Fatalf("case %d, expected error, %v", i, expectedErr)
}
} else if err != nil {
assert.Fail(t, "", "case %d, expect no error, got %v", i, err)
t.Fatalf("case %d, expect no error, got %v", i, err)
} else {
assert.Equal(t, ptrToValue(expected), ptrToValue(actual), "case %d", i)
if e, a := ptrToValue(expected), ptrToValue(actual); !reflect.DeepEqual(e, a) {
t.Errorf("case %d, expect %v, got %v", i, e, a)
}
}
}
@@ -3,8 +3,6 @@ package dynamodbattribute
import (
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
func TestTagParse(t *testing.T) {
@@ -42,6 +40,8 @@ func TestTagParse(t *testing.T) {
if c.av {
actual.parseAVTag(c.in)
}
assert.Equal(t, c.expect, actual, "case %d", i+1)
if e, a := c.expect, actual; !reflect.DeepEqual(e, a) {
t.Errorf("case %d, expect %v, got %v", i, e, a)
}
}
}