Codebase list golang-github-mitchellh-mapstructure / e6efb10f-cf02-4933-bf87-1ecd246e3b4c/upstream/1.5.0+git20220423.1.bf980b3
Import upstream version 1.5.0+git20220423.1.bf980b3 Debian Janitor 1 year, 3 months ago
4 changed file(s) with 41 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
+0
-18
.github/workflows/test.yml less more
0 on: [push, pull_request]
1 name: Test
2 jobs:
3 test:
4 strategy:
5 matrix:
6 go-version: [1.15.x]
7 os: [ubuntu-latest]
8 runs-on: ${{ matrix.os }}
9 steps:
10 - name: Install Go
11 uses: actions/setup-go@v2
12 with:
13 go-version: ${{ matrix.go-version }}
14 - name: Checkout code
15 uses: actions/checkout@v2
16 - name: Test
17 run: go test ./...
0 ## 1.5.1
1
2 * Wrap errors so they're compatible with `errors.Is` and `errors.As` [GH-282]
3 * Fix map of slices not decoding properly in certain cases. [GH-266]
4
05 ## 1.5.0
16
27 * New option `IgnoreUntaggedFields` to ignore decoding to any fields
457457 var err error
458458 input, err = DecodeHookExec(d.config.DecodeHook, inputVal, outVal)
459459 if err != nil {
460 return fmt.Errorf("error decoding '%s': %s", name, err)
460 return fmt.Errorf("error decoding '%s': %w", name, err)
461461 }
462462 }
463463
11221122 if valSlice.IsNil() || d.config.ZeroFields {
11231123 // Make a new slice to hold our result, same size as the original data.
11241124 valSlice = reflect.MakeSlice(sliceType, dataVal.Len(), dataVal.Len())
1125 } else if valSlice.Len() > dataVal.Len() {
1126 valSlice = valSlice.Slice(0, dataVal.Len())
11251127 }
11261128
11271129 // Accumulate any errors
135135 type Slice struct {
136136 Vfoo string
137137 Vbar []string
138 }
139
140 type SliceOfByte struct {
141 Vfoo string
142 Vbar []byte
138143 }
139144
140145 type SliceOfAlias struct {
16531658 testSliceInput(t, inputStringSlicePointer, outputStringSlice)
16541659 }
16551660
1661 func TestNotEmptyByteSlice(t *testing.T) {
1662 t.Parallel()
1663
1664 inputByteSlice := map[string]interface{}{
1665 "vfoo": "foo",
1666 "vbar": []byte(`{"bar": "bar"}`),
1667 }
1668
1669 result := SliceOfByte{
1670 Vfoo: "another foo",
1671 Vbar: []byte(`{"bar": "bar bar bar bar bar bar bar bar"}`),
1672 }
1673
1674 err := Decode(inputByteSlice, &result)
1675 if err != nil {
1676 t.Fatalf("got unexpected error: %s", err)
1677 }
1678
1679 expected := SliceOfByte{
1680 Vfoo: "foo",
1681 Vbar: []byte(`{"bar": "bar"}`),
1682 }
1683
1684 if !reflect.DeepEqual(result, expected) {
1685 t.Errorf("bad: %#v", result)
1686 }
1687 }
1688
16561689 func TestInvalidSlice(t *testing.T) {
16571690 t.Parallel()
16581691