rpc: chunk JSON parts of communication + refactoring
JSONDecoder was buffering more of connection data than just the JSON. => Unchunker didn't bother and just started unchunking. While chaining JSONDecoder.Buffered() and the connection using ChainedReader works, it's still not a clean architecture. => Every JSON message is now wrapped in a chunked stream (chunked and unchunked) => no special-cases => Keep ChainedReader, might be useful later on...
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package rpc
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/zrepl/zrepl/util"
|
||||
"io"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestByteStreamRPCDecodeJSONError(t *testing.T) {
|
||||
|
||||
r := strings.NewReader("{'a':'aber'}")
|
||||
|
||||
var chunked bytes.Buffer
|
||||
ch := util.NewChunker(r)
|
||||
io.Copy(&chunked, &ch)
|
||||
|
||||
type SampleType struct {
|
||||
A uint
|
||||
}
|
||||
var s SampleType
|
||||
err := readChunkedJSON(&chunked, &s)
|
||||
assert.NotNil(t, err)
|
||||
|
||||
_, ok := err.(ByteStreamRPCDecodeJSONError)
|
||||
if !ok {
|
||||
t.Errorf("expected ByteStreamRPCDecodeJSONError, got %t\n", err)
|
||||
t.Errorf("%s\n", err)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user