blob: 71f5e2c7e79e647e78504dd7c5aa02aa45d17d52 [file] [log] [blame]
Jens Geyer527b6d92014-11-30 15:07:18 +01001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20package thrift
21
22import (
23 "errors"
24 "testing"
25)
26
27func TestPrependError(t *testing.T) {
28 err := NewTApplicationException(INTERNAL_ERROR, "original error")
29 err2, ok := PrependError("Prepend: ", err).(TApplicationException)
30 if !ok {
31 t.Fatal("Couldn't cast error TApplicationException")
32 }
33 if err2.Error() != "Prepend: original error" {
34 t.Fatal("Unexpected error string")
35 }
36 if err2.TypeId() != INTERNAL_ERROR {
37 t.Fatal("Unexpected type error")
38 }
39
40 err3 := NewTProtocolExceptionWithType(INVALID_DATA, errors.New("original error"))
41 err4, ok := PrependError("Prepend: ", err3).(TProtocolException)
42 if !ok {
43 t.Fatal("Couldn't cast error TProtocolException")
44 }
45 if err4.Error() != "Prepend: original error" {
46 t.Fatal("Unexpected error string")
47 }
48 if err4.TypeId() != INVALID_DATA {
49 t.Fatal("Unexpected type error")
50 }
51
52 err5 := NewTTransportException(TIMED_OUT, "original error")
53 err6, ok := PrependError("Prepend: ", err5).(TTransportException)
54 if !ok {
55 t.Fatal("Couldn't cast error TTransportException")
56 }
57 if err6.Error() != "Prepend: original error" {
58 t.Fatal("Unexpected error string")
59 }
60 if err6.TypeId() != TIMED_OUT {
61 t.Fatal("Unexpected type error")
62 }
63
64 err7 := errors.New("original error")
65 err8 := PrependError("Prepend: ", err7)
66 if err8.Error() != "Prepend: original error" {
67 t.Fatal("Unexpected error string")
68 }
69}