c9d2436d77
Merge in DNS/adguard-home from 2574-external-tests-3 to master Updates #2574. Squashed commit of the following: commit 29d429c65dee2621ca503710a7ba9522f14f55f9 Author: Eugene Burkov <e.burkov@adguard.com> Date: Thu Feb 4 20:06:57 2021 +0300 all: finally fix spacing commit 9e3a3be63b74852a7802e3f1832648444b58e4d0 Author: Eugene Burkov <e.burkov@adguard.com> Date: Thu Feb 4 19:59:09 2021 +0300 aghtest: polish spacing commit 8a984159fe813b95b989803f5b8b78d01a41bd39 Author: Eugene Burkov <e.burkov@adguard.com> Date: Thu Feb 4 18:44:47 2021 +0300 all: fix linux tests, imp code quality commit 0c1b42bacba1b23fa847e1fa032579c525b3eaa1 Author: Eugene Burkov <e.burkov@adguard.com> Date: Thu Feb 4 17:33:12 2021 +0300 all: mv testutil to aghtest package, imp tests
76 lines
1.4 KiB
Go
76 lines
1.4 KiB
Go
package agherr
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestError_Error(t *testing.T) {
|
|
testCases := []struct {
|
|
name string
|
|
want string
|
|
err error
|
|
}{{
|
|
name: "simple",
|
|
want: "a",
|
|
err: Many("a"),
|
|
}, {
|
|
name: "wrapping",
|
|
want: "a: b",
|
|
err: Many("a", errors.New("b")),
|
|
}, {
|
|
name: "wrapping several",
|
|
want: "a: b (hidden: c, d)",
|
|
err: Many("a", errors.New("b"), errors.New("c"), errors.New("d")),
|
|
}, {
|
|
name: "wrapping wrapper",
|
|
want: "a: b: c (hidden: d)",
|
|
err: Many("a", Many("b", errors.New("c"), errors.New("d"))),
|
|
}}
|
|
for _, tc := range testCases {
|
|
assert.Equal(t, tc.want, tc.err.Error(), tc.name)
|
|
}
|
|
}
|
|
|
|
func TestError_Unwrap(t *testing.T) {
|
|
var _ wrapper = &manyError{}
|
|
|
|
const (
|
|
errSimple = iota
|
|
errWrapped
|
|
errNil
|
|
)
|
|
errs := []error{
|
|
errSimple: errors.New("a"),
|
|
errWrapped: fmt.Errorf("err: %w", errors.New("nested")),
|
|
errNil: nil,
|
|
}
|
|
testCases := []struct {
|
|
name string
|
|
want error
|
|
wrapped error
|
|
}{{
|
|
name: "simple",
|
|
want: errs[errSimple],
|
|
wrapped: Many("a", errs[errSimple]),
|
|
}, {
|
|
name: "nested",
|
|
want: errs[errWrapped],
|
|
wrapped: Many("b", errs[errWrapped]),
|
|
}, {
|
|
name: "nil passed",
|
|
want: errs[errNil],
|
|
wrapped: Many("c", errs[errNil]),
|
|
}, {
|
|
name: "nil not passed",
|
|
want: nil,
|
|
wrapped: Many("d"),
|
|
}}
|
|
for _, tc := range testCases {
|
|
assert.Equal(t, tc.want, errors.Unwrap(tc.wrapped), tc.name)
|
|
}
|
|
}
|