1 // Copyright (c) 2014 The btcsuite developers
2 // Use of this source code is governed by an ISC
3 // license that can be found in the LICENSE file.
10 "github.com/btcsuite/btcd/btcjson"
13 // TestErrorCodeStringer tests the stringized output for the ErrorCode type.
14 func TestErrorCodeStringer(t *testing.T) {
21 {btcjson.ErrDuplicateMethod, "ErrDuplicateMethod"},
22 {btcjson.ErrInvalidUsageFlags, "ErrInvalidUsageFlags"},
23 {btcjson.ErrInvalidType, "ErrInvalidType"},
24 {btcjson.ErrEmbeddedType, "ErrEmbeddedType"},
25 {btcjson.ErrUnexportedField, "ErrUnexportedField"},
26 {btcjson.ErrUnsupportedFieldType, "ErrUnsupportedFieldType"},
27 {btcjson.ErrNonOptionalField, "ErrNonOptionalField"},
28 {btcjson.ErrNonOptionalDefault, "ErrNonOptionalDefault"},
29 {btcjson.ErrMismatchedDefault, "ErrMismatchedDefault"},
30 {btcjson.ErrUnregisteredMethod, "ErrUnregisteredMethod"},
31 {btcjson.ErrNumParams, "ErrNumParams"},
32 {btcjson.ErrMissingDescription, "ErrMissingDescription"},
33 {0xffff, "Unknown ErrorCode (65535)"},
36 // Detect additional error codes that don't have the stringer added.
37 if len(tests)-1 != int(btcjson.TstNumErrorCodes) {
38 t.Errorf("It appears an error code was added without adding an " +
39 "associated stringer test")
42 t.Logf("Running %d tests", len(tests))
43 for i, test := range tests {
44 result := test.in.String()
45 if result != test.want {
46 t.Errorf("String #%d\n got: %s want: %s", i, result,
53 // TestError tests the error output for the Error type.
54 func TestError(t *testing.T) {
62 btcjson.Error{Description: "some error"},
66 btcjson.Error{Description: "human-readable error"},
67 "human-readable error",
71 t.Logf("Running %d tests", len(tests))
72 for i, test := range tests {
73 result := test.in.Error()
74 if result != test.want {
75 t.Errorf("Error #%d\n got: %s want: %s", i, result,