Beispiel #1
0
func TestWriteByteFailed(t *testing.T) {
	buf := &bytes.Buffer{}
	writer := io.MultiWriter(testwriter.Limited(2), buf)
	assert.NoError(t, writeByte(writer, 'a'), "WriteByte failed")
	assert.NoError(t, writeByte(writer, 'b'), "WriteByte failed")
	assert.Error(t, writeByte(writer, 'c'), "WriteByte should fail due to lack of space")
	assert.Equal(t, []byte("ab"), buf.Bytes(), "Written bytes mismatch")
}
Beispiel #2
0
func TestWriteStructErr(t *testing.T) {
	writer := testwriter.Limited(10)
	err := WriteStruct(writer, structTest.s)
	if assert.Error(t, err, "WriteStruct should fail") {
		// Apache Thrift just prepends the error message, and doesn't give us access
		// to the underlying error, so we can't check the underlying error exactly.
		assert.Contains(t, err.Error(), testwriter.ErrOutOfSpace.Error(), "Underlying error missing")
	}
}