mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-12-16 20:24:15 +03:00
6358240e9b
Merge in DNS/adguard-home from 2273-clean-tests-output to master Closes #2273. Squashed commit of the following: commit 7571a33fc1f76300bd256578b3afa95338e399c4 Merge: f17df0f9ca19523b25
Author: Eugene Burkov <e.burkov@adguard.com> Date: Mon Nov 16 15:45:30 2020 +0300 Merge branch 'master' into 2273-clean-tests-output commit f17df0f9ce2a3ed25db33fbc6a2e7cabd33f657b Author: Eugene Burkov <e.burkov@adguard.com> Date: Mon Nov 16 15:35:42 2020 +0300 home: move build constraint on top line commit 3717c8ef5a51f9dcaa7e524bfa7b0f1d90bec93d Author: Eugene Burkov <e.burkov@adguard.com> Date: Mon Nov 16 15:24:50 2020 +0300 all: add improvements to changelog commit de6d5afe39d74a3c3d3e0bbe6d0e09aea0214d56 Merge: 43d4f7acf394fc5a9d
Author: Eugene Burkov <e.burkov@adguard.com> Date: Mon Nov 16 15:04:38 2020 +0300 Merge branch 'master' into 2273-clean-tests-output commit 43d4f7acf188e810aa7277cb6479110c9842e8be Author: Eugene Burkov <e.burkov@adguard.com> Date: Mon Nov 16 13:38:13 2020 +0300 dnsfilter: remove redundant test logging commit 7194c1413006b8f52fc454e89ab052bf52e4e517 Author: Eugene Burkov <e.burkov@adguard.com> Date: Mon Nov 16 12:19:14 2020 +0300 testutil: improve comments commit 9f17ab08e287fa69ce30d9e7eec8ea8880f87716 Author: Eugene Burkov <e.burkov@adguard.com> Date: Sat Nov 14 01:22:08 2020 +0300 nclient4: fix wrong function name commit f355749149b2a4485792ba2bdcbc0bb4b629d726 Author: Eugene Burkov <e.burkov@adguard.com> Date: Sat Nov 14 01:07:22 2020 +0300 testutil: fix comments and naming commit f8c50a260bfae08d594a7f37d603941d3680a45e Author: Eugene Burkov <e.burkov@adguard.com> Date: Fri Nov 13 14:09:50 2020 +0300 testutil: create a package and include it commit f169cdc4084b719de65aa0cdc65200b48785322e Author: Eugene Burkov <e.burkov@adguard.com> Date: Thu Nov 12 20:15:58 2020 +0300 agherr: discard loggers output commit 360e736b5a2a30f2c5350448234f14b841e3ea27 Author: Eugene Burkov <e.burkov@adguard.com> Date: Thu Nov 12 20:09:55 2020 +0300 all: replace default log writer with ioutil.Discard Closes #2273.
79 lines
1.5 KiB
Go
79 lines
1.5 KiB
Go
package agherr
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/testutil"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestMain(m *testing.M) {
|
|
testutil.DiscardLogOutput(m)
|
|
}
|
|
|
|
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) {
|
|
const (
|
|
errSimple = iota
|
|
errWrapped
|
|
errNil
|
|
)
|
|
errs := []error{
|
|
errSimple: errors.New("a"),
|
|
errWrapped: fmt.Errorf("%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)
|
|
}
|
|
}
|