vendor: update all dependencies to latest versions

This commit is contained in:
Nick Craig-Wood 2018-01-16 13:20:59 +00:00
parent 8e83fb6fb9
commit 7d3a17725d
4878 changed files with 1974229 additions and 201215 deletions

10
vendor/github.com/pengsrc/go-shared/convert/string.go generated vendored Normal file
View file

@ -0,0 +1,10 @@
package convert
// StringSliceWithConverter converts a list of string using the passed converter function
func StringSliceWithConverter(s []string, c func(string) string) []string {
out := []string{}
for _, i := range s {
out = append(out, c(i))
}
return out
}

View file

@ -0,0 +1,14 @@
package convert
import (
"strings"
"testing"
)
func TestStringSliceWithConverter(t *testing.T) {
s := StringSliceWithConverter([]string{"A", "b", "C"}, strings.ToLower)
e := []string{"a", "b", "c"}
if s[0] != e[0] || s[1] != e[1] || s[2] != e[2] {
t.Errorf("%v != %v", s, e)
}
}

View file

@ -37,6 +37,10 @@ func StringToTime(timeString string, format string) (time.Time, error) {
// TimeToTimestamp transforms given time to unix time int.
func TimeToTimestamp(t time.Time) int64 {
zero := time.Time{}
if t == zero {
t = time.Unix(0, 0).UTC()
}
return t.Unix()
}

View file

@ -299,6 +299,79 @@ func Int64ValueMap(src map[string]*int64) map[string]int64 {
return dst
}
// Int64Uint returns a uint pointer to the given int64 value.
func Int64Uint(src int64) *uint {
dst := uint(src)
return &dst
}
// Uint8 return a uint8 pointer to the given uint8 value.
func Uint8(src uint8) *uint8 {
dst := uint8(src)
return &dst
}
// Uint8Value returns the value of the given uint8 pointer or
// 0 if the pointer is nil.
func Uint8Value(v *uint8) uint8 {
if v != nil {
return *v
}
return 0
}
// Uint32 return a uint32 pointer to the given uint32 value.
func Uint32(src uint32) *uint32 {
dst := uint32(src)
return &dst
}
// Uint32Value returns the value of the given uint32 pointer or
// 0 if the pointer is nil.
func Uint32Value(v *uint32) uint32 {
if v != nil {
return *v
}
return 0
}
// Uint64 return a uint64 pointer to the given uint64 value.
func Uint64(src uint64) *uint64 {
dst := uint64(src)
return &dst
}
// Uint64Value returns the value of the given uint64 pointer or
// 0 if the pointer is nil.
func Uint64Value(v *uint64) uint64 {
if v != nil {
return *v
}
return 0
}
// Uint64Slice converts a slice of uint64 values into a slice of
// uint64 pointers
func Uint64Slice(src []uint64) []*uint64 {
dst := make([]*uint64, len(src))
for i := 0; i < len(src); i++ {
dst[i] = &(src[i])
}
return dst
}
// Uint64ValueSlice converts a slice of uint64 pointers into a slice of
// uint64 values
func Uint64ValueSlice(src []*uint64) []uint64 {
dst := make([]uint64, len(src))
for i := 0; i < len(src); i++ {
if src[i] != nil {
dst[i] = *(src[i])
}
}
return dst
}
// Float32 returns a pointer to the given float32 value.
func Float32(v float32) *float32 {
return &v

View file

@ -244,84 +244,6 @@ func TestIntMap(t *testing.T) {
}
}
func TestInt64Value(t *testing.T) {
i := int64(1024)
assert.Equal(t, i, Int64Value(Int64(i)))
assert.Equal(t, int64(0), Int64Value(nil))
}
var testCasesInt64Slice = [][]int64{
{1, 2, 3, 4},
}
func TestInt64Slice(t *testing.T) {
for idx, in := range testCasesInt64Slice {
if in == nil {
continue
}
out := Int64Slice(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
}
out2 := Int64ValueSlice(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
}
}
var testCasesInt64ValueSlice = [][]*int64{}
func TestInt64ValueSlice(t *testing.T) {
for idx, in := range testCasesInt64ValueSlice {
if in == nil {
continue
}
out := Int64ValueSlice(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
if in[i] == nil {
assert.Empty(t, out[i], "Unexpected value at idx %d", idx)
} else {
assert.Equal(t, *(in[i]), out[i], "Unexpected value at idx %d", idx)
}
}
out2 := Int64Slice(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
for i := range out2 {
if in[i] == nil {
assert.Empty(t, *(out2[i]), "Unexpected value at idx %d", idx)
} else {
assert.Equal(t, in[i], out2[i], "Unexpected value at idx %d", idx)
}
}
}
}
var testCasesInt64Map = []map[string]int64{
{"a": 3, "b": 2, "c": 1},
}
func TestInt64Map(t *testing.T) {
for idx, in := range testCasesInt64Map {
if in == nil {
continue
}
out := Int64Map(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
}
out2 := Int64ValueMap(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
}
}
func TestInt32Value(t *testing.T) {
i := int32(1024)
assert.Equal(t, i, Int32Value(Int32(i)))
@ -400,42 +322,42 @@ func TestInt32Map(t *testing.T) {
}
}
func TestFloat64Value(t *testing.T) {
i := float64(1024)
assert.Equal(t, i, Float64Value(Float64(i)))
func TestInt64Value(t *testing.T) {
i := int64(1024)
assert.Equal(t, i, Int64Value(Int64(i)))
assert.Equal(t, float64(0), Float64Value(nil))
assert.Equal(t, int64(0), Int64Value(nil))
}
var testCasesFloat64Slice = [][]float64{
var testCasesInt64Slice = [][]int64{
{1, 2, 3, 4},
}
func TestFloat64Slice(t *testing.T) {
for idx, in := range testCasesFloat64Slice {
func TestInt64Slice(t *testing.T) {
for idx, in := range testCasesInt64Slice {
if in == nil {
continue
}
out := Float64Slice(in)
out := Int64Slice(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
}
out2 := Float64ValueSlice(out)
out2 := Int64ValueSlice(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
}
}
var testCasesFloat64ValueSlice = [][]*float64{}
var testCasesInt64ValueSlice = [][]*int64{}
func TestFloat64ValueSlice(t *testing.T) {
for idx, in := range testCasesFloat64ValueSlice {
func TestInt64ValueSlice(t *testing.T) {
for idx, in := range testCasesInt64ValueSlice {
if in == nil {
continue
}
out := Float64ValueSlice(in)
out := Int64ValueSlice(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
if in[i] == nil {
@ -445,7 +367,7 @@ func TestFloat64ValueSlice(t *testing.T) {
}
}
out2 := Float64Slice(out)
out2 := Int64Slice(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
for i := range out2 {
if in[i] == nil {
@ -457,22 +379,64 @@ func TestFloat64ValueSlice(t *testing.T) {
}
}
var testCasesFloat64Map = []map[string]float64{
var testCasesInt64Map = []map[string]int64{
{"a": 3, "b": 2, "c": 1},
}
func TestFloat64Map(t *testing.T) {
for idx, in := range testCasesFloat64Map {
func TestInt64Map(t *testing.T) {
for idx, in := range testCasesInt64Map {
if in == nil {
continue
}
out := Float64Map(in)
out := Int64Map(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
}
out2 := Float64ValueMap(out)
out2 := Int64ValueMap(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
}
}
func TestUint8Value(t *testing.T) {
i := uint8(128)
assert.Equal(t, i, Uint8Value(Uint8(i)))
assert.Equal(t, uint8(0), Uint8Value(nil))
}
func TestUint32Value(t *testing.T) {
i := uint32(1024)
assert.Equal(t, i, Uint32Value(Uint32(i)))
assert.Equal(t, uint32(0), Uint32Value(nil))
}
func TestUint64Value(t *testing.T) {
i := uint64(1024)
assert.Equal(t, i, Uint64Value(Uint64(i)))
assert.Equal(t, uint64(0), Uint64Value(nil))
}
var testCasesUint64Slice = [][]uint64{
{1, 2, 3, 4},
}
func TestUint64Slice(t *testing.T) {
for idx, in := range testCasesUint64Slice {
if in == nil {
continue
}
out := Uint64Slice(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
}
out2 := Uint64ValueSlice(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
}
@ -556,6 +520,84 @@ func TestFloat32Map(t *testing.T) {
}
}
func TestFloat64Value(t *testing.T) {
i := float64(1024)
assert.Equal(t, i, Float64Value(Float64(i)))
assert.Equal(t, float64(0), Float64Value(nil))
}
var testCasesFloat64Slice = [][]float64{
{1, 2, 3, 4},
}
func TestFloat64Slice(t *testing.T) {
for idx, in := range testCasesFloat64Slice {
if in == nil {
continue
}
out := Float64Slice(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
}
out2 := Float64ValueSlice(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
}
}
var testCasesFloat64ValueSlice = [][]*float64{}
func TestFloat64ValueSlice(t *testing.T) {
for idx, in := range testCasesFloat64ValueSlice {
if in == nil {
continue
}
out := Float64ValueSlice(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
if in[i] == nil {
assert.Empty(t, out[i], "Unexpected value at idx %d", idx)
} else {
assert.Equal(t, *(in[i]), out[i], "Unexpected value at idx %d", idx)
}
}
out2 := Float64Slice(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
for i := range out2 {
if in[i] == nil {
assert.Empty(t, *(out2[i]), "Unexpected value at idx %d", idx)
} else {
assert.Equal(t, in[i], out2[i], "Unexpected value at idx %d", idx)
}
}
}
}
var testCasesFloat64Map = []map[string]float64{
{"a": 3, "b": 2, "c": 1},
}
func TestFloat64Map(t *testing.T) {
for idx, in := range testCasesFloat64Map {
if in == nil {
continue
}
out := Float64Map(in)
assert.Len(t, out, len(in), "Unexpected len at idx %d", idx)
for i := range out {
assert.Equal(t, in[i], *(out[i]), "Unexpected value at idx %d", idx)
}
out2 := Float64ValueMap(out)
assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx)
assert.Equal(t, in, out2, "Unexpected value at idx %d", idx)
}
}
func TestTimeValue(t *testing.T) {
tm := time.Time{}
assert.Equal(t, tm, TimeValue(Time(tm)))