File: error_test.go

package info (click to toggle)
golang-github-juju-testing 1.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 512 kB
  • sloc: makefile: 6
file content (69 lines) | stat: -rw-r--r-- 1,471 bytes parent folder | download
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package checkers_test

import (
	"fmt"

	"github.com/juju/errors"
	jc "github.com/juju/testing/checkers"
	gc "gopkg.in/check.v1"
)

type ErrorSuite struct{}

var _ = gc.Suite(&ErrorSuite{})

var errorIsTests = []struct {
	arg    interface{}
	target interface{}
	result bool
	msg    string
}{{
	arg:    fmt.Errorf("bar"),
	target: nil,
	result: false,
}, {
	arg:    nil,
	target: fmt.Errorf("bar"),
	result: false,
}, {
	arg:    nil,
	target: nil,
	result: true,
}, {
	arg:    fmt.Errorf("bar"),
	target: fmt.Errorf("foo"),
	result: false,
}, {
	arg:    errors.ConstError("bar"),
	target: errors.ConstError("foo"),
	result: false,
}, {
	arg:    errors.ConstError("foo"),
	target: errors.ConstError("foo"),
	result: true,
}, {
	arg:    errors.Trace(errors.ConstError("foo")),
	target: errors.ConstError("foo"),
	result: true,
}, {
	arg:    errors.ConstError("foo"),
	target: "blah",
	msg:    "wrong error target type, got: string",
}, {
	arg:    "blah",
	target: errors.ConstError("foo"),
	msg:    "wrong argument type string for errors.ConstError",
}, {
	arg:    (*error)(nil),
	target: errors.ConstError("foo"),
	msg:    "wrong argument type *error for errors.ConstError",
}}

func (s *ErrorSuite) TestErrorIs(c *gc.C) {
	for i, test := range errorIsTests {
		c.Logf("test %d. %T %T", i, test.arg, test.target)
		result, msg := jc.ErrorIs.Check([]interface{}{test.arg, test.target}, nil)
		c.Check(result, gc.Equals, test.result)
		c.Check(msg, gc.Equals, test.msg)
	}
}