X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/blobdiff_plain/8fa166777cbcd92e871e937d9557f0f1a732c04d..d9bc63a10d0978d9a5222cf7be74044e55f409b7:/hotline/transaction_test.go diff --git a/hotline/transaction_test.go b/hotline/transaction_test.go index 820b08c..e7b535d 100644 --- a/hotline/transaction_test.go +++ b/hotline/transaction_test.go @@ -6,111 +6,6 @@ import ( "testing" ) -func TestReadFields(t *testing.T) { - type args struct { - paramCount []byte - buf []byte - } - tests := []struct { - name string - args args - want []Field - wantErr bool - }{ - { - name: "valid field data", - args: args{ - paramCount: []byte{0x00, 0x02}, - buf: []byte{ - 0x00, 0x65, // ID: FieldData - 0x00, 0x04, // Size: 2 bytes - 0x01, 0x02, 0x03, 0x04, // Data - 0x00, 0x66, // ID: FieldUserName - 0x00, 0x02, // Size: 2 bytes - 0x00, 0x01, // Data - }, - }, - want: []Field{ - { - ID: [2]byte{0x00, 0x65}, - FieldSize: [2]byte{0x00, 0x04}, - Data: []byte{0x01, 0x02, 0x03, 0x04}, - }, - { - ID: [2]byte{0x00, 0x66}, - FieldSize: [2]byte{0x00, 0x02}, - Data: []byte{0x00, 0x01}, - }, - }, - wantErr: false, - }, - { - name: "empty bytes", - args: args{ - paramCount: []byte{0x00, 0x00}, - buf: []byte{}, - }, - want: []Field(nil), - wantErr: false, - }, - { - name: "when field size does not match data length", - args: args{ - paramCount: []byte{0x00, 0x01}, - buf: []byte{ - 0x00, 0x65, // ID: FieldData - 0x00, 0x04, // Size: 4 bytes - 0x01, 0x02, 0x03, // Data - }, - }, - want: []Field{}, - wantErr: true, - }, - { - name: "when field size of second field does not match data length", - args: args{ - paramCount: []byte{0x00, 0x01}, - buf: []byte{ - 0x00, 0x65, // ID: FieldData - 0x00, 0x02, // Size: 2 bytes - 0x01, 0x02, // Data - 0x00, 0x65, // ID: FieldData - 0x00, 0x04, // Size: 4 bytes - 0x01, 0x02, 0x03, // Data - }, - }, - want: []Field{}, - wantErr: true, - }, - { - name: "when field data has extra bytes", - args: args{ - paramCount: []byte{0x00, 0x01}, - buf: []byte{ - 0x00, 0x65, // ID: FieldData - 0x00, 0x02, // Size: 2 bytes - 0x01, 0x02, 0x03, // Data - }, - }, - want: []Field{}, - wantErr: true, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got, err := ReadFields(tt.args.paramCount, tt.args.buf) - if (err != nil) != tt.wantErr { - t.Errorf("ReadFields() error = %v, wantErr %v", err, tt.wantErr) - return - } - - if !assert.Equal(t, tt.want, got) { - t.Errorf("ReadFields() got = %v, want %v", got, tt.want) - } - }) - } -} - func Test_transactionScanner(t *testing.T) { type args struct { data []byte @@ -462,7 +357,7 @@ func TestTransaction_Write(t1 *testing.T) { ParamCount: [2]byte{0, 1}, Fields: []Field{ { - ID: FieldData, + Type: FieldData, FieldSize: [2]byte{0, 3}, Data: []byte("hai"), },