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
|
package ws
import (
"bytes"
"fmt"
"io/ioutil"
"testing"
)
func TestWriteHeader(t *testing.T) {
for i, test := range RWTestCases {
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) {
buf := &bytes.Buffer{}
err := WriteHeader(buf, test.Header)
if test.Err && err == nil {
t.Errorf("expected error, got nil")
}
if !test.Err && err != nil {
t.Errorf("unexpected error: %s", err)
}
if test.Err {
return
}
if bts := buf.Bytes(); !bytes.Equal(bts, test.Data) {
t.Errorf("WriteHeader()\nwrote:\n\t%08b\nwant:\n\t%08b", bts, test.Data)
}
})
}
}
func BenchmarkWriteHeader(b *testing.B) {
for _, bench := range RWBenchCases {
b.Run(bench.label, func(b *testing.B) {
for i := 0; i < b.N; i++ {
if err := WriteHeader(ioutil.Discard, bench.header); err != nil {
b.Fatal(err)
}
}
})
}
}
|