ref: 3b2b07510bc45fbec6b7b20a0a7e27be6b62eefc
pkg/go-git-http/pktparser_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 |
package githttp import ( "encoding/hex" "errors" "reflect" "testing" ) func TestParsePktLen(t *testing.T) { tests := []struct { in string wantLen int wantErr error }{ // Valid pkt-len. {"00a5", 165, nil}, {"01a5", 421, nil}, {"0032", 50, nil}, {"000b", 11, nil}, {"000B", 11, nil}, // Valud flush-pkt. {"0000", 0, nil}, {"0001", 0, errors.New("invalid pkt-len: 1")}, {"0003", 0, errors.New("invalid pkt-len: 3")}, {"abyz", 0, hex.InvalidByteError('y')}, {"-<%^", 0, hex.InvalidByteError('-')}, // Maximum length. {"fff4", 65524, nil}, {"fff5", 0, errors.New("invalid pkt-len: 65525")}, {"ffff", 0, errors.New("invalid pkt-len: 65535")}, } for _, tt := range tests { gotLen, gotErr := parsePktLen([]byte(tt.in)) if gotLen != tt.wantLen || !reflect.DeepEqual(gotErr, tt.wantErr) { t.Errorf("test %q:\n got: %#v, %#v\nwant: %#v, %#v\n", tt.in, gotLen, gotErr, tt.wantLen, tt.wantErr) } } } |