forked from gcash/bchd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error_test.go
80 lines (70 loc) · 2.07 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright (c) 2014 The btcsuite developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package btcjson_test
import (
"testing"
"github.com/gcash/bchd/btcjson"
)
// TestErrorCodeStringer tests the stringized output for the ErrorCode type.
func TestErrorCodeStringer(t *testing.T) {
t.Parallel()
tests := []struct {
in btcjson.ErrorCode
want string
}{
{btcjson.ErrDuplicateMethod, "ErrDuplicateMethod"},
{btcjson.ErrInvalidUsageFlags, "ErrInvalidUsageFlags"},
{btcjson.ErrInvalidType, "ErrInvalidType"},
{btcjson.ErrEmbeddedType, "ErrEmbeddedType"},
{btcjson.ErrUnexportedField, "ErrUnexportedField"},
{btcjson.ErrUnsupportedFieldType, "ErrUnsupportedFieldType"},
{btcjson.ErrNonOptionalField, "ErrNonOptionalField"},
{btcjson.ErrNonOptionalDefault, "ErrNonOptionalDefault"},
{btcjson.ErrMismatchedDefault, "ErrMismatchedDefault"},
{btcjson.ErrUnregisteredMethod, "ErrUnregisteredMethod"},
{btcjson.ErrNumParams, "ErrNumParams"},
{btcjson.ErrMissingDescription, "ErrMissingDescription"},
{0xffff, "Unknown ErrorCode (65535)"},
}
// Detect additional error codes that don't have the stringer added.
if len(tests)-1 != int(btcjson.TstNumErrorCodes) {
t.Errorf("It appears an error code was added without adding an " +
"associated stringer test")
}
t.Logf("Running %d tests", len(tests))
for i, test := range tests {
result := test.in.String()
if result != test.want {
t.Errorf("String #%d\n got: %s want: %s", i, result,
test.want)
continue
}
}
}
// TestError tests the error output for the Error type.
func TestError(t *testing.T) {
t.Parallel()
tests := []struct {
in btcjson.Error
want string
}{
{
btcjson.Error{Description: "some error"},
"some error",
},
{
btcjson.Error{Description: "human-readable error"},
"human-readable error",
},
}
t.Logf("Running %d tests", len(tests))
for i, test := range tests {
result := test.in.Error()
if result != test.want {
t.Errorf("Error #%d\n got: %s want: %s", i, result,
test.want)
continue
}
}
}