mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 15:16:51 +08:00
base: improve coverage
This commit is contained in:
@@ -3,11 +3,25 @@ package base
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
type limitedBuffer struct {
|
||||
cap int
|
||||
n int
|
||||
}
|
||||
|
||||
func (b *limitedBuffer) Write(p []byte) (int, error) {
|
||||
b.n += len(p)
|
||||
if b.n > b.cap {
|
||||
return 0, fmt.Errorf("capacity reached")
|
||||
}
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
var casesBody = []struct {
|
||||
name string
|
||||
h Header
|
||||
@@ -90,3 +104,9 @@ func TestBodyReadErrors(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestBodyWriteErrors(t *testing.T) {
|
||||
bw := bufio.NewWriterSize(&limitedBuffer{cap: 3}, 1)
|
||||
err := body([]byte("1234")).write(bw)
|
||||
require.Equal(t, "capacity reached", err.Error())
|
||||
}
|
||||
|
Reference in New Issue
Block a user