github.com/dashpay/godash@v0.0.0-20160726055534-e038a21e0e3d/btcjson/error_test.go (about)

     1  // Copyright (c) 2014 The btcsuite developers
     2  // Copyright (c) 2016 The Dash developers
     3  // Use of this source code is governed by an ISC
     4  // license that can be found in the LICENSE file.
     5  
     6  package btcjson_test
     7  
     8  import (
     9  	"testing"
    10  
    11  	"github.com/dashpay/godash/btcjson"
    12  )
    13  
    14  // TestErrorCodeStringer tests the stringized output for the ErrorCode type.
    15  func TestErrorCodeStringer(t *testing.T) {
    16  	t.Parallel()
    17  
    18  	tests := []struct {
    19  		in   btcjson.ErrorCode
    20  		want string
    21  	}{
    22  		{btcjson.ErrDuplicateMethod, "ErrDuplicateMethod"},
    23  		{btcjson.ErrInvalidUsageFlags, "ErrInvalidUsageFlags"},
    24  		{btcjson.ErrInvalidType, "ErrInvalidType"},
    25  		{btcjson.ErrEmbeddedType, "ErrEmbeddedType"},
    26  		{btcjson.ErrUnexportedField, "ErrUnexportedField"},
    27  		{btcjson.ErrUnsupportedFieldType, "ErrUnsupportedFieldType"},
    28  		{btcjson.ErrNonOptionalField, "ErrNonOptionalField"},
    29  		{btcjson.ErrNonOptionalDefault, "ErrNonOptionalDefault"},
    30  		{btcjson.ErrMismatchedDefault, "ErrMismatchedDefault"},
    31  		{btcjson.ErrUnregisteredMethod, "ErrUnregisteredMethod"},
    32  		{btcjson.ErrNumParams, "ErrNumParams"},
    33  		{btcjson.ErrMissingDescription, "ErrMissingDescription"},
    34  		{0xffff, "Unknown ErrorCode (65535)"},
    35  	}
    36  
    37  	// Detect additional error codes that don't have the stringer added.
    38  	if len(tests)-1 != int(btcjson.TstNumErrorCodes) {
    39  		t.Errorf("It appears an error code was added without adding an " +
    40  			"associated stringer test")
    41  	}
    42  
    43  	t.Logf("Running %d tests", len(tests))
    44  	for i, test := range tests {
    45  		result := test.in.String()
    46  		if result != test.want {
    47  			t.Errorf("String #%d\n got: %s want: %s", i, result,
    48  				test.want)
    49  			continue
    50  		}
    51  	}
    52  }
    53  
    54  // TestError tests the error output for the Error type.
    55  func TestError(t *testing.T) {
    56  	t.Parallel()
    57  
    58  	tests := []struct {
    59  		in   btcjson.Error
    60  		want string
    61  	}{
    62  		{
    63  			btcjson.Error{Description: "some error"},
    64  			"some error",
    65  		},
    66  		{
    67  			btcjson.Error{Description: "human-readable error"},
    68  			"human-readable error",
    69  		},
    70  	}
    71  
    72  	t.Logf("Running %d tests", len(tests))
    73  	for i, test := range tests {
    74  		result := test.in.Error()
    75  		if result != test.want {
    76  			t.Errorf("Error #%d\n got: %s want: %s", i, result,
    77  				test.want)
    78  			continue
    79  		}
    80  	}
    81  }