mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-12-02 17:13:33 +01:00
22 lines
457 B
Go
22 lines
457 B
Go
package server
|
|
|
|
import (
|
|
"errors"
|
|
"io"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestTruncatedBody(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
body string
|
|
expected int64
|
|
truncated bool
|
|
}{{"abc", 4, true}, {"abc", 3, false}, {"abcd", 3, false}} {
|
|
_, e := io.ReadAll(checkedBody(io.NopCloser(strings.NewReader(tc.body)), tc.expected))
|
|
if errors.Is(e, io.ErrUnexpectedEOF) != tc.truncated {
|
|
t.Fatalf("expected=%d got=%v", tc.expected, e)
|
|
}
|
|
}
|
|
}
|