func TestReadErrorResponseWithSingleException(t *testing.T) { buf := new(bytes.Buffer) bw := rw.NewWriter(buf) bw.WriteByte(byte(1)) // indicates continue of exception class/msg array bw.WriteStrings("org.foo.BlargException", "wibble wibble!!") bw.WriteByte(byte(0)) // indicates end of exception class/msg array bw.WriteBytes([]byte("this is a stacktrace simulator\nEOL")) var serverExc error serverExc = obinary.ReadErrorResponse(rw.NewReader(buf)) e, ok := serverExc.(orient.OServerException) if !ok { t.Fatal("wrong exception type") } equals(t, 1, len(e.Exceptions)) equals(t, "org.foo.BlargException", e.Exceptions[0].ExcClass()) equals(t, "wibble wibble!!", e.Exceptions[0].ExcMessage()) }
func TestReadErrorResponseWithMultipleExceptions(t *testing.T) { buf := new(bytes.Buffer) bw := rw.NewWriter(buf) bw.WriteByte(byte(1)) // indicates more exceptions to come bw.WriteStrings("org.foo.BlargException", "Too many blorgles!!") bw.WriteByte(byte(1)) // indicates more exceptions to come bw.WriteStrings("org.foo.FeebleException", "Not enough juice") bw.WriteByte(byte(1)) // indicates more exceptions to come bw.WriteStrings("org.foo.WobbleException", "Orbital decay") bw.WriteByte(byte(0)) // indicates end of exceptions bw.WriteBytes([]byte("this is a stacktrace simulator\nEOL")) serverExc := obinary.ReadErrorResponse(rw.NewReader(buf)) e, ok := serverExc.(orient.OServerException) if !ok { t.Fatal("wrong exception type") } equals(t, "org.foo.BlargException", e.Exceptions[0].ExcClass()) equals(t, "Not enough juice", e.Exceptions[1].ExcMessage()) equals(t, "org.foo.WobbleException", e.Exceptions[2].ExcClass()) equals(t, "Orbital decay", e.Exceptions[2].ExcMessage()) }