File: error_test.go

package info (click to toggle)
golang-github-go-kit-kit 0.13.0-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,784 kB
  • sloc: sh: 22; makefile: 11
file content (54 lines) | stat: -rw-r--r-- 1,171 bytes parent folder | download | duplicates (3)
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
package jsonrpc

import "testing"

func TestError(t *testing.T) {
	wantCode := ParseError
	sut := Error{
		Code: wantCode,
	}

	gotCode := sut.ErrorCode()
	if gotCode != wantCode {
		t.Fatalf("want=%d, got=%d", gotCode, wantCode)
	}

	if sut.Error() == "" {
		t.Fatal("Empty error string.")
	}

	want := "override"
	sut.Message = want
	got := sut.Error()
	if sut.Error() != want {
		t.Fatalf("overridden error message: want=%s, got=%s", want, got)
	}

}
func TestErrorsSatisfyError(t *testing.T) {
	errs := []interface{}{
		parseError("parseError"),
		invalidRequestError("invalidRequestError"),
		methodNotFoundError("methodNotFoundError"),
		invalidParamsError("invalidParamsError"),
		internalError("internalError"),
	}
	for _, e := range errs {
		err, ok := e.(error)
		if !ok {
			t.Fatalf("Couldn't assert %s as error.", e)
		}
		errString := err.Error()
		if errString == "" {
			t.Fatal("Empty error string")
		}

		ec, ok := e.(ErrorCoder)
		if !ok {
			t.Fatalf("Couldn't assert %s as ErrorCoder.", e)
		}
		if ErrorMessage(ec.ErrorCode()) == "" {
			t.Fatalf("Error type %s returned code of %d, which does not map to error string", e, ec.ErrorCode())
		}
	}
}