mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 10:33:35 +00:00
vendor cleanup: remove unused,non-go and test files
This commit is contained in:
33
vendor/github.com/imdario/mergo/.gitignore
generated
vendored
33
vendor/github.com/imdario/mergo/.gitignore
generated
vendored
@ -1,33 +0,0 @@
|
||||
#### joe made this: http://goel.io/joe
|
||||
|
||||
#### go ####
|
||||
# Binaries for programs and plugins
|
||||
*.exe
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
|
||||
# Test binary, build with `go test -c`
|
||||
*.test
|
||||
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
||||
|
||||
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
|
||||
.glide/
|
||||
|
||||
#### vim ####
|
||||
# Swap
|
||||
[._]*.s[a-v][a-z]
|
||||
[._]*.sw[a-p]
|
||||
[._]s[a-v][a-z]
|
||||
[._]sw[a-p]
|
||||
|
||||
# Session
|
||||
Session.vim
|
||||
|
||||
# Temporary
|
||||
.netrwhist
|
||||
*~
|
||||
# Auto-generated tag files
|
||||
tags
|
7
vendor/github.com/imdario/mergo/.travis.yml
generated
vendored
7
vendor/github.com/imdario/mergo/.travis.yml
generated
vendored
@ -1,7 +0,0 @@
|
||||
language: go
|
||||
install:
|
||||
- go get -t
|
||||
- go get golang.org/x/tools/cmd/cover
|
||||
- go get github.com/mattn/goveralls
|
||||
script:
|
||||
- $HOME/gopath/bin/goveralls -service=travis-ci -repotoken $COVERALLS_TOKEN
|
46
vendor/github.com/imdario/mergo/CODE_OF_CONDUCT.md
generated
vendored
46
vendor/github.com/imdario/mergo/CODE_OF_CONDUCT.md
generated
vendored
@ -1,46 +0,0 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at i@dario.im. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
|
||||
|
||||
[homepage]: http://contributor-covenant.org
|
||||
[version]: http://contributor-covenant.org/version/1/4/
|
222
vendor/github.com/imdario/mergo/README.md
generated
vendored
222
vendor/github.com/imdario/mergo/README.md
generated
vendored
@ -1,222 +0,0 @@
|
||||
# Mergo
|
||||
|
||||
A helper to merge structs and maps in Golang. Useful for configuration default values, avoiding messy if-statements.
|
||||
|
||||
Also a lovely [comune](http://en.wikipedia.org/wiki/Mergo) (municipality) in the Province of Ancona in the Italian region of Marche.
|
||||
|
||||
## Status
|
||||
|
||||
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).
|
||||
|
||||
[![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
|
||||
[3]: https://godoc.org/github.com/imdario/mergo?status.svg
|
||||
[4]: https://godoc.org/github.com/imdario/mergo
|
||||
[5]: https://goreportcard.com/badge/imdario/mergo
|
||||
[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 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)
|
||||
- [kubernetes/kubernetes](https://github.com/kubernetes/kubernetes)
|
||||
- [vmware/dispatch](https://github.com/vmware/dispatch)
|
||||
- [Shopify/themekit](https://github.com/Shopify/themekit)
|
||||
- [imdario/zas](https://github.com/imdario/zas)
|
||||
- [matcornic/hermes](https://github.com/matcornic/hermes)
|
||||
- [OpenBazaar/openbazaar-go](https://github.com/OpenBazaar/openbazaar-go)
|
||||
- [kataras/iris](https://github.com/kataras/iris)
|
||||
- [michaelsauter/crane](https://github.com/michaelsauter/crane)
|
||||
- [go-task/task](https://github.com/go-task/task)
|
||||
- [sensu/uchiwa](https://github.com/sensu/uchiwa)
|
||||
- [ory/hydra](https://github.com/ory/hydra)
|
||||
- [sisatech/vcli](https://github.com/sisatech/vcli)
|
||||
- [dairycart/dairycart](https://github.com/dairycart/dairycart)
|
||||
- [projectcalico/felix](https://github.com/projectcalico/felix)
|
||||
- [resin-os/balena](https://github.com/resin-os/balena)
|
||||
- [go-kivik/kivik](https://github.com/go-kivik/kivik)
|
||||
- [Telefonica/govice](https://github.com/Telefonica/govice)
|
||||
- [supergiant/supergiant](supergiant/supergiant)
|
||||
- [SergeyTsalkov/brooce](https://github.com/SergeyTsalkov/brooce)
|
||||
- [soniah/dnsmadeeasy](https://github.com/soniah/dnsmadeeasy)
|
||||
- [ohsu-comp-bio/funnel](https://github.com/ohsu-comp-bio/funnel)
|
||||
- [EagerIO/Stout](https://github.com/EagerIO/Stout)
|
||||
- [lynndylanhurley/defsynth-api](https://github.com/lynndylanhurley/defsynth-api)
|
||||
- [russross/canvasassignments](https://github.com/russross/canvasassignments)
|
||||
- [rdegges/cryptly-api](https://github.com/rdegges/cryptly-api)
|
||||
- [casualjim/exeggutor](https://github.com/casualjim/exeggutor)
|
||||
- [divshot/gitling](https://github.com/divshot/gitling)
|
||||
- [RWJMurphy/gorl](https://github.com/RWJMurphy/gorl)
|
||||
- [andrerocker/deploy42](https://github.com/andrerocker/deploy42)
|
||||
- [elwinar/rambler](https://github.com/elwinar/rambler)
|
||||
- [tmaiaroto/gopartman](https://github.com/tmaiaroto/gopartman)
|
||||
- [jfbus/impressionist](https://github.com/jfbus/impressionist)
|
||||
- [Jmeyering/zealot](https://github.com/Jmeyering/zealot)
|
||||
- [godep-migrator/rigger-host](https://github.com/godep-migrator/rigger-host)
|
||||
- [Dronevery/MultiwaySwitch-Go](https://github.com/Dronevery/MultiwaySwitch-Go)
|
||||
- [thoas/picfit](https://github.com/thoas/picfit)
|
||||
- [mantasmatelis/whooplist-server](https://github.com/mantasmatelis/whooplist-server)
|
||||
- [jnuthong/item_search](https://github.com/jnuthong/item_search)
|
||||
- [bukalapak/snowboard](https://github.com/bukalapak/snowboard)
|
||||
|
||||
## Installation
|
||||
|
||||
go get github.com/imdario/mergo
|
||||
|
||||
// use in your .go code
|
||||
import (
|
||||
"github.com/imdario/mergo"
|
||||
)
|
||||
|
||||
## 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. 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 {
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
Also, you can merge overwriting values using the transformer `WithOverride`.
|
||||
|
||||
```go
|
||||
if err := mergo.Merge(&dst, src, mergo.WithOverride); err != nil {
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
Additionally, you can map a `map[string]interface{}` to a struct (and otherwise, from struct to map), following the same restrictions as in `Merge()`. Keys are capitalized to find each corresponding exported field.
|
||||
|
||||
```go
|
||||
if err := mergo.Map(&dst, srcMap); err != nil {
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
Warning: if you map a struct to map, it won't do it recursively. Don't expect Mergo to map struct members of your struct as `map[string]interface{}`. They will be just assigned as values.
|
||||
|
||||
More information and examples in [godoc documentation](http://godoc.org/github.com/imdario/mergo).
|
||||
|
||||
### Nice example
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/imdario/mergo"
|
||||
)
|
||||
|
||||
type Foo struct {
|
||||
A string
|
||||
B int64
|
||||
}
|
||||
|
||||
func main() {
|
||||
src := Foo{
|
||||
A: "one",
|
||||
B: 2,
|
||||
}
|
||||
dest := Foo{
|
||||
A: "two",
|
||||
}
|
||||
mergo.Merge(&dest, src)
|
||||
fmt.Println(dest)
|
||||
// Will print
|
||||
// {two 2}
|
||||
}
|
||||
```
|
||||
|
||||
Note: if test are failing due missing package, please execute:
|
||||
|
||||
go get gopkg.in/yaml.v2
|
||||
|
||||
### Transformers
|
||||
|
||||
Transformers allow to merge specific types differently than in the default behavior. In other words, now you can customize how some types are merged. For example, `time.Time` is a struct; it doesn't have zero value but IsZero can return true because it has fields with zero value. How can we merge a non-zero `time.Time`?
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/imdario/mergo"
|
||||
"reflect"
|
||||
"time"
|
||||
)
|
||||
|
||||
type timeTransfomer struct {
|
||||
}
|
||||
|
||||
func (t timeTransfomer) Transformer(typ reflect.Type) func(dst, src reflect.Value) error {
|
||||
if typ == reflect.TypeOf(time.Time{}) {
|
||||
return func(dst, src reflect.Value) error {
|
||||
if dst.CanSet() {
|
||||
isZero := dst.MethodByName("IsZero")
|
||||
result := isZero.Call([]reflect.Value{})
|
||||
if result[0].Bool() {
|
||||
dst.Set(src)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Snapshot struct {
|
||||
Time time.Time
|
||||
// ...
|
||||
}
|
||||
|
||||
func main() {
|
||||
src := Snapshot{time.Now()}
|
||||
dest := Snapshot{}
|
||||
mergo.Merge(&dest, src, mergo.WithTransformers(timeTransfomer{}))
|
||||
fmt.Println(dest)
|
||||
// Will print
|
||||
// { 2018-01-12 01:15:00 +0000 UTC m=+0.000000001 }
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## Contact me
|
||||
|
||||
If I can help you, you have an idea or you are using Mergo in your projects, don't hesitate to drop me a line (or a pull request): [@im_dario](https://twitter.com/im_dario)
|
||||
|
||||
## About
|
||||
|
||||
Written by [Dario Castañé](http://dario.im).
|
||||
|
||||
## License
|
||||
|
||||
[BSD 3-Clause](http://opensource.org/licenses/BSD-3-Clause) license, as [Go language](http://golang.org/LICENSE).
|
25
vendor/github.com/imdario/mergo/issue17_test.go
generated
vendored
25
vendor/github.com/imdario/mergo/issue17_test.go
generated
vendored
@ -1,25 +0,0 @@
|
||||
package mergo
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
request = `{"timestamp":null, "name": "foo"}`
|
||||
maprequest = map[string]interface{}{
|
||||
"timestamp": nil,
|
||||
"name": "foo",
|
||||
"newStuff": "foo",
|
||||
}
|
||||
)
|
||||
|
||||
func TestIssue17MergeWithOverwrite(t *testing.T) {
|
||||
var something map[string]interface{}
|
||||
if err := json.Unmarshal([]byte(request), &something); err != nil {
|
||||
t.Errorf("Error while Unmarshalling maprequest: %s", err)
|
||||
}
|
||||
if err := MergeWithOverwrite(&something, maprequest); err != nil {
|
||||
t.Errorf("Error while merging: %s", err)
|
||||
}
|
||||
}
|
27
vendor/github.com/imdario/mergo/issue23_test.go
generated
vendored
27
vendor/github.com/imdario/mergo/issue23_test.go
generated
vendored
@ -1,27 +0,0 @@
|
||||
package mergo
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
type document struct {
|
||||
Created *time.Time
|
||||
}
|
||||
|
||||
func TestIssue23MergeWithOverwrite(t *testing.T) {
|
||||
now := time.Now()
|
||||
dst := document{
|
||||
&now,
|
||||
}
|
||||
expected := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)
|
||||
src := document{
|
||||
&expected,
|
||||
}
|
||||
if err := MergeWithOverwrite(&dst, src); err != nil {
|
||||
t.Errorf("Error while merging %s", err)
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
33
vendor/github.com/imdario/mergo/issue33_test.go
generated
vendored
33
vendor/github.com/imdario/mergo/issue33_test.go
generated
vendored
@ -1,33 +0,0 @@
|
||||
package mergo
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
type Foo struct {
|
||||
Str string
|
||||
Bslice []byte
|
||||
}
|
||||
|
||||
func TestIssue33Merge(t *testing.T) {
|
||||
dest := Foo{Str: "a"}
|
||||
toMerge := Foo{
|
||||
Str: "b",
|
||||
Bslice: []byte{1, 2},
|
||||
}
|
||||
if err := Merge(&dest, toMerge); err != nil {
|
||||
t.Errorf("Error while merging: %s", err)
|
||||
}
|
||||
// Merge doesn't overwrite an attribute if in destination it doesn't have a zero value.
|
||||
// In this case, Str isn't a zero value string.
|
||||
if dest.Str != "a" {
|
||||
t.Errorf("dest.Str should have not been override as it has a non-zero value: dest.Str(%v) != 'a'", dest.Str)
|
||||
}
|
||||
// If we want to override, we must use MergeWithOverwrite or Merge using WithOverride.
|
||||
if err := Merge(&dest, toMerge, WithOverride); err != nil {
|
||||
t.Errorf("Error while merging: %s", err)
|
||||
}
|
||||
if dest.Str != toMerge.Str {
|
||||
t.Errorf("dest.Str should have been override: dest.Str(%v) != toMerge.Str(%v)", dest.Str, toMerge.Str)
|
||||
}
|
||||
}
|
59
vendor/github.com/imdario/mergo/issue38_test.go
generated
vendored
59
vendor/github.com/imdario/mergo/issue38_test.go
generated
vendored
@ -1,59 +0,0 @@
|
||||
package mergo
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
type structWithoutTimePointer struct {
|
||||
Created time.Time
|
||||
}
|
||||
|
||||
func TestIssue38Merge(t *testing.T) {
|
||||
dst := structWithoutTimePointer{
|
||||
time.Now(),
|
||||
}
|
||||
|
||||
expected := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)
|
||||
src := structWithoutTimePointer{
|
||||
expected,
|
||||
}
|
||||
if err := Merge(&dst, src); err != nil {
|
||||
t.Errorf("Error while merging %s", err)
|
||||
}
|
||||
if dst.Created == src.Created {
|
||||
t.Fatalf("Created merged unexpectedly: dst.Created(%v) == src.Created(%v)", dst.Created, src.Created)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIssue38MergeEmptyStruct(t *testing.T) {
|
||||
dst := structWithoutTimePointer{}
|
||||
|
||||
expected := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)
|
||||
src := structWithoutTimePointer{
|
||||
expected,
|
||||
}
|
||||
if err := Merge(&dst, src); err != nil {
|
||||
t.Errorf("Error while merging %s", err)
|
||||
}
|
||||
if dst.Created == src.Created {
|
||||
t.Fatalf("Created merged unexpectedly: dst.Created(%v) == src.Created(%v)", dst.Created, src.Created)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIssue38MergeWithOverwrite(t *testing.T) {
|
||||
dst := structWithoutTimePointer{
|
||||
time.Now(),
|
||||
}
|
||||
|
||||
expected := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)
|
||||
src := structWithoutTimePointer{
|
||||
expected,
|
||||
}
|
||||
if err := MergeWithOverwrite(&dst, src); err != nil {
|
||||
t.Errorf("Error while merging %s", err)
|
||||
}
|
||||
if dst.Created != src.Created {
|
||||
t.Fatalf("Created not merged in properly: dst.Created(%v) != src.Created(%v)", dst.Created, src.Created)
|
||||
}
|
||||
}
|
18
vendor/github.com/imdario/mergo/issue50_test.go
generated
vendored
18
vendor/github.com/imdario/mergo/issue50_test.go
generated
vendored
@ -1,18 +0,0 @@
|
||||
package mergo
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
type testStruct struct {
|
||||
time.Duration
|
||||
}
|
||||
|
||||
func TestIssue50Merge(t *testing.T) {
|
||||
to := testStruct{}
|
||||
from := testStruct{}
|
||||
if err := Merge(&to, from); err != nil {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
99
vendor/github.com/imdario/mergo/issue52_test.go
generated
vendored
99
vendor/github.com/imdario/mergo/issue52_test.go
generated
vendored
@ -1,99 +0,0 @@
|
||||
package mergo
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
type structWithTime struct {
|
||||
Birth time.Time
|
||||
}
|
||||
|
||||
type timeTransfomer struct {
|
||||
overwrite bool
|
||||
}
|
||||
|
||||
func (t timeTransfomer) Transformer(typ reflect.Type) func(dst, src reflect.Value) error {
|
||||
if typ == reflect.TypeOf(time.Time{}) {
|
||||
return func(dst, src reflect.Value) error {
|
||||
if dst.CanSet() {
|
||||
if t.overwrite {
|
||||
isZero := src.MethodByName("IsZero")
|
||||
result := isZero.Call([]reflect.Value{})
|
||||
if !result[0].Bool() {
|
||||
dst.Set(src)
|
||||
}
|
||||
} else {
|
||||
isZero := dst.MethodByName("IsZero")
|
||||
result := isZero.Call([]reflect.Value{})
|
||||
if result[0].Bool() {
|
||||
dst.Set(src)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestOverwriteZeroSrcTime(t *testing.T) {
|
||||
now := time.Now()
|
||||
dst := structWithTime{now}
|
||||
src := structWithTime{}
|
||||
if err := MergeWithOverwrite(&dst, src); err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
if !dst.Birth.IsZero() {
|
||||
t.Fatalf("dst should have been overwritten: dst.Birth(%v) != now(%v)", dst.Birth, now)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOverwriteZeroSrcTimeWithTransformer(t *testing.T) {
|
||||
now := time.Now()
|
||||
dst := structWithTime{now}
|
||||
src := structWithTime{}
|
||||
if err := MergeWithOverwrite(&dst, src, WithTransformers(timeTransfomer{true})); err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
if dst.Birth.IsZero() {
|
||||
t.Fatalf("dst should not have been overwritten: dst.Birth(%v) != now(%v)", dst.Birth, now)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOverwriteZeroDstTime(t *testing.T) {
|
||||
now := time.Now()
|
||||
dst := structWithTime{}
|
||||
src := structWithTime{now}
|
||||
if err := MergeWithOverwrite(&dst, src); err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
if dst.Birth.IsZero() {
|
||||
t.Fatalf("dst should have been overwritten: dst.Birth(%v) != zero(%v)", dst.Birth, time.Time{})
|
||||
}
|
||||
}
|
||||
|
||||
func TestZeroDstTime(t *testing.T) {
|
||||
now := time.Now()
|
||||
dst := structWithTime{}
|
||||
src := structWithTime{now}
|
||||
if err := Merge(&dst, src); err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
if !dst.Birth.IsZero() {
|
||||
t.Fatalf("dst should not have been overwritten: dst.Birth(%v) != zero(%v)", dst.Birth, time.Time{})
|
||||
}
|
||||
}
|
||||
|
||||
func TestZeroDstTimeWithTransformer(t *testing.T) {
|
||||
now := time.Now()
|
||||
dst := structWithTime{}
|
||||
src := structWithTime{now}
|
||||
if err := Merge(&dst, src, WithTransformers(timeTransfomer{})); err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
if dst.Birth.IsZero() {
|
||||
t.Fatalf("dst should have been overwritten: dst.Birth(%v) != now(%v)", dst.Birth, now)
|
||||
}
|
||||
}
|
20
vendor/github.com/imdario/mergo/issue61_test.go
generated
vendored
20
vendor/github.com/imdario/mergo/issue61_test.go
generated
vendored
@ -1,20 +0,0 @@
|
||||
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
38
vendor/github.com/imdario/mergo/issue64_test.go
generated
vendored
@ -1,38 +0,0 @@
|
||||
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
48
vendor/github.com/imdario/mergo/issue66_test.go
generated
vendored
@ -1,48 +0,0 @@
|
||||
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")
|
||||
}
|
||||
}
|
33
vendor/github.com/imdario/mergo/merge_appendslice_test.go
generated
vendored
33
vendor/github.com/imdario/mergo/merge_appendslice_test.go
generated
vendored
@ -1,33 +0,0 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
50
vendor/github.com/imdario/mergo/merge_test.go
generated
vendored
50
vendor/github.com/imdario/mergo/merge_test.go
generated
vendored
@ -1,50 +0,0 @@
|
||||
package mergo
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type transformer struct {
|
||||
m map[reflect.Type]func(dst, src reflect.Value) error
|
||||
}
|
||||
|
||||
func (s *transformer) Transformer(t reflect.Type) func(dst, src reflect.Value) error {
|
||||
if fn, ok := s.m[t]; ok {
|
||||
return fn
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type foo struct {
|
||||
s string
|
||||
Bar *bar
|
||||
}
|
||||
|
||||
type bar struct {
|
||||
i int
|
||||
s map[string]string
|
||||
}
|
||||
|
||||
func TestMergeWithTransformerNilStruct(t *testing.T) {
|
||||
a := foo{s: "foo"}
|
||||
b := foo{Bar: &bar{i: 2, s: map[string]string{"foo": "bar"}}}
|
||||
if err := Merge(&a, &b, WithOverride, WithTransformers(&transformer{
|
||||
m: map[reflect.Type]func(dst, src reflect.Value) error{
|
||||
reflect.TypeOf(&bar{}): func(dst, src reflect.Value) error {
|
||||
// Do sthg with Elem
|
||||
t.Log(dst.Elem().FieldByName("i"))
|
||||
t.Log(src.Elem())
|
||||
return nil
|
||||
},
|
||||
},
|
||||
})); 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")
|
||||
}
|
||||
if a.Bar == nil {
|
||||
t.Fatalf("b not merged in properly: a.Bar shouldn't be nil")
|
||||
}
|
||||
}
|
755
vendor/github.com/imdario/mergo/mergo_test.go
generated
vendored
755
vendor/github.com/imdario/mergo/mergo_test.go
generated
vendored
@ -1,755 +0,0 @@
|
||||
// Copyright 2013 Dario Castañé. All rights reserved.
|
||||
// Copyright 2009 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package mergo
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
type simpleTest struct {
|
||||
Value int
|
||||
}
|
||||
|
||||
type complexTest struct {
|
||||
St simpleTest
|
||||
sz int
|
||||
ID string
|
||||
}
|
||||
|
||||
type mapTest struct {
|
||||
M map[int]int
|
||||
}
|
||||
|
||||
type ifcTest struct {
|
||||
I interface{}
|
||||
}
|
||||
|
||||
type moreComplextText struct {
|
||||
Ct complexTest
|
||||
St simpleTest
|
||||
Nt simpleTest
|
||||
}
|
||||
|
||||
type pointerTest struct {
|
||||
C *simpleTest
|
||||
}
|
||||
|
||||
type sliceTest struct {
|
||||
S []int
|
||||
}
|
||||
|
||||
func TestKb(t *testing.T) {
|
||||
type testStruct struct {
|
||||
Name string
|
||||
KeyValue map[string]interface{}
|
||||
}
|
||||
|
||||
akv := make(map[string]interface{})
|
||||
akv["Key1"] = "not value 1"
|
||||
akv["Key2"] = "value2"
|
||||
a := testStruct{}
|
||||
a.Name = "A"
|
||||
a.KeyValue = akv
|
||||
|
||||
bkv := make(map[string]interface{})
|
||||
bkv["Key1"] = "value1"
|
||||
bkv["Key3"] = "value3"
|
||||
b := testStruct{}
|
||||
b.Name = "B"
|
||||
b.KeyValue = bkv
|
||||
|
||||
ekv := make(map[string]interface{})
|
||||
ekv["Key1"] = "value1"
|
||||
ekv["Key2"] = "value2"
|
||||
ekv["Key3"] = "value3"
|
||||
expected := testStruct{}
|
||||
expected.Name = "B"
|
||||
expected.KeyValue = ekv
|
||||
|
||||
Merge(&b, a)
|
||||
|
||||
if !reflect.DeepEqual(b, expected) {
|
||||
t.Errorf("Actual: %#v did not match \nExpected: %#v", b, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNil(t *testing.T) {
|
||||
if err := Merge(nil, nil); err != ErrNilArguments {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestDifferentTypes(t *testing.T) {
|
||||
a := simpleTest{42}
|
||||
b := 42
|
||||
if err := Merge(&a, b); err != ErrDifferentArgumentsTypes {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestSimpleStruct(t *testing.T) {
|
||||
a := simpleTest{}
|
||||
b := simpleTest{42}
|
||||
if err := Merge(&a, b); err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
if a.Value != 42 {
|
||||
t.Fatalf("b not merged in properly: a.Value(%d) != b.Value(%d)", a.Value, b.Value)
|
||||
}
|
||||
if !reflect.DeepEqual(a, b) {
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
func TestComplexStruct(t *testing.T) {
|
||||
a := complexTest{}
|
||||
a.ID = "athing"
|
||||
b := complexTest{simpleTest{42}, 1, "bthing"}
|
||||
if err := Merge(&a, b); err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
if a.St.Value != 42 {
|
||||
t.Fatalf("b not merged in properly: a.St.Value(%d) != b.St.Value(%d)", a.St.Value, b.St.Value)
|
||||
}
|
||||
if a.sz == 1 {
|
||||
t.Fatalf("a's private field sz not preserved from merge: a.sz(%d) == b.sz(%d)", a.sz, b.sz)
|
||||
}
|
||||
if a.ID == b.ID {
|
||||
t.Fatalf("a's field ID merged unexpectedly: a.ID(%s) == b.ID(%s)", a.ID, b.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestComplexStructWithOverwrite(t *testing.T) {
|
||||
a := complexTest{simpleTest{1}, 1, "do-not-overwrite-with-empty-value"}
|
||||
b := complexTest{simpleTest{42}, 2, ""}
|
||||
|
||||
expect := complexTest{simpleTest{42}, 1, "do-not-overwrite-with-empty-value"}
|
||||
if err := MergeWithOverwrite(&a, b); err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(a, expect) {
|
||||
t.Fatalf("Test failed:\ngot :\n%#v\n\nwant :\n%#v\n\n", a, expect)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPointerStruct(t *testing.T) {
|
||||
s1 := simpleTest{}
|
||||
s2 := simpleTest{19}
|
||||
a := pointerTest{&s1}
|
||||
b := pointerTest{&s2}
|
||||
if err := Merge(&a, b); err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
if a.C.Value != b.C.Value {
|
||||
t.Fatalf("b not merged in properly: a.C.Value(%d) != b.C.Value(%d)", a.C.Value, b.C.Value)
|
||||
}
|
||||
}
|
||||
|
||||
type embeddingStruct struct {
|
||||
embeddedStruct
|
||||
}
|
||||
|
||||
type embeddedStruct struct {
|
||||
A string
|
||||
}
|
||||
|
||||
func TestEmbeddedStruct(t *testing.T) {
|
||||
tests := []struct {
|
||||
src embeddingStruct
|
||||
dst embeddingStruct
|
||||
expected embeddingStruct
|
||||
}{
|
||||
{
|
||||
src: embeddingStruct{
|
||||
embeddedStruct{"foo"},
|
||||
},
|
||||
dst: embeddingStruct{
|
||||
embeddedStruct{""},
|
||||
},
|
||||
expected: embeddingStruct{
|
||||
embeddedStruct{"foo"},
|
||||
},
|
||||
},
|
||||
{
|
||||
src: embeddingStruct{
|
||||
embeddedStruct{""},
|
||||
},
|
||||
dst: embeddingStruct{
|
||||
embeddedStruct{"bar"},
|
||||
},
|
||||
expected: embeddingStruct{
|
||||
embeddedStruct{"bar"},
|
||||
},
|
||||
},
|
||||
{
|
||||
src: embeddingStruct{
|
||||
embeddedStruct{"foo"},
|
||||
},
|
||||
dst: embeddingStruct{
|
||||
embeddedStruct{"bar"},
|
||||
},
|
||||
expected: embeddingStruct{
|
||||
embeddedStruct{"bar"},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
err := Merge(&test.dst, test.src)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
continue
|
||||
}
|
||||
if !reflect.DeepEqual(test.dst, test.expected) {
|
||||
t.Errorf("unexpected output\nexpected:\n%+v\nsaw:\n%+v\n", test.expected, test.dst)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPointerStructNil(t *testing.T) {
|
||||
a := pointerTest{nil}
|
||||
b := pointerTest{&simpleTest{19}}
|
||||
if err := Merge(&a, b); err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
if a.C.Value != b.C.Value {
|
||||
t.Fatalf("b not merged in a properly: a.C.Value(%d) != b.C.Value(%d)", a.C.Value, b.C.Value)
|
||||
}
|
||||
}
|
||||
|
||||
func testSlice(t *testing.T, a []int, b []int, e []int, opts ...func(*Config)) {
|
||||
t.Helper()
|
||||
bc := b
|
||||
|
||||
sa := sliceTest{a}
|
||||
sb := sliceTest{b}
|
||||
if err := Merge(&sa, sb, opts...); err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
if !reflect.DeepEqual(sb.S, bc) {
|
||||
t.Fatalf("Source slice was modified %d != %d", sb.S, bc)
|
||||
}
|
||||
if !reflect.DeepEqual(sa.S, e) {
|
||||
t.Fatalf("b not merged in a proper way %d != %d", sa.S, e)
|
||||
}
|
||||
|
||||
ma := map[string][]int{"S": a}
|
||||
mb := map[string][]int{"S": b}
|
||||
if err := Merge(&ma, mb, opts...); err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
if !reflect.DeepEqual(mb["S"], bc) {
|
||||
t.Fatalf("map value: Source slice was modified %d != %d", mb["S"], bc)
|
||||
}
|
||||
if !reflect.DeepEqual(ma["S"], e) {
|
||||
t.Fatalf("map value: b not merged in a proper way %d != %d", ma["S"], e)
|
||||
}
|
||||
|
||||
if a == nil {
|
||||
// test case with missing dst key
|
||||
ma := map[string][]int{}
|
||||
mb := map[string][]int{"S": b}
|
||||
if err := Merge(&ma, mb); err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
if !reflect.DeepEqual(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("missing dst key: b not merged in a proper way %d != %d", ma["S"], e)
|
||||
}
|
||||
}
|
||||
|
||||
if b == nil {
|
||||
// test case with missing src key
|
||||
ma := map[string][]int{"S": a}
|
||||
mb := map[string][]int{}
|
||||
if err := Merge(&ma, mb); err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
if !reflect.DeepEqual(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("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}, []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) {
|
||||
a := mapTest{}
|
||||
b := mapTest{
|
||||
map[int]int{},
|
||||
}
|
||||
if err := Merge(&a, b); err != nil {
|
||||
t.Fail()
|
||||
}
|
||||
if !reflect.DeepEqual(a, b) {
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
func TestEmptyToEmptyMaps(t *testing.T) {
|
||||
a := mapTest{}
|
||||
b := mapTest{}
|
||||
if err := Merge(&a, b); err != nil {
|
||||
t.Fail()
|
||||
}
|
||||
if !reflect.DeepEqual(a, b) {
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
func TestEmptyToNotEmptyMaps(t *testing.T) {
|
||||
a := mapTest{map[int]int{
|
||||
1: 2,
|
||||
3: 4,
|
||||
}}
|
||||
aa := mapTest{map[int]int{
|
||||
1: 2,
|
||||
3: 4,
|
||||
}}
|
||||
b := mapTest{
|
||||
map[int]int{},
|
||||
}
|
||||
if err := Merge(&a, b); err != nil {
|
||||
t.Fail()
|
||||
}
|
||||
if !reflect.DeepEqual(a, aa) {
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
func TestMapsWithOverwrite(t *testing.T) {
|
||||
m := map[string]simpleTest{
|
||||
"a": {}, // overwritten by 16
|
||||
"b": {42}, // not overwritten by empty value
|
||||
"c": {13}, // overwritten by 12
|
||||
"d": {61},
|
||||
}
|
||||
n := map[string]simpleTest{
|
||||
"a": {16},
|
||||
"b": {},
|
||||
"c": {12},
|
||||
"e": {14},
|
||||
}
|
||||
expect := map[string]simpleTest{
|
||||
"a": {16},
|
||||
"b": {},
|
||||
"c": {12},
|
||||
"d": {61},
|
||||
"e": {14},
|
||||
}
|
||||
|
||||
if err := MergeWithOverwrite(&m, n); 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 TestMaps(t *testing.T) {
|
||||
m := map[string]simpleTest{
|
||||
"a": {},
|
||||
"b": {42},
|
||||
"c": {13},
|
||||
"d": {61},
|
||||
}
|
||||
n := map[string]simpleTest{
|
||||
"a": {16},
|
||||
"b": {},
|
||||
"c": {12},
|
||||
"e": {14},
|
||||
}
|
||||
expect := map[string]simpleTest{
|
||||
"a": {0},
|
||||
"b": {42},
|
||||
"c": {13},
|
||||
"d": {61},
|
||||
"e": {14},
|
||||
}
|
||||
|
||||
if err := Merge(&m, n); 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)
|
||||
}
|
||||
if m["a"].Value != 0 {
|
||||
t.Fatalf(`n merged in m because I solved non-addressable map values TODO: m["a"].Value(%d) != n["a"].Value(%d)`, m["a"].Value, n["a"].Value)
|
||||
}
|
||||
if m["b"].Value != 42 {
|
||||
t.Fatalf(`n wrongly merged in m: m["b"].Value(%d) != n["b"].Value(%d)`, m["b"].Value, n["b"].Value)
|
||||
}
|
||||
if m["c"].Value != 13 {
|
||||
t.Fatalf(`n overwritten in m: m["c"].Value(%d) != n["c"].Value(%d)`, m["c"].Value, n["c"].Value)
|
||||
}
|
||||
}
|
||||
|
||||
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")
|
||||
ft := thing["fields"].(map[interface{}]interface{})
|
||||
fl := license["fields"].(map[interface{}]interface{})
|
||||
// license has one extra field (site) and another already existing in thing (author) that Mergo won't override.
|
||||
expectedLength := len(ft) + len(fl) - 1
|
||||
if err := Merge(&license, thing); err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
currentLength := len(license["fields"].(map[interface{}]interface{}))
|
||||
if currentLength != expectedLength {
|
||||
t.Fatalf(`thing not merged in license properly, license must have %d elements instead of %d`, expectedLength, currentLength)
|
||||
}
|
||||
fields := license["fields"].(map[interface{}]interface{})
|
||||
if _, ok := fields["id"]; !ok {
|
||||
t.Fatalf(`thing not merged in license properly, license must have a new id field from thing`)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTwoPointerValues(t *testing.T) {
|
||||
a := &simpleTest{}
|
||||
b := &simpleTest{42}
|
||||
if err := Merge(a, b); err != nil {
|
||||
t.Fatalf(`Boom. You crossed the streams: %s`, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMap(t *testing.T) {
|
||||
a := complexTest{}
|
||||
a.ID = "athing"
|
||||
c := moreComplextText{a, simpleTest{}, simpleTest{}}
|
||||
b := map[string]interface{}{
|
||||
"ct": map[string]interface{}{
|
||||
"st": map[string]interface{}{
|
||||
"value": 42,
|
||||
},
|
||||
"sz": 1,
|
||||
"id": "bthing",
|
||||
},
|
||||
"st": &simpleTest{144}, // Mapping a reference
|
||||
"zt": simpleTest{299}, // Mapping a missing field (zt doesn't exist)
|
||||
"nt": simpleTest{3},
|
||||
}
|
||||
if err := Map(&c, b); err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
m := b["ct"].(map[string]interface{})
|
||||
n := m["st"].(map[string]interface{})
|
||||
o := b["st"].(*simpleTest)
|
||||
p := b["nt"].(simpleTest)
|
||||
if c.Ct.St.Value != 42 {
|
||||
t.Fatalf("b not merged in properly: c.Ct.St.Value(%d) != b.Ct.St.Value(%d)", c.Ct.St.Value, n["value"])
|
||||
}
|
||||
if c.St.Value != 144 {
|
||||
t.Fatalf("b not merged in properly: c.St.Value(%d) != b.St.Value(%d)", c.St.Value, o.Value)
|
||||
}
|
||||
if c.Nt.Value != 3 {
|
||||
t.Fatalf("b not merged in properly: c.Nt.Value(%d) != b.Nt.Value(%d)", c.St.Value, p.Value)
|
||||
}
|
||||
if c.Ct.sz == 1 {
|
||||
t.Fatalf("a's private field sz not preserved from merge: c.Ct.sz(%d) == b.Ct.sz(%d)", c.Ct.sz, m["sz"])
|
||||
}
|
||||
if c.Ct.ID == m["id"] {
|
||||
t.Fatalf("a's field ID merged unexpectedly: c.Ct.ID(%s) == b.Ct.ID(%s)", c.Ct.ID, m["id"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestSimpleMap(t *testing.T) {
|
||||
a := simpleTest{}
|
||||
b := map[string]interface{}{
|
||||
"value": 42,
|
||||
}
|
||||
if err := Map(&a, b); err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
if a.Value != 42 {
|
||||
t.Fatalf("b not merged in properly: a.Value(%d) != b.Value(%v)", a.Value, b["value"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestIfcMap(t *testing.T) {
|
||||
a := ifcTest{}
|
||||
b := ifcTest{42}
|
||||
if err := Map(&a, b); err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
if a.I != 42 {
|
||||
t.Fatalf("b not merged in properly: a.I(%d) != b.I(%d)", a.I, b.I)
|
||||
}
|
||||
if !reflect.DeepEqual(a, b) {
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
func TestIfcMapNoOverwrite(t *testing.T) {
|
||||
a := ifcTest{13}
|
||||
b := ifcTest{42}
|
||||
if err := Map(&a, b); err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
if a.I != 13 {
|
||||
t.Fatalf("a not left alone: a.I(%d) == b.I(%d)", a.I, b.I)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIfcMapWithOverwrite(t *testing.T) {
|
||||
a := ifcTest{13}
|
||||
b := ifcTest{42}
|
||||
if err := MapWithOverwrite(&a, b); err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
if a.I != 42 {
|
||||
t.Fatalf("b not merged in properly: a.I(%d) != b.I(%d)", a.I, b.I)
|
||||
}
|
||||
if !reflect.DeepEqual(a, b) {
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
type pointerMapTest struct {
|
||||
A int
|
||||
hidden int
|
||||
B *simpleTest
|
||||
}
|
||||
|
||||
func TestBackAndForth(t *testing.T) {
|
||||
pt := pointerMapTest{42, 1, &simpleTest{66}}
|
||||
m := make(map[string]interface{})
|
||||
if err := Map(&m, pt); err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
var (
|
||||
v interface{}
|
||||
ok bool
|
||||
)
|
||||
if v, ok = m["a"]; v.(int) != pt.A || !ok {
|
||||
t.Fatalf("pt not merged in properly: m[`a`](%d) != pt.A(%d)", v, pt.A)
|
||||
}
|
||||
if v, ok = m["b"]; !ok {
|
||||
t.Fatalf("pt not merged in properly: B is missing in m")
|
||||
}
|
||||
var st *simpleTest
|
||||
if st = v.(*simpleTest); st.Value != 66 {
|
||||
t.Fatalf("something went wrong while mapping pt on m, B wasn't copied")
|
||||
}
|
||||
bpt := pointerMapTest{}
|
||||
if err := Map(&bpt, m); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if bpt.A != pt.A {
|
||||
t.Fatalf("pt not merged in properly: bpt.A(%d) != pt.A(%d)", bpt.A, pt.A)
|
||||
}
|
||||
if bpt.hidden == pt.hidden {
|
||||
t.Fatalf("pt unexpectedly merged: bpt.hidden(%d) == pt.hidden(%d)", bpt.hidden, pt.hidden)
|
||||
}
|
||||
if bpt.B.Value != pt.B.Value {
|
||||
t.Fatalf("pt not merged in properly: bpt.B.Value(%d) != pt.B.Value(%d)", bpt.B.Value, pt.B.Value)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEmbeddedPointerUnpacking(t *testing.T) {
|
||||
tests := []struct{ input pointerMapTest }{
|
||||
{pointerMapTest{42, 1, nil}},
|
||||
{pointerMapTest{42, 1, &simpleTest{66}}},
|
||||
}
|
||||
newValue := 77
|
||||
m := map[string]interface{}{
|
||||
"b": map[string]interface{}{
|
||||
"value": newValue,
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
pt := test.input
|
||||
if err := MapWithOverwrite(&pt, m); err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
if pt.B.Value != newValue {
|
||||
t.Fatalf("pt not mapped properly: pt.A.Value(%d) != m[`b`][`value`](%d)", pt.B.Value, newValue)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
type structWithTimePointer struct {
|
||||
Birth *time.Time
|
||||
}
|
||||
|
||||
func TestTime(t *testing.T) {
|
||||
now := time.Now()
|
||||
dataStruct := structWithTimePointer{
|
||||
Birth: &now,
|
||||
}
|
||||
dataMap := map[string]interface{}{
|
||||
"Birth": &now,
|
||||
}
|
||||
b := structWithTimePointer{}
|
||||
if err := Merge(&b, dataStruct); err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
if b.Birth.IsZero() {
|
||||
t.Fatalf("time.Time not merged in properly: b.Birth(%v) != dataStruct['Birth'](%v)", b.Birth, dataStruct.Birth)
|
||||
}
|
||||
if b.Birth != dataStruct.Birth {
|
||||
t.Fatalf("time.Time not merged in properly: b.Birth(%v) != dataStruct['Birth'](%v)", b.Birth, dataStruct.Birth)
|
||||
}
|
||||
b = structWithTimePointer{}
|
||||
if err := Map(&b, dataMap); err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
if b.Birth.IsZero() {
|
||||
t.Fatalf("time.Time not merged in properly: b.Birth(%v) != dataMap['Birth'](%v)", b.Birth, dataMap["Birth"])
|
||||
}
|
||||
}
|
||||
|
||||
type simpleNested struct {
|
||||
A int
|
||||
}
|
||||
|
||||
type structWithNestedPtrValueMap struct {
|
||||
NestedPtrValue map[string]*simpleNested
|
||||
}
|
||||
|
||||
func TestNestedPtrValueInMap(t *testing.T) {
|
||||
src := &structWithNestedPtrValueMap{
|
||||
NestedPtrValue: map[string]*simpleNested{
|
||||
"x": {
|
||||
A: 1,
|
||||
},
|
||||
},
|
||||
}
|
||||
dst := &structWithNestedPtrValueMap{
|
||||
NestedPtrValue: map[string]*simpleNested{
|
||||
"x": {},
|
||||
},
|
||||
}
|
||||
if err := Map(dst, src); err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
if dst.NestedPtrValue["x"].A == 0 {
|
||||
t.Fatalf("Nested Ptr value not merged in properly: dst.NestedPtrValue[\"x\"].A(%v) != src.NestedPtrValue[\"x\"].A(%v)", dst.NestedPtrValue["x"].A, src.NestedPtrValue["x"].A)
|
||||
}
|
||||
}
|
||||
|
||||
func loadYAML(path string) (m map[string]interface{}) {
|
||||
m = make(map[string]interface{})
|
||||
raw, _ := ioutil.ReadFile(path)
|
||||
_ = yaml.Unmarshal(raw, &m)
|
||||
return
|
||||
}
|
||||
|
||||
type structWithMap struct {
|
||||
m map[string]structWithUnexportedProperty
|
||||
}
|
||||
|
||||
type structWithUnexportedProperty struct {
|
||||
s string
|
||||
}
|
||||
|
||||
func TestUnexportedProperty(t *testing.T) {
|
||||
a := structWithMap{map[string]structWithUnexportedProperty{
|
||||
"key": {"hello"},
|
||||
}}
|
||||
b := structWithMap{map[string]structWithUnexportedProperty{
|
||||
"key": {"hi"},
|
||||
}}
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
t.Errorf("Should not have panicked")
|
||||
}
|
||||
}()
|
||||
Merge(&a, b)
|
||||
}
|
||||
|
||||
type structWithBoolPointer struct {
|
||||
C *bool
|
||||
}
|
||||
|
||||
func TestBooleanPointer(t *testing.T) {
|
||||
bt, bf := true, false
|
||||
src := structWithBoolPointer{
|
||||
&bt,
|
||||
}
|
||||
dst := structWithBoolPointer{
|
||||
&bf,
|
||||
}
|
||||
if err := Merge(&dst, src); err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
if dst.C == src.C {
|
||||
t.Fatalf("dst.C should be a different pointer than src.C")
|
||||
}
|
||||
if *dst.C != *src.C {
|
||||
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
18
vendor/github.com/imdario/mergo/pr80_test.go
generated
vendored
@ -1,18 +0,0 @@
|
||||
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
42
vendor/github.com/imdario/mergo/pr81_test.go
generated
vendored
@ -1,42 +0,0 @@
|
||||
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)
|
||||
}
|
||||
}
|
6
vendor/github.com/imdario/mergo/testdata/thing.yml
generated
vendored
6
vendor/github.com/imdario/mergo/testdata/thing.yml
generated
vendored
@ -1,6 +0,0 @@
|
||||
fields:
|
||||
id: int
|
||||
name: string
|
||||
parent: ref "datu:thing"
|
||||
status: enum(draft, public, private)
|
||||
author: updater
|
Reference in New Issue
Block a user