(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func TestRealDecoder_getArrayLength(t *testing.T) { |
| 13 | tests := []struct { |
| 14 | name string |
| 15 | input []byte |
| 16 | wantLen int |
| 17 | wantErr error |
| 18 | }{ |
| 19 | { |
| 20 | name: "null array (-1)", |
| 21 | input: []byte{0xFF, 0xFF, 0xFF, 0xFF}, |
| 22 | wantLen: -1, |
| 23 | wantErr: nil, |
| 24 | }, |
| 25 | { |
| 26 | name: "valid array length 64", |
| 27 | input: makeInput(64), |
| 28 | wantLen: 64, |
| 29 | wantErr: nil, |
| 30 | }, |
| 31 | { |
| 32 | name: "valid array up to MaxResponseSize", |
| 33 | input: makeInput(int(MaxResponseSize)), |
| 34 | wantLen: int(MaxResponseSize), |
| 35 | wantErr: nil, |
| 36 | }, |
| 37 | { |
| 38 | name: "insufficient data", |
| 39 | input: []byte{0x00, 0x00, 0x00}, // fewer than 4 bytes |
| 40 | wantLen: -1, |
| 41 | wantErr: ErrInsufficientData, |
| 42 | }, |
| 43 | { |
| 44 | name: "length exceeds remaining", |
| 45 | input: []byte{0x00, 0x00, 0x00, 0x05, 0x00}, // length of 5, but only 1 byte remains |
| 46 | wantLen: -1, |
| 47 | wantErr: ErrInsufficientData, |
| 48 | }, |
| 49 | { |
| 50 | name: "length exceeds MaxResponseSize", |
| 51 | input: makeInput(int(MaxResponseSize + 1)), |
| 52 | wantLen: -1, |
| 53 | wantErr: errInvalidArrayLength, |
| 54 | }, |
| 55 | { |
| 56 | name: "negative length other than null array", |
| 57 | input: []byte{0x80, 0x00, 0x00, 0x00}, |
| 58 | wantLen: -1, |
| 59 | wantErr: errInvalidArrayLength, |
| 60 | }, |
| 61 | } |
| 62 | |
| 63 | for _, tt := range tests { |
| 64 | t.Run(tt.name, func(t *testing.T) { |
| 65 | rd := &realDecoder{ |
| 66 | raw: tt.input, |
| 67 | } |
| 68 | gotLen, gotErr := rd.getArrayLength() |
| 69 | if gotLen != tt.wantLen { |
nothing calls this directly
no test coverage detected