Combine stream fuzz tests
Signed-off-by: Derek McGowan <derek@mcg.dev>
This commit is contained in:
parent
0762a3a759
commit
8304a61b53
@ -32,10 +32,17 @@ func FuzzSendAndReceive(f *testing.F) {
|
|||||||
f.Add(bytes.Repeat([]byte{0}, windowSize+1))
|
f.Add(bytes.Repeat([]byte{0}, windowSize+1))
|
||||||
f.Add([]byte("hello"))
|
f.Add([]byte("hello"))
|
||||||
f.Add(bytes.Repeat([]byte("hello"), windowSize+1))
|
f.Add(bytes.Repeat([]byte("hello"), windowSize+1))
|
||||||
f.Fuzz(func(t *testing.T, expected []byte) {
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
f.Fuzz(func(t *testing.T, expected []byte) {
|
||||||
|
runSendAndReceiveFuzz(ctx, t, expected)
|
||||||
|
runSendAndReceiveChainFuzz(ctx, t, expected)
|
||||||
|
runWriterFuzz(ctx, t, expected)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func runSendAndReceiveFuzz(ctx context.Context, t *testing.T, expected []byte) {
|
||||||
rs, ws := pipeStream()
|
rs, ws := pipeStream()
|
||||||
r, w := io.Pipe()
|
r, w := io.Pipe()
|
||||||
SendStream(ctx, r, ws)
|
SendStream(ctx, r, ws)
|
||||||
@ -54,18 +61,9 @@ func FuzzSendAndReceive(f *testing.F) {
|
|||||||
if !bytes.Equal(expected, actual) {
|
if !bytes.Equal(expected, actual) {
|
||||||
t.Fatalf("received bytes are not equal\n\tactual: %v\n\texpected:%v", actual, expected)
|
t.Fatalf("received bytes are not equal\n\tactual: %v\n\texpected:%v", actual, expected)
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
func FuzzSendAndReceiveChain(f *testing.F) {
|
|
||||||
f.Add([]byte{})
|
|
||||||
f.Add([]byte{0})
|
|
||||||
f.Add(bytes.Repeat([]byte{0}, windowSize+1))
|
|
||||||
f.Add([]byte("hello"))
|
|
||||||
f.Add(bytes.Repeat([]byte("hello"), windowSize+1))
|
|
||||||
f.Fuzz(func(t *testing.T, expected []byte) {
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
|
func runSendAndReceiveChainFuzz(ctx context.Context, t *testing.T, expected []byte) {
|
||||||
r, w := io.Pipe()
|
r, w := io.Pipe()
|
||||||
|
|
||||||
or := chainStreams(ctx, chainStreams(ctx, chainStreams(ctx, r)))
|
or := chainStreams(ctx, chainStreams(ctx, chainStreams(ctx, r)))
|
||||||
@ -83,19 +81,9 @@ func FuzzSendAndReceiveChain(f *testing.F) {
|
|||||||
if !bytes.Equal(expected, actual) {
|
if !bytes.Equal(expected, actual) {
|
||||||
t.Fatalf("received bytes are not equal\n\tactual: %v\n\texpected:%v", actual, expected)
|
t.Fatalf("received bytes are not equal\n\tactual: %v\n\texpected:%v", actual, expected)
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func FuzzWriter(f *testing.F) {
|
func runWriterFuzz(ctx context.Context, t *testing.T, expected []byte) {
|
||||||
f.Add([]byte{})
|
|
||||||
f.Add([]byte{0})
|
|
||||||
f.Add(bytes.Repeat([]byte{0}, windowSize+1))
|
|
||||||
f.Add([]byte("hello"))
|
|
||||||
f.Add(bytes.Repeat([]byte("hello"), windowSize+1))
|
|
||||||
f.Fuzz(func(t *testing.T, expected []byte) {
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
rs, ws := pipeStream()
|
rs, ws := pipeStream()
|
||||||
wc := WriteByteStream(ctx, ws)
|
wc := WriteByteStream(ctx, ws)
|
||||||
or := ReceiveStream(ctx, rs)
|
or := ReceiveStream(ctx, rs)
|
||||||
@ -113,7 +101,6 @@ func FuzzWriter(f *testing.F) {
|
|||||||
if !bytes.Equal(expected, actual) {
|
if !bytes.Equal(expected, actual) {
|
||||||
t.Fatalf("received bytes are not equal\n\tactual: %v\n\texpected:%v", actual, expected)
|
t.Fatalf("received bytes are not equal\n\tactual: %v\n\texpected:%v", actual, expected)
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func chainStreams(ctx context.Context, r io.Reader) io.Reader {
|
func chainStreams(ctx context.Context, r io.Reader) io.Reader {
|
||||||
|
Loading…
Reference in New Issue
Block a user