-
Notifications
You must be signed in to change notification settings - Fork 52
/
error_test.go
46 lines (37 loc) · 1020 Bytes
/
error_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package ch
import (
"context"
"io"
"testing"
"github.com/go-faster/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/multierr"
"github.com/ClickHouse/ch-go/proto"
)
func TestError(t *testing.T) {
err := errors.Wrap(multierr.Append(
errors.Wrap(io.EOF, "foo"),
errors.Wrap(context.Canceled, "bar"),
), "parent")
t.Log(err)
assert.ErrorIs(t, err, io.EOF)
assert.ErrorIs(t, err, context.Canceled)
}
func TestException_Error(t *testing.T) {
err := errors.Wrap(multierr.Append(
errors.Wrap(&Exception{
Code: proto.ErrBadArguments,
}, "foo"),
errors.Wrap(context.Canceled, "bar"),
), "parent")
var ex *Exception
require.ErrorAs(t, err, &ex)
require.True(t, IsException(err), "IsException should be true")
e, ok := AsException(err)
require.True(t, ok)
require.NotNil(t, e)
require.True(t, IsErr(err, proto.ErrBadArguments))
require.False(t, IsErr(err, proto.ErrTableIsDropped))
require.False(t, IsErr(io.EOF, proto.ErrBadArguments))
}