-
-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into should-not-dereference
- Loading branch information
Showing
11 changed files
with
299 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name: 'fund-on-stackaid' | ||
on: | ||
push: | ||
branches: | ||
- master | ||
jobs: | ||
stackaid-json: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-go@v3 # Only required for Go based repos | ||
- uses: stackaid/[email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
| 0.3.x | :white_check_mark: | | ||
| < 0.3 | :x: | | ||
|
||
## Reporting a Vulnerability | ||
## Security contact information | ||
|
||
Report any vulnerability to [email protected]. | ||
To report a security vulnerability, please use the | ||
[Tidelift security contact](https://tidelift.com/security). | ||
Tidelift will coordinate the fix and disclosure. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
package mergo_test | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/imdario/mergo" | ||
) | ||
|
||
func TestIssue202(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
dst, src, want map[string]interface{} | ||
}{ | ||
{ | ||
name: "slice override string", | ||
dst: map[string]interface{}{ | ||
"x": 456, | ||
"y": "foo", | ||
}, | ||
src: map[string]interface{}{ | ||
"x": "123", | ||
"y": []int{1, 2, 3}, | ||
}, | ||
want: map[string]interface{}{ | ||
"x": "123", | ||
"y": []int{1, 2, 3}, | ||
}, | ||
}, | ||
{ | ||
name: "string override slice", | ||
dst: map[string]interface{}{ | ||
"x": 456, | ||
"y": []int{1, 2, 3}, | ||
}, | ||
src: map[string]interface{}{ | ||
"x": "123", | ||
"y": "foo", | ||
}, | ||
want: map[string]interface{}{ | ||
"x": "123", | ||
"y": "foo", | ||
}, | ||
}, | ||
{ | ||
name: "map override string", | ||
dst: map[string]interface{}{ | ||
"x": 456, | ||
"y": "foo", | ||
}, | ||
src: map[string]interface{}{ | ||
"x": "123", | ||
"y": map[string]interface{}{ | ||
"a": true, | ||
}, | ||
}, | ||
want: map[string]interface{}{ | ||
"x": "123", | ||
"y": map[string]interface{}{ | ||
"a": true, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "string override map", | ||
dst: map[string]interface{}{ | ||
"x": 456, | ||
"y": map[string]interface{}{ | ||
"a": true, | ||
}, | ||
}, | ||
src: map[string]interface{}{ | ||
"x": "123", | ||
"y": "foo", | ||
}, | ||
want: map[string]interface{}{ | ||
"x": "123", | ||
"y": "foo", | ||
}, | ||
}, | ||
{ | ||
name: "map override map", | ||
dst: map[string]interface{}{ | ||
"x": 456, | ||
"y": map[string]interface{}{ | ||
"a": 10, | ||
}, | ||
}, | ||
src: map[string]interface{}{ | ||
"x": "123", | ||
"y": map[string]interface{}{ | ||
"a": true, | ||
}, | ||
}, | ||
want: map[string]interface{}{ | ||
"x": "123", | ||
"y": map[string]interface{}{ | ||
"a": true, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "map override map with merge", | ||
dst: map[string]interface{}{ | ||
"x": 456, | ||
"y": map[string]interface{}{ | ||
"a": 10, | ||
"b": 100, | ||
}, | ||
}, | ||
src: map[string]interface{}{ | ||
"x": "123", | ||
"y": map[string]interface{}{ | ||
"a": true, | ||
}, | ||
}, | ||
want: map[string]interface{}{ | ||
"x": "123", | ||
"y": map[string]interface{}{ | ||
"a": true, | ||
"b": 100, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if err := mergo.Merge(&tt.dst, tt.src, mergo.WithOverride); err != nil { | ||
t.Error(err) | ||
} | ||
|
||
if !reflect.DeepEqual(tt.dst, tt.want) { | ||
t.Errorf("maps not equal.\nwant:\n%v\ngot:\n%v\n", tt.want, tt.dst) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package mergo_test | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/imdario/mergo" | ||
) | ||
|
||
func TestIssue220(t *testing.T) { | ||
dst := []interface{}{ | ||
map[string]int{ | ||
"a": 1, | ||
}, | ||
} | ||
src := []interface{}{ | ||
"nil", | ||
} | ||
expected := []interface{}{ | ||
map[string]int{ | ||
"a": 1, | ||
}, | ||
} | ||
|
||
err := mergo.Merge(&dst, src, mergo.WithSliceDeepCopy) | ||
if err != nil { | ||
t.Errorf("unexpected error %v", err) | ||
} | ||
|
||
if !reflect.DeepEqual(dst, expected) { | ||
t.Errorf("expected: %#v\ngot: %#v", expected, dst) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package mergo_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/imdario/mergo" | ||
) | ||
|
||
var testDataM = []struct { | ||
M1 mapTest | ||
M2 mapTest | ||
WithOverrideEmptyValue bool | ||
ExpectedMap map[int]int | ||
}{ | ||
{ | ||
M1: mapTest{ | ||
M: map[int]int{1: 1, 3: 3}, | ||
}, | ||
M2: mapTest{ | ||
M: map[int]int{1: 2, 2: 2}, | ||
}, | ||
WithOverrideEmptyValue: true, | ||
ExpectedMap: map[int]int{1: 1, 3: 3}, | ||
}, | ||
{ | ||
M1: mapTest{ | ||
M: map[int]int{1: 1, 3: 3}, | ||
}, | ||
M2: mapTest{ | ||
M: map[int]int{1: 2, 2: 2}, | ||
}, | ||
WithOverrideEmptyValue: false, | ||
ExpectedMap: map[int]int{1: 1, 2: 2, 3: 3}, | ||
}, | ||
{ | ||
M1: mapTest{ | ||
M: map[int]int{}, | ||
}, | ||
M2: mapTest{ | ||
M: map[int]int{1: 2, 2: 2}, | ||
}, | ||
WithOverrideEmptyValue: true, | ||
ExpectedMap: map[int]int{}, | ||
}, | ||
{ | ||
M1: mapTest{ | ||
M: map[int]int{}, | ||
}, | ||
M2: mapTest{ | ||
M: map[int]int{1: 2, 2: 2}, | ||
}, | ||
WithOverrideEmptyValue: false, | ||
ExpectedMap: map[int]int{1: 2, 2: 2}, | ||
}, | ||
} | ||
|
||
func withOverrideEmptyValue(enable bool) func(*mergo.Config) { | ||
if enable { | ||
return mergo.WithOverwriteWithEmptyValue | ||
} | ||
|
||
return mergo.WithOverride | ||
} | ||
|
||
func TestMergeMapWithOverride(t *testing.T) { | ||
t.Parallel() | ||
|
||
for _, data := range testDataM { | ||
err := mergo.Merge(&data.M2, data.M1, withOverrideEmptyValue(data.WithOverrideEmptyValue)) | ||
if err != nil { | ||
t.Errorf("Error while merging %s", err) | ||
} | ||
|
||
if len(data.M2.M) != len(data.ExpectedMap) { | ||
t.Errorf("Got %d elements in map, but expected %d", len(data.M2.M), len(data.ExpectedMap)) | ||
return | ||
} | ||
|
||
for i, val := range data.M2.M { | ||
if val != data.ExpectedMap[i] { | ||
t.Errorf("Expected value: %d, but got %d while merging map", data.ExpectedMap[i], val) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.