Bumping k8s dependencies to 1.13
This commit is contained in:
25
vendor/github.com/imdario/mergo/README.md
generated
vendored
25
vendor/github.com/imdario/mergo/README.md
generated
vendored
@@ -8,10 +8,11 @@ Also a lovely [comune](http://en.wikipedia.org/wiki/Mergo) (municipality) in the
|
||||
|
||||
It is ready for production use. [It is used in several projects by Docker, Google, The Linux Foundation, VMWare, Shopify, etc](https://github.com/imdario/mergo#mergo-in-the-wild).
|
||||
|
||||
[![Build Status][1]][2]
|
||||
[![GoDoc][3]][4]
|
||||
[![GoCard][5]][6]
|
||||
[![Build Status][1]][2]
|
||||
[![Coverage Status][7]][8]
|
||||
[![Sourcegraph][9]][10]
|
||||
|
||||
[1]: https://travis-ci.org/imdario/mergo.png
|
||||
[2]: https://travis-ci.org/imdario/mergo
|
||||
@@ -21,15 +22,28 @@ It is ready for production use. [It is used in several projects by Docker, Googl
|
||||
[6]: https://goreportcard.com/report/github.com/imdario/mergo
|
||||
[7]: https://coveralls.io/repos/github/imdario/mergo/badge.svg?branch=master
|
||||
[8]: https://coveralls.io/github/imdario/mergo?branch=master
|
||||
[9]: https://sourcegraph.com/github.com/imdario/mergo/-/badge.svg
|
||||
[10]: https://sourcegraph.com/github.com/imdario/mergo?badge
|
||||
|
||||
### Latest release
|
||||
|
||||
[Release 0.3.1](https://github.com/imdario/mergo/releases/tag/0.3.1) is an important release because it changes `Merge()`and `Map()` signatures to support [transformers](#transformers). An optional/variadic argument has been added, so it won't break existing code.
|
||||
[Release v0.3.6](https://github.com/imdario/mergo/releases/tag/v0.3.6).
|
||||
|
||||
### Important note
|
||||
|
||||
Please keep in mind that in [0.3.2](//github.com/imdario/mergo/releases/tag/0.3.2) Mergo changed `Merge()`and `Map()` signatures to support [transformers](#transformers). An optional/variadic argument has been added, so it won't break existing code.
|
||||
|
||||
If you were using Mergo **before** April 6th 2015, please check your project works as intended after updating your local copy with ```go get -u github.com/imdario/mergo```. I apologize for any issue caused by its previous behavior and any future bug that Mergo could cause (I hope it won't!) in existing projects after the change (release 0.2.0).
|
||||
|
||||
### Donations
|
||||
|
||||
If Mergo is useful to you, consider buying me a coffee, a beer or making a monthly donation so I can keep building great free software. :heart_eyes:
|
||||
|
||||
<a href='https://ko-fi.com/B0B58839' target='_blank'><img height='36' style='border:0px;height:36px;' src='https://az743702.vo.msecnd.net/cdn/kofi1.png?v=0' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>
|
||||
[](https://beerpay.io/imdario/mergo)
|
||||
[](https://beerpay.io/imdario/mergo)
|
||||
<a href="https://liberapay.com/dario/donate"><img alt="Donate using Liberapay" src="https://liberapay.com/assets/widgets/donate.svg"></a>
|
||||
|
||||
### Mergo in the wild
|
||||
|
||||
- [moby/moby](https://github.com/moby/moby)
|
||||
@@ -84,7 +98,7 @@ If you were using Mergo **before** April 6th 2015, please check your project wor
|
||||
|
||||
## Usage
|
||||
|
||||
You can only merge same-type structs with exported fields initialized as zero value of their type and same-types maps. Mergo won't merge unexported (private) fields but will do recursively any exported one. Also maps will be merged recursively except for structs inside maps (because they are not addressable using Go reflection).
|
||||
You can only merge same-type structs with exported fields initialized as zero value of their type and same-types maps. Mergo won't merge unexported (private) fields but will do recursively any exported one. It won't merge empty structs value as [they are not considered zero values](https://golang.org/ref/spec#The_zero_value) either. Also maps will be merged recursively except for structs inside maps (because they are not addressable using Go reflection).
|
||||
|
||||
```go
|
||||
if err := mergo.Merge(&dst, src); err != nil {
|
||||
@@ -95,7 +109,7 @@ if err := mergo.Merge(&dst, src); err != nil {
|
||||
Also, you can merge overwriting values using the transformer `WithOverride`.
|
||||
|
||||
```go
|
||||
if err := mergo.Merge(&dst, src, WithOverride); err != nil {
|
||||
if err := mergo.Merge(&dst, src, mergo.WithOverride); err != nil {
|
||||
// ...
|
||||
}
|
||||
```
|
||||
@@ -155,6 +169,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/imdario/mergo"
|
||||
"reflect"
|
||||
"time"
|
||||
)
|
||||
@@ -186,7 +201,7 @@ type Snapshot struct {
|
||||
func main() {
|
||||
src := Snapshot{time.Now()}
|
||||
dest := Snapshot{}
|
||||
mergo.Merge(&dest, src, WithTransformers(timeTransfomer{}))
|
||||
mergo.Merge(&dest, src, mergo.WithTransformers(timeTransfomer{}))
|
||||
fmt.Println(dest)
|
||||
// Will print
|
||||
// { 2018-01-12 01:15:00 +0000 UTC m=+0.000000001 }
|
||||
|
2
vendor/github.com/imdario/mergo/issue23_test.go
generated
vendored
2
vendor/github.com/imdario/mergo/issue23_test.go
generated
vendored
@@ -21,7 +21,7 @@ func TestIssue23MergeWithOverwrite(t *testing.T) {
|
||||
if err := MergeWithOverwrite(&dst, src); err != nil {
|
||||
t.Errorf("Error while merging %s", err)
|
||||
}
|
||||
if dst.Created != src.Created {
|
||||
if !dst.Created.Equal(*src.Created) { //--> https://golang.org/pkg/time/#pkg-overview
|
||||
t.Fatalf("Created not merged in properly: dst.Created(%v) != src.Created(%v)", dst.Created, src.Created)
|
||||
}
|
||||
}
|
||||
|
20
vendor/github.com/imdario/mergo/issue61_test.go
generated
vendored
Normal file
20
vendor/github.com/imdario/mergo/issue61_test.go
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
package mergo
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestIssue61MergeNilMap(t *testing.T) {
|
||||
type T struct {
|
||||
I map[string][]string
|
||||
}
|
||||
t1 := T{}
|
||||
t2 := T{I: map[string][]string{"hi": {"there"}}}
|
||||
if err := Merge(&t1, t2); err != nil {
|
||||
t.Fail()
|
||||
}
|
||||
if !reflect.DeepEqual(t2, T{I: map[string][]string{"hi": {"there"}}}) {
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
38
vendor/github.com/imdario/mergo/issue64_test.go
generated
vendored
Normal file
38
vendor/github.com/imdario/mergo/issue64_test.go
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
package mergo
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
type Student struct {
|
||||
Name string
|
||||
Books []string
|
||||
}
|
||||
|
||||
var testData = []struct {
|
||||
S1 Student
|
||||
S2 Student
|
||||
ExpectedSlice []string
|
||||
}{
|
||||
{Student{"Jack", []string{"a", "B"}}, Student{"Tom", []string{"1"}}, []string{"a", "B"}},
|
||||
{Student{"Jack", []string{"a", "B"}}, Student{"Tom", []string{}}, []string{"a", "B"}},
|
||||
{Student{"Jack", []string{}}, Student{"Tom", []string{"1"}}, []string{"1"}},
|
||||
{Student{"Jack", []string{}}, Student{"Tom", []string{}}, []string{}},
|
||||
}
|
||||
|
||||
func TestIssue64MergeSliceWithOverride(t *testing.T) {
|
||||
for _, data := range testData {
|
||||
err := Merge(&data.S2, data.S1, WithOverride)
|
||||
if err != nil {
|
||||
t.Errorf("Error while merging %s", err)
|
||||
}
|
||||
if len(data.S2.Books) != len(data.ExpectedSlice) {
|
||||
t.Fatalf("Got %d elements in slice, but expected %d", len(data.S2.Books), len(data.ExpectedSlice))
|
||||
}
|
||||
for i, val := range data.S2.Books {
|
||||
if val != data.ExpectedSlice[i] {
|
||||
t.Fatalf("Expected %s, but got %s while merging slice with override", data.ExpectedSlice[i], val)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
48
vendor/github.com/imdario/mergo/issue66_test.go
generated
vendored
Normal file
48
vendor/github.com/imdario/mergo/issue66_test.go
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
package mergo
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
type PrivateSliceTest66 struct {
|
||||
PublicStrings []string
|
||||
privateStrings []string
|
||||
}
|
||||
|
||||
func TestPrivateSlice(t *testing.T) {
|
||||
p1 := PrivateSliceTest66{
|
||||
PublicStrings: []string{"one", "two", "three"},
|
||||
privateStrings: []string{"four", "five"},
|
||||
}
|
||||
p2 := PrivateSliceTest66{
|
||||
PublicStrings: []string{"six", "seven"},
|
||||
}
|
||||
if err := Merge(&p1, p2); err != nil {
|
||||
t.Fatalf("Error during the merge: %v", err)
|
||||
}
|
||||
if len(p1.PublicStrings) != 3 {
|
||||
t.Error("5 elements should be in 'PublicStrings' field")
|
||||
}
|
||||
if len(p1.privateStrings) != 2 {
|
||||
t.Error("2 elements should be in 'privateStrings' field")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrivateSliceWithAppendSlice(t *testing.T) {
|
||||
p1 := PrivateSliceTest66{
|
||||
PublicStrings: []string{"one", "two", "three"},
|
||||
privateStrings: []string{"four", "five"},
|
||||
}
|
||||
p2 := PrivateSliceTest66{
|
||||
PublicStrings: []string{"six", "seven"},
|
||||
}
|
||||
if err := Merge(&p1, p2, WithAppendSlice); err != nil {
|
||||
t.Fatalf("Error during the merge: %v", err)
|
||||
}
|
||||
if len(p1.PublicStrings) != 5 {
|
||||
t.Error("5 elements should be in 'PublicStrings' field")
|
||||
}
|
||||
if len(p1.privateStrings) != 2 {
|
||||
t.Error("2 elements should be in 'privateStrings' field")
|
||||
}
|
||||
}
|
14
vendor/github.com/imdario/mergo/map.go
generated
vendored
14
vendor/github.com/imdario/mergo/map.go
generated
vendored
@@ -31,8 +31,8 @@ func isExported(field reflect.StructField) bool {
|
||||
// Traverses recursively both values, assigning src's fields values to dst.
|
||||
// The map argument tracks comparisons that have already been seen, which allows
|
||||
// short circuiting on recursive types.
|
||||
func deepMap(dst, src reflect.Value, visited map[uintptr]*visit, depth int, config *config) (err error) {
|
||||
overwrite := config.overwrite
|
||||
func deepMap(dst, src reflect.Value, visited map[uintptr]*visit, depth int, config *Config) (err error) {
|
||||
overwrite := config.Overwrite
|
||||
if dst.CanAddr() {
|
||||
addr := dst.UnsafeAddr()
|
||||
h := 17 * addr
|
||||
@@ -128,23 +128,23 @@ func deepMap(dst, src reflect.Value, visited map[uintptr]*visit, depth int, conf
|
||||
// doesn't apply if dst is a map.
|
||||
// This is separated method from Merge because it is cleaner and it keeps sane
|
||||
// semantics: merging equal types, mapping different (restricted) types.
|
||||
func Map(dst, src interface{}, opts ...func(*config)) error {
|
||||
func Map(dst, src interface{}, opts ...func(*Config)) error {
|
||||
return _map(dst, src, opts...)
|
||||
}
|
||||
|
||||
// MapWithOverwrite will do the same as Map except that non-empty dst attributes will be overriden by
|
||||
// MapWithOverwrite will do the same as Map except that non-empty dst attributes will be overridden by
|
||||
// non-empty src attribute values.
|
||||
// Deprecated: Use Map(…) with WithOverride
|
||||
func MapWithOverwrite(dst, src interface{}, opts ...func(*config)) error {
|
||||
func MapWithOverwrite(dst, src interface{}, opts ...func(*Config)) error {
|
||||
return _map(dst, src, append(opts, WithOverride)...)
|
||||
}
|
||||
|
||||
func _map(dst, src interface{}, opts ...func(*config)) error {
|
||||
func _map(dst, src interface{}, opts ...func(*Config)) error {
|
||||
var (
|
||||
vDst, vSrc reflect.Value
|
||||
err error
|
||||
)
|
||||
config := &config{}
|
||||
config := &Config{}
|
||||
|
||||
for _, opt := range opts {
|
||||
opt(config)
|
||||
|
83
vendor/github.com/imdario/mergo/merge.go
generated
vendored
83
vendor/github.com/imdario/mergo/merge.go
generated
vendored
@@ -8,7 +8,10 @@
|
||||
|
||||
package mergo
|
||||
|
||||
import "reflect"
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func hasExportedField(dst reflect.Value) (exported bool) {
|
||||
for i, n := 0, dst.NumField(); i < n; i++ {
|
||||
@@ -22,20 +25,21 @@ func hasExportedField(dst reflect.Value) (exported bool) {
|
||||
return
|
||||
}
|
||||
|
||||
type config struct {
|
||||
overwrite bool
|
||||
transformers transformers
|
||||
type Config struct {
|
||||
Overwrite bool
|
||||
AppendSlice bool
|
||||
Transformers Transformers
|
||||
}
|
||||
|
||||
type transformers interface {
|
||||
type Transformers interface {
|
||||
Transformer(reflect.Type) func(dst, src reflect.Value) error
|
||||
}
|
||||
|
||||
// Traverses recursively both values, assigning src's fields values to dst.
|
||||
// The map argument tracks comparisons that have already been seen, which allows
|
||||
// short circuiting on recursive types.
|
||||
func deepMerge(dst, src reflect.Value, visited map[uintptr]*visit, depth int, config *config) (err error) {
|
||||
overwrite := config.overwrite
|
||||
func deepMerge(dst, src reflect.Value, visited map[uintptr]*visit, depth int, config *Config) (err error) {
|
||||
overwrite := config.Overwrite
|
||||
|
||||
if !src.IsValid() {
|
||||
return
|
||||
@@ -54,8 +58,8 @@ func deepMerge(dst, src reflect.Value, visited map[uintptr]*visit, depth int, co
|
||||
visited[h] = &visit{addr, typ, seen}
|
||||
}
|
||||
|
||||
if config.transformers != nil && !isEmptyValue(dst) {
|
||||
if fn := config.transformers.Transformer(dst.Type()); fn != nil {
|
||||
if config.Transformers != nil && !isEmptyValue(dst) {
|
||||
if fn := config.Transformers.Transformer(dst.Type()); fn != nil {
|
||||
err = fn(dst, src)
|
||||
return
|
||||
}
|
||||
@@ -75,9 +79,8 @@ func deepMerge(dst, src reflect.Value, visited map[uintptr]*visit, depth int, co
|
||||
}
|
||||
}
|
||||
case reflect.Map:
|
||||
if len(src.MapKeys()) == 0 && !src.IsNil() && len(dst.MapKeys()) == 0 {
|
||||
if dst.IsNil() && !src.IsNil() {
|
||||
dst.Set(reflect.MakeMap(dst.Type()))
|
||||
return
|
||||
}
|
||||
for _, key := range src.MapKeys() {
|
||||
srcElement := src.MapIndex(key)
|
||||
@@ -86,7 +89,7 @@ func deepMerge(dst, src reflect.Value, visited map[uintptr]*visit, depth int, co
|
||||
}
|
||||
dstElement := dst.MapIndex(key)
|
||||
switch srcElement.Kind() {
|
||||
case reflect.Chan, reflect.Func, reflect.Map, reflect.Ptr, reflect.Interface, reflect.Slice:
|
||||
case reflect.Chan, reflect.Func, reflect.Map, reflect.Interface, reflect.Slice:
|
||||
if srcElement.IsNil() {
|
||||
continue
|
||||
}
|
||||
@@ -101,7 +104,15 @@ func deepMerge(dst, src reflect.Value, visited map[uintptr]*visit, depth int, co
|
||||
case reflect.Ptr:
|
||||
fallthrough
|
||||
case reflect.Map:
|
||||
if err = deepMerge(dstElement, srcElement, visited, depth+1, config); err != nil {
|
||||
srcMapElm := srcElement
|
||||
dstMapElm := dstElement
|
||||
if srcMapElm.CanInterface() {
|
||||
srcMapElm = reflect.ValueOf(srcMapElm.Interface())
|
||||
if dstMapElm.IsValid() {
|
||||
dstMapElm = reflect.ValueOf(dstMapElm.Interface())
|
||||
}
|
||||
}
|
||||
if err = deepMerge(dstMapElm, srcMapElm, visited, depth+1, config); err != nil {
|
||||
return
|
||||
}
|
||||
case reflect.Slice:
|
||||
@@ -114,7 +125,14 @@ func deepMerge(dst, src reflect.Value, visited map[uintptr]*visit, depth int, co
|
||||
dstSlice = reflect.ValueOf(dstElement.Interface())
|
||||
}
|
||||
|
||||
dstSlice = reflect.AppendSlice(dstSlice, srcSlice)
|
||||
if !isEmptyValue(src) && (overwrite || isEmptyValue(dst)) && !config.AppendSlice {
|
||||
dstSlice = srcSlice
|
||||
} else if config.AppendSlice {
|
||||
if srcSlice.Type() != dstSlice.Type() {
|
||||
return fmt.Errorf("cannot append two slice with different type (%s, %s)", srcSlice.Type(), dstSlice.Type())
|
||||
}
|
||||
dstSlice = reflect.AppendSlice(dstSlice, srcSlice)
|
||||
}
|
||||
dst.SetMapIndex(key, dstSlice)
|
||||
}
|
||||
}
|
||||
@@ -122,7 +140,7 @@ func deepMerge(dst, src reflect.Value, visited map[uintptr]*visit, depth int, co
|
||||
continue
|
||||
}
|
||||
|
||||
if !isEmptyValue(srcElement) && (overwrite || (!dstElement.IsValid() || isEmptyValue(dst))) {
|
||||
if srcElement.IsValid() && (overwrite || (!dstElement.IsValid() || isEmptyValue(dstElement))) {
|
||||
if dst.IsNil() {
|
||||
dst.Set(reflect.MakeMap(dst.Type()))
|
||||
}
|
||||
@@ -130,7 +148,17 @@ func deepMerge(dst, src reflect.Value, visited map[uintptr]*visit, depth int, co
|
||||
}
|
||||
}
|
||||
case reflect.Slice:
|
||||
dst.Set(reflect.AppendSlice(dst, src))
|
||||
if !dst.CanSet() {
|
||||
break
|
||||
}
|
||||
if !isEmptyValue(src) && (overwrite || isEmptyValue(dst)) && !config.AppendSlice {
|
||||
dst.Set(src)
|
||||
} else if config.AppendSlice {
|
||||
if src.Type() != dst.Type() {
|
||||
return fmt.Errorf("cannot append two slice with different type (%s, %s)", src.Type(), dst.Type())
|
||||
}
|
||||
dst.Set(reflect.AppendSlice(dst, src))
|
||||
}
|
||||
case reflect.Ptr:
|
||||
fallthrough
|
||||
case reflect.Interface:
|
||||
@@ -174,36 +202,41 @@ func deepMerge(dst, src reflect.Value, visited map[uintptr]*visit, depth int, co
|
||||
// src attributes if they themselves are not empty. dst and src must be valid same-type structs
|
||||
// and dst must be a pointer to struct.
|
||||
// It won't merge unexported (private) fields and will do recursively any exported field.
|
||||
func Merge(dst, src interface{}, opts ...func(*config)) error {
|
||||
func Merge(dst, src interface{}, opts ...func(*Config)) error {
|
||||
return merge(dst, src, opts...)
|
||||
}
|
||||
|
||||
// MergeWithOverwrite will do the same as Merge except that non-empty dst attributes will be overriden by
|
||||
// non-empty src attribute values.
|
||||
// Deprecated: use Merge(…) with WithOverride
|
||||
func MergeWithOverwrite(dst, src interface{}, opts ...func(*config)) error {
|
||||
func MergeWithOverwrite(dst, src interface{}, opts ...func(*Config)) error {
|
||||
return merge(dst, src, append(opts, WithOverride)...)
|
||||
}
|
||||
|
||||
// WithTransformers adds transformers to merge, allowing to customize the merging of some types.
|
||||
func WithTransformers(transformers transformers) func(*config) {
|
||||
return func(config *config) {
|
||||
config.transformers = transformers
|
||||
func WithTransformers(transformers Transformers) func(*Config) {
|
||||
return func(config *Config) {
|
||||
config.Transformers = transformers
|
||||
}
|
||||
}
|
||||
|
||||
// WithOverride will make merge override non-empty dst attributes with non-empty src attributes values.
|
||||
func WithOverride(config *config) {
|
||||
config.overwrite = true
|
||||
func WithOverride(config *Config) {
|
||||
config.Overwrite = true
|
||||
}
|
||||
|
||||
func merge(dst, src interface{}, opts ...func(*config)) error {
|
||||
// WithAppendSlice will make merge append slices instead of overwriting it
|
||||
func WithAppendSlice(config *Config) {
|
||||
config.AppendSlice = true
|
||||
}
|
||||
|
||||
func merge(dst, src interface{}, opts ...func(*Config)) error {
|
||||
var (
|
||||
vDst, vSrc reflect.Value
|
||||
err error
|
||||
)
|
||||
|
||||
config := &config{}
|
||||
config := &Config{}
|
||||
|
||||
for _, opt := range opts {
|
||||
opt(config)
|
||||
|
33
vendor/github.com/imdario/mergo/merge_appendslice_test.go
generated
vendored
Normal file
33
vendor/github.com/imdario/mergo/merge_appendslice_test.go
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
package mergo
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
var testDataS = []struct {
|
||||
S1 Student
|
||||
S2 Student
|
||||
ExpectedSlice []string
|
||||
}{
|
||||
{Student{"Jack", []string{"a", "B"}}, Student{"Tom", []string{"1"}}, []string{"1", "a", "B"}},
|
||||
{Student{"Jack", []string{"a", "B"}}, Student{"Tom", []string{}}, []string{"a", "B"}},
|
||||
{Student{"Jack", []string{}}, Student{"Tom", []string{"1"}}, []string{"1"}},
|
||||
{Student{"Jack", []string{}}, Student{"Tom", []string{}}, []string{}},
|
||||
}
|
||||
|
||||
func TestMergeSliceWithOverrideWithAppendSlice(t *testing.T) {
|
||||
for _, data := range testDataS {
|
||||
err := Merge(&data.S2, data.S1, WithOverride, WithAppendSlice)
|
||||
if err != nil {
|
||||
t.Errorf("Error while merging %s", err)
|
||||
}
|
||||
if len(data.S2.Books) != len(data.ExpectedSlice) {
|
||||
t.Fatalf("Got %d elements in slice, but expected %d", len(data.S2.Books), len(data.ExpectedSlice))
|
||||
}
|
||||
for i, val := range data.S2.Books {
|
||||
if val != data.ExpectedSlice[i] {
|
||||
t.Fatalf("Expected %s, but got %s while merging slice with override", data.ExpectedSlice[i], val)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
7
vendor/github.com/imdario/mergo/mergo.go
generated
vendored
7
vendor/github.com/imdario/mergo/mergo.go
generated
vendored
@@ -45,7 +45,12 @@ func isEmptyValue(v reflect.Value) bool {
|
||||
return v.Uint() == 0
|
||||
case reflect.Float32, reflect.Float64:
|
||||
return v.Float() == 0
|
||||
case reflect.Interface, reflect.Ptr, reflect.Func:
|
||||
case reflect.Interface, reflect.Ptr:
|
||||
if v.IsNil() {
|
||||
return true
|
||||
}
|
||||
return isEmptyValue(v.Elem())
|
||||
case reflect.Func:
|
||||
return v.IsNil()
|
||||
case reflect.Invalid:
|
||||
return true
|
||||
|
88
vendor/github.com/imdario/mergo/mergo_test.go
generated
vendored
88
vendor/github.com/imdario/mergo/mergo_test.go
generated
vendored
@@ -6,11 +6,12 @@
|
||||
package mergo
|
||||
|
||||
import (
|
||||
"gopkg.in/yaml.v2"
|
||||
"io/ioutil"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
type simpleTest struct {
|
||||
@@ -225,13 +226,13 @@ func TestPointerStructNil(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func testSlice(t *testing.T, a []int, b []int) {
|
||||
func testSlice(t *testing.T, a []int, b []int, e []int, opts ...func(*Config)) {
|
||||
t.Helper()
|
||||
bc := b
|
||||
e := append(a, b...)
|
||||
|
||||
sa := sliceTest{a}
|
||||
sb := sliceTest{b}
|
||||
if err := Merge(&sa, sb); err != nil {
|
||||
if err := Merge(&sa, sb, opts...); err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
if !reflect.DeepEqual(sb.S, bc) {
|
||||
@@ -243,14 +244,14 @@ func testSlice(t *testing.T, a []int, b []int) {
|
||||
|
||||
ma := map[string][]int{"S": a}
|
||||
mb := map[string][]int{"S": b}
|
||||
if err := Merge(&ma, mb); err != nil {
|
||||
if err := Merge(&ma, mb, opts...); err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
if !reflect.DeepEqual(mb["S"], bc) {
|
||||
t.Fatalf("Source slice was modified %d != %d", mb["S"], bc)
|
||||
t.Fatalf("map value: Source slice was modified %d != %d", mb["S"], bc)
|
||||
}
|
||||
if !reflect.DeepEqual(ma["S"], e) {
|
||||
t.Fatalf("b not merged in a proper way %d != %d", ma["S"], e)
|
||||
t.Fatalf("map value: b not merged in a proper way %d != %d", ma["S"], e)
|
||||
}
|
||||
|
||||
if a == nil {
|
||||
@@ -261,10 +262,10 @@ func testSlice(t *testing.T, a []int, b []int) {
|
||||
t.FailNow()
|
||||
}
|
||||
if !reflect.DeepEqual(mb["S"], bc) {
|
||||
t.Fatalf("Source slice was modified %d != %d", mb["S"], bc)
|
||||
t.Fatalf("missing dst key: Source slice was modified %d != %d", mb["S"], bc)
|
||||
}
|
||||
if !reflect.DeepEqual(ma["S"], e) {
|
||||
t.Fatalf("b not merged in a proper way %d != %d", ma["S"], e)
|
||||
t.Fatalf("missing dst key: b not merged in a proper way %d != %d", ma["S"], e)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,20 +277,25 @@ func testSlice(t *testing.T, a []int, b []int) {
|
||||
t.FailNow()
|
||||
}
|
||||
if !reflect.DeepEqual(mb["S"], bc) {
|
||||
t.Fatalf("Source slice was modified %d != %d", mb["S"], bc)
|
||||
t.Fatalf("missing src key: Source slice was modified %d != %d", mb["S"], bc)
|
||||
}
|
||||
if !reflect.DeepEqual(ma["S"], e) {
|
||||
t.Fatalf("b not merged in a proper way %d != %d", ma["S"], e)
|
||||
t.Fatalf("missing src key: b not merged in a proper way %d != %d", ma["S"], e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSlice(t *testing.T) {
|
||||
testSlice(t, nil, []int{1, 2, 3})
|
||||
testSlice(t, []int{}, []int{1, 2, 3})
|
||||
testSlice(t, []int{1}, []int{2, 3})
|
||||
testSlice(t, []int{1}, []int{})
|
||||
testSlice(t, []int{1}, nil)
|
||||
testSlice(t, nil, []int{1, 2, 3}, []int{1, 2, 3})
|
||||
testSlice(t, []int{}, []int{1, 2, 3}, []int{1, 2, 3})
|
||||
testSlice(t, []int{1}, []int{2, 3}, []int{1})
|
||||
testSlice(t, []int{1}, []int{}, []int{1})
|
||||
testSlice(t, []int{1}, nil, []int{1})
|
||||
testSlice(t, nil, []int{1, 2, 3}, []int{1, 2, 3}, WithAppendSlice)
|
||||
testSlice(t, []int{}, []int{1, 2, 3}, []int{1, 2, 3}, WithAppendSlice)
|
||||
testSlice(t, []int{1}, []int{2, 3}, []int{1, 2, 3}, WithAppendSlice)
|
||||
testSlice(t, []int{1}, []int{}, []int{1}, WithAppendSlice)
|
||||
testSlice(t, []int{1}, nil, []int{1}, WithAppendSlice)
|
||||
}
|
||||
|
||||
func TestEmptyMaps(t *testing.T) {
|
||||
@@ -405,6 +411,30 @@ func TestMaps(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMapsWithNilPointer(t *testing.T) {
|
||||
m := map[string]*simpleTest{
|
||||
"a": nil,
|
||||
"b": nil,
|
||||
}
|
||||
n := map[string]*simpleTest{
|
||||
"b": nil,
|
||||
"c": nil,
|
||||
}
|
||||
expect := map[string]*simpleTest{
|
||||
"a": nil,
|
||||
"b": nil,
|
||||
"c": nil,
|
||||
}
|
||||
|
||||
if err := Merge(&m, n, WithOverride); err != nil {
|
||||
t.Fatalf(err.Error())
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(m, expect) {
|
||||
t.Fatalf("Test failed:\ngot :\n%#v\n\nwant :\n%#v\n\n", m, expect)
|
||||
}
|
||||
}
|
||||
|
||||
func TestYAMLMaps(t *testing.T) {
|
||||
thing := loadYAML("testdata/thing.yml")
|
||||
license := loadYAML("testdata/license.yml")
|
||||
@@ -666,10 +696,10 @@ type structWithUnexportedProperty struct {
|
||||
|
||||
func TestUnexportedProperty(t *testing.T) {
|
||||
a := structWithMap{map[string]structWithUnexportedProperty{
|
||||
"key": structWithUnexportedProperty{"hello"},
|
||||
"key": {"hello"},
|
||||
}}
|
||||
b := structWithMap{map[string]structWithUnexportedProperty{
|
||||
"key": structWithUnexportedProperty{"hi"},
|
||||
"key": {"hi"},
|
||||
}}
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
@@ -701,3 +731,25 @@ func TestBooleanPointer(t *testing.T) {
|
||||
t.Fatalf("dst.C should be true")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMergeMapWithInnerSliceOfDifferentType(t *testing.T) {
|
||||
src := map[string]interface{}{
|
||||
"foo": []string{"a", "b"},
|
||||
}
|
||||
dst := map[string]interface{}{
|
||||
"foo": []int{1, 2},
|
||||
}
|
||||
|
||||
if err := Merge(&src, &dst, WithOverride, WithAppendSlice); err == nil {
|
||||
t.Fatal("expected an error, got nothing")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMergeSliceDifferentType(t *testing.T) {
|
||||
src := []string{"a", "b"}
|
||||
dst := []int{1, 2}
|
||||
|
||||
if err := Merge(&src, &dst, WithOverride, WithAppendSlice); err == nil {
|
||||
t.Fatal("expected an error, got nothing")
|
||||
}
|
||||
}
|
||||
|
18
vendor/github.com/imdario/mergo/pr80_test.go
generated
vendored
Normal file
18
vendor/github.com/imdario/mergo/pr80_test.go
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
package mergo
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
type mapInterface map[string]interface{}
|
||||
|
||||
func TestMergeMapsEmptyString(t *testing.T) {
|
||||
a := mapInterface{"s": ""}
|
||||
b := mapInterface{"s": "foo"}
|
||||
if err := Merge(&a, b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if a["s"] != "foo" {
|
||||
t.Fatalf("b not merged in properly: a.s.Value(%s) != expected(%s)", a["s"], "foo")
|
||||
}
|
||||
}
|
42
vendor/github.com/imdario/mergo/pr81_test.go
generated
vendored
Normal file
42
vendor/github.com/imdario/mergo/pr81_test.go
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
package mergo
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMapInterfaceWithMultipleLayer(t *testing.T) {
|
||||
m1 := map[string]interface{}{
|
||||
"k1": map[string]interface{}{
|
||||
"k1.1": "v1",
|
||||
},
|
||||
}
|
||||
|
||||
m2 := map[string]interface{}{
|
||||
"k1": map[string]interface{}{
|
||||
"k1.1": "v2",
|
||||
"k1.2": "v3",
|
||||
},
|
||||
}
|
||||
|
||||
if err := Map(&m1, m2, WithOverride); err != nil {
|
||||
t.Fatalf("Error merging: %v", err)
|
||||
}
|
||||
|
||||
// Check overwrite of sub map works
|
||||
expected := "v2"
|
||||
actual := m1["k1"].(map[string]interface{})["k1.1"].(string)
|
||||
if actual != expected {
|
||||
t.Fatalf("Expected %v but got %v",
|
||||
expected,
|
||||
actual)
|
||||
}
|
||||
|
||||
// Check new key is merged
|
||||
expected = "v3"
|
||||
actual = m1["k1"].(map[string]interface{})["k1.2"].(string)
|
||||
if actual != expected {
|
||||
t.Fatalf("Expected %v but got %v",
|
||||
expected,
|
||||
actual)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user