vendor: update all dependencies to latest versions

This commit is contained in:
Nick Craig-Wood 2017-09-30 15:27:27 +01:00
parent 911d121bb9
commit b017fcfe9a
3048 changed files with 537057 additions and 189681 deletions

View file

@ -153,6 +153,7 @@ var stringInterfaceMapType = reflect.TypeOf(map[string]interface{}(nil))
var byteSliceType = reflect.TypeOf([]byte(nil))
var byteSliceSlicetype = reflect.TypeOf([][]byte(nil))
var numberType = reflect.TypeOf(Number(""))
var timeType = reflect.TypeOf(time.Time{})
func (d *Decoder) decode(av *dynamodb.AttributeValue, v reflect.Value, fieldTag tag) error {
var u Unmarshaler
@ -338,12 +339,12 @@ func (d *Decoder) decodeNumber(n *string, v reflect.Value, fieldTag tag) error {
}
v.SetFloat(i)
default:
if _, ok := v.Interface().(time.Time); ok && fieldTag.AsUnixTime {
if v.Type().ConvertibleTo(timeType) && fieldTag.AsUnixTime {
t, err := decodeUnixTime(*n)
if err != nil {
return err
}
v.Set(reflect.ValueOf(t))
v.Set(reflect.ValueOf(t).Convert(v.Type()))
return nil
}
return &UnmarshalTypeError{Value: "number", Type: v.Type()}
@ -502,12 +503,12 @@ func (d *Decoder) decodeString(s *string, v reflect.Value, fieldTag tag) error {
// To maintain backwards compatibility with ConvertFrom family of methods which
// converted strings to time.Time structs
if _, ok := v.Interface().(time.Time); ok {
if v.Type().ConvertibleTo(timeType) {
t, err := time.Parse(time.RFC3339, *s)
if err != nil {
return err
}
v.Set(reflect.ValueOf(t))
v.Set(reflect.ValueOf(t).Convert(v.Type()))
return nil
}
@ -564,7 +565,7 @@ func decodeUnixTime(n string) (time.Time, error) {
v, err := strconv.ParseInt(n, 10, 64)
if err != nil {
return time.Time{}, &UnmarshalError{
Err: err, Value: n, Type: reflect.TypeOf(time.Time{}),
Err: err, Value: n, Type: timeType,
}
}

View file

@ -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,6 +557,42 @@ 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) {
type A struct {
Normal AliasedTime
Tagged AliasedTime `dynamodbav:",unixtime"`
}
expect := A{
Normal: AliasedTime(time.Unix(123, 0).UTC()),
Tagged: AliasedTime(time.Unix(456, 0)),
}
input := &dynamodb.AttributeValue{
M: map[string]*dynamodb.AttributeValue{
"Normal": {
S: aws.String("1970-01-01T00:02:03Z"),
},
"Tagged": {
N: aws.String("456"),
},
},
}
actual := A{}
err := Unmarshal(input, &actual)
if err != nil {
t.Errorf("expect no error, got %v", err)
}
if expect != actual {
t.Errorf("expect %v, got %v", expect, actual)
}
}

View file

@ -34,7 +34,7 @@
// panic(fmt.Sprintf("failed to DynamoDB marshal Record, %v", err))
// }
//
// _, err := r.svc.PutItem(&dynamodb.PutItemInput{
// _, err = svc.PutItem(&dynamodb.PutItemInput{
// TableName: aws.String(myTableName),
// Item: av,
// })

View file

@ -285,7 +285,9 @@ func (e *Encoder) encode(av *dynamodb.AttributeValue, v reflect.Value, fieldTag
func (e *Encoder) encodeStruct(av *dynamodb.AttributeValue, v reflect.Value, fieldTag tag) error {
// To maintain backwards compatibility with ConvertTo family of methods which
// converted time.Time structs to strings
if t, ok := v.Interface().(time.Time); ok {
if v.Type().ConvertibleTo(timeType) {
var t time.Time
t = v.Convert(timeType).Interface().(time.Time)
if fieldTag.AsUnixTime {
return UnixTime(t).MarshalDynamoDBAttributeValue(av)
}

View file

@ -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,5 +233,39 @@ 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
func TestEncodeAliasedUnixTime(t *testing.T) {
type A struct {
Normal AliasedTime
Tagged AliasedTime `dynamodbav:",unixtime"`
}
a := A{
Normal: AliasedTime(time.Unix(123, 0).UTC()),
Tagged: AliasedTime(time.Unix(456, 0)),
}
actual, err := Marshal(a)
if err != nil {
t.Errorf("expect no err, got %v", err)
}
expect := &dynamodb.AttributeValue{
M: map[string]*dynamodb.AttributeValue{
"Normal": {
S: aws.String("1970-01-01T00:02:03Z"),
},
"Tagged": {
N: aws.String("456"),
},
},
}
if e, a := expect, actual; !reflect.DeepEqual(e, a) {
t.Errorf("expect %v, got %v", e, a)
}
}

View file

@ -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)
}
}
}
}

View file

@ -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)
}
}
}

View file

@ -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)
}
}
}