Combine stream fuzz tests
@@ -32,10 +32,17 @@ func FuzzSendAndReceive(f *testing.F) {
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()
+ 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()
r, w := io.Pipe()
SendStream(ctx, r, ws)
@@ -54,18 +61,9 @@ func FuzzSendAndReceive(f *testing.F) {
if !bytes.Equal(expected, actual) {
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()
or := chainStreams(ctx, chainStreams(ctx, chainStreams(ctx, r)))
@@ -83,19 +81,9 @@ func FuzzSendAndReceiveChain(f *testing.F) {
if !bytes.Equal(expected, actual) {
t.Fatalf("received bytes are not equal\n\tactual: %v\n\texpected:%v", actual, expected)
}
- })
}
-func FuzzWriter(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 runWriterFuzz(ctx context.Context, t *testing.T, expected []byte) {
rs, ws := pipeStream()
wc := WriteByteStream(ctx, ws)
or := ReceiveStream(ctx, rs)
@@ -113,7 +101,6 @@ func FuzzWriter(f *testing.F) {
if !bytes.Equal(expected, actual) {
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 {
