(t *testing.T)
| 15 | } |
| 16 | |
| 17 | func TestBuffering(t *testing.T) { |
| 18 | var ( |
| 19 | h Handler |
| 20 | zr zeroReader |
| 21 | ) |
| 22 | type args struct { |
| 23 | body io.ReadCloser |
| 24 | limit int64 |
| 25 | } |
| 26 | tests := []struct { |
| 27 | name string |
| 28 | args args |
| 29 | resultCheck func(io.ReadCloser, int64, args) bool |
| 30 | }{ |
| 31 | { |
| 32 | name: "0 limit, body is returned as is", |
| 33 | args: args{ |
| 34 | body: io.NopCloser(&zr), |
| 35 | limit: 0, |
| 36 | }, |
| 37 | resultCheck: func(res io.ReadCloser, read int64, args args) bool { |
| 38 | return res == args.body && read == args.limit && read == 0 |
| 39 | }, |
| 40 | }, |
| 41 | { |
| 42 | name: "negative limit, body is read completely", |
| 43 | args: args{ |
| 44 | body: io.NopCloser(io.LimitReader(&zr, 100)), |
| 45 | limit: -1, |
| 46 | }, |
| 47 | resultCheck: func(res io.ReadCloser, read int64, args args) bool { |
| 48 | brc, ok := res.(bodyReadCloser) |
| 49 | return ok && brc.body == nil && brc.buf.Len() == 100 && read == 100 |
| 50 | }, |
| 51 | }, |
| 52 | { |
| 53 | name: "positive limit, body is read partially", |
| 54 | args: args{ |
| 55 | body: io.NopCloser(io.LimitReader(&zr, 100)), |
| 56 | limit: 50, |
| 57 | }, |
| 58 | resultCheck: func(res io.ReadCloser, read int64, args args) bool { |
| 59 | brc, ok := res.(bodyReadCloser) |
| 60 | return ok && brc.body != nil && brc.buf.Len() == 50 && read == 50 |
| 61 | }, |
| 62 | }, |
| 63 | { |
| 64 | name: "positive limit, body is read completely", |
| 65 | args: args{ |
| 66 | body: io.NopCloser(io.LimitReader(&zr, 100)), |
| 67 | limit: 101, |
| 68 | }, |
| 69 | resultCheck: func(res io.ReadCloser, read int64, args args) bool { |
| 70 | brc, ok := res.(bodyReadCloser) |
| 71 | return ok && brc.body == nil && brc.buf.Len() == 100 && read == 100 |
| 72 | }, |
| 73 | }, |
| 74 | } |
nothing calls this directly
no test coverage detected