github.com/blueinnovationsgroup/can-go@v0.0.0-20230518195432-d0567cda0028/pkg/socketcan/errorframe_test.go (about)

     1  package socketcan
     2  
     3  import (
     4  	"testing"
     5  
     6  	"gotest.tools/v3/assert"
     7  )
     8  
     9  func TestErrorFrame_String(t *testing.T) {
    10  	for _, tt := range []struct {
    11  		msg      string
    12  		f        ErrorFrame
    13  		expected string
    14  	}{
    15  		{
    16  			msg: "lost arbitration",
    17  			f: ErrorFrame{
    18  				ErrorClass:         ErrorClassLostArbitration,
    19  				LostArbitrationBit: 42,
    20  			},
    21  			expected: "LostArbitration in bit 42 (000000)",
    22  		},
    23  		{
    24  			msg: "controller",
    25  			f: ErrorFrame{
    26  				ErrorClass:      ErrorClassController,
    27  				ControllerError: ControllerErrorRxBufferOverflow,
    28  			},
    29  			expected: "Controller: RxBufferOverflow (000000)",
    30  		},
    31  		{
    32  			msg: "protocol violation",
    33  			f: ErrorFrame{
    34  				ErrorClass:                     ErrorClassProtocolViolation,
    35  				ProtocolError:                  ProtocolViolationErrorFrameFormat,
    36  				ProtocolViolationErrorLocation: ProtocolViolationErrorLocationID20To18,
    37  			},
    38  			expected: "ProtocolViolation: FrameFormat: location ID20To18 (000000)",
    39  		},
    40  		{
    41  			msg: "transceiver",
    42  			f: ErrorFrame{
    43  				ErrorClass:       ErrorClassTransceiver,
    44  				TransceiverError: TransceiverErrorCANHShortToGND,
    45  			},
    46  			expected: "Transceiver: CANHShortToGND (000000)",
    47  		},
    48  		{
    49  			msg: "controller specific information",
    50  			f: ErrorFrame{
    51  				ErrorClass:                    ErrorClassTxTimeout,
    52  				ControllerSpecificInformation: [3]byte{0x12, 0x34, 0x56},
    53  			},
    54  			expected: "TxTimeout (123456)",
    55  		},
    56  	} {
    57  		tt := tt
    58  		t.Run(tt.msg, func(t *testing.T) {
    59  			assert.Equal(t, tt.expected, tt.f.String())
    60  		})
    61  	}
    62  }