Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 1 | /* |
| 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 | |
| 20 | package common |
| 21 | |
| 22 | import ( |
John Boiles | 5785279 | 2018-01-05 14:37:05 -0800 | [diff] [blame] | 23 | "context" |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 24 | "errors" |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 25 | "reflect" |
D. Can Celasun | 4f77ab8 | 2017-09-21 15:21:00 +0200 | [diff] [blame] | 26 | "sync" |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 27 | "testing" |
claudemiro | f8ca055 | 2016-01-10 23:31:30 -0200 | [diff] [blame] | 28 | |
| 29 | "github.com/golang/mock/gomock" |
Yuxuan 'fishy' Wang | b71f11e | 2021-03-22 15:01:00 -0700 | [diff] [blame] | 30 | |
| 31 | "github.com/apache/thrift/lib/go/thrift" |
| 32 | "github.com/apache/thrift/test/go/src/gen/thrifttest" |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 33 | ) |
| 34 | |
| 35 | type test_unit struct { |
| 36 | host string |
| 37 | port int64 |
| 38 | domain_socket string |
| 39 | transport string |
| 40 | protocol string |
| 41 | ssl bool |
| 42 | } |
| 43 | |
| 44 | var units = []test_unit{ |
Nobuaki Sukegawa | fd02a30 | 2016-08-16 14:06:48 +0900 | [diff] [blame] | 45 | {"127.0.0.1", 9095, "", "", "binary", false}, |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 46 | {"127.0.0.1", 9091, "", "", "compact", false}, |
| 47 | {"127.0.0.1", 9092, "", "", "binary", true}, |
| 48 | {"127.0.0.1", 9093, "", "", "compact", true}, |
| 49 | } |
| 50 | |
| 51 | func TestAllConnection(t *testing.T) { |
| 52 | certPath = "../../../keys" |
D. Can Celasun | 4f77ab8 | 2017-09-21 15:21:00 +0200 | [diff] [blame] | 53 | wg := &sync.WaitGroup{} |
| 54 | wg.Add(len(units)) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 55 | for _, unit := range units { |
D. Can Celasun | 4f77ab8 | 2017-09-21 15:21:00 +0200 | [diff] [blame] | 56 | go func(u test_unit) { |
| 57 | defer wg.Done() |
| 58 | doUnit(t, &u) |
| 59 | }(unit) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 60 | } |
D. Can Celasun | 4f77ab8 | 2017-09-21 15:21:00 +0200 | [diff] [blame] | 61 | wg.Wait() |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | func doUnit(t *testing.T, unit *test_unit) { |
| 65 | ctrl := gomock.NewController(t) |
| 66 | defer ctrl.Finish() |
| 67 | handler := NewMockThriftTest(ctrl) |
claudemiro | f8ca055 | 2016-01-10 23:31:30 -0200 | [diff] [blame] | 68 | |
| 69 | processor, serverTransport, transportFactory, protocolFactory, err := GetServerParams(unit.host, unit.port, unit.domain_socket, unit.transport, unit.protocol, unit.ssl, "../../../keys", handler) |
| 70 | |
| 71 | server := thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory) |
| 72 | if err = server.Listen(); err != nil { |
D. Can Celasun | 4f77ab8 | 2017-09-21 15:21:00 +0200 | [diff] [blame] | 73 | t.Errorf("Unable to start server: %v", err) |
| 74 | return |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 75 | } |
John Sirois | f7d4979 | 2016-02-03 17:12:19 -0700 | [diff] [blame] | 76 | go server.AcceptLoop() |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 77 | defer server.Stop() |
D. Can Celasun | 4f77ab8 | 2017-09-21 15:21:00 +0200 | [diff] [blame] | 78 | client, trans, err := StartClient(unit.host, unit.port, unit.domain_socket, unit.transport, unit.protocol, unit.ssl) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 79 | if err != nil { |
D. Can Celasun | 4f77ab8 | 2017-09-21 15:21:00 +0200 | [diff] [blame] | 80 | t.Errorf("Unable to start client: %v", err) |
| 81 | return |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 82 | } |
D. Can Celasun | 4f77ab8 | 2017-09-21 15:21:00 +0200 | [diff] [blame] | 83 | defer trans.Close() |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 84 | callEverythingWithMock(t, client, handler) |
| 85 | } |
| 86 | |
| 87 | var rmapmap = map[int32]map[int32]int32{ |
Yuxuan 'fishy' Wang | b71f11e | 2021-03-22 15:01:00 -0700 | [diff] [blame] | 88 | -4: {-4: -4, -3: -3, -2: -2, -1: -1}, |
| 89 | 4: {4: 4, 3: 3, 2: 2, 1: 1}, |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | var xxs = &thrifttest.Xtruct{ |
| 93 | StringThing: "Hello2", |
| 94 | ByteThing: 42, |
| 95 | I32Thing: 4242, |
| 96 | I64Thing: 424242, |
| 97 | } |
| 98 | |
| 99 | var xcept = &thrifttest.Xception{ErrorCode: 1001, Message: "some"} |
John Boiles | 5785279 | 2018-01-05 14:37:05 -0800 | [diff] [blame] | 100 | var defaultCtx = context.Background() |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 101 | |
| 102 | func callEverythingWithMock(t *testing.T, client *thrifttest.ThriftTestClient, handler *MockThriftTest) { |
| 103 | gomock.InOrder( |
taozle | c0d384a | 2017-07-17 18:40:42 +0200 | [diff] [blame] | 104 | handler.EXPECT().TestVoid(gomock.Any()), |
| 105 | handler.EXPECT().TestString(gomock.Any(), "thing").Return("thing", nil), |
| 106 | handler.EXPECT().TestBool(gomock.Any(), true).Return(true, nil), |
| 107 | handler.EXPECT().TestBool(gomock.Any(), false).Return(false, nil), |
| 108 | handler.EXPECT().TestByte(gomock.Any(), int8(42)).Return(int8(42), nil), |
| 109 | handler.EXPECT().TestI32(gomock.Any(), int32(4242)).Return(int32(4242), nil), |
| 110 | handler.EXPECT().TestI64(gomock.Any(), int64(424242)).Return(int64(424242), nil), |
Jens Geyer | 8bcfdd9 | 2014-12-14 03:14:26 +0100 | [diff] [blame] | 111 | // TODO: add TestBinary() |
taozle | c0d384a | 2017-07-17 18:40:42 +0200 | [diff] [blame] | 112 | handler.EXPECT().TestDouble(gomock.Any(), float64(42.42)).Return(float64(42.42), nil), |
| 113 | handler.EXPECT().TestStruct(gomock.Any(), &thrifttest.Xtruct{StringThing: "thing", ByteThing: 42, I32Thing: 4242, I64Thing: 424242}).Return(&thrifttest.Xtruct{StringThing: "thing", ByteThing: 42, I32Thing: 4242, I64Thing: 424242}, nil), |
| 114 | handler.EXPECT().TestNest(gomock.Any(), &thrifttest.Xtruct2{StructThing: &thrifttest.Xtruct{StringThing: "thing", ByteThing: 42, I32Thing: 4242, I64Thing: 424242}}).Return(&thrifttest.Xtruct2{StructThing: &thrifttest.Xtruct{StringThing: "thing", ByteThing: 42, I32Thing: 4242, I64Thing: 424242}}, nil), |
| 115 | handler.EXPECT().TestMap(gomock.Any(), map[int32]int32{1: 2, 3: 4, 5: 42}).Return(map[int32]int32{1: 2, 3: 4, 5: 42}, nil), |
| 116 | handler.EXPECT().TestStringMap(gomock.Any(), map[string]string{"a": "2", "b": "blah", "some": "thing"}).Return(map[string]string{"a": "2", "b": "blah", "some": "thing"}, nil), |
| 117 | handler.EXPECT().TestSet(gomock.Any(), []int32{1, 2, 42}).Return([]int32{1, 2, 42}, nil), |
| 118 | handler.EXPECT().TestList(gomock.Any(), []int32{1, 2, 42}).Return([]int32{1, 2, 42}, nil), |
| 119 | handler.EXPECT().TestEnum(gomock.Any(), thrifttest.Numberz_TWO).Return(thrifttest.Numberz_TWO, nil), |
| 120 | handler.EXPECT().TestTypedef(gomock.Any(), thrifttest.UserId(42)).Return(thrifttest.UserId(42), nil), |
| 121 | handler.EXPECT().TestMapMap(gomock.Any(), int32(42)).Return(rmapmap, nil), |
Nobuaki Sukegawa | 2fab3de | 2015-08-16 15:42:58 +0900 | [diff] [blame] | 122 | // TODO: not testing insanity |
taozle | c0d384a | 2017-07-17 18:40:42 +0200 | [diff] [blame] | 123 | handler.EXPECT().TestMulti(gomock.Any(), int8(42), int32(4242), int64(424242), map[int16]string{1: "blah", 2: "thing"}, thrifttest.Numberz_EIGHT, thrifttest.UserId(24)).Return(xxs, nil), |
| 124 | handler.EXPECT().TestException(gomock.Any(), "some").Return(xcept), |
| 125 | handler.EXPECT().TestException(gomock.Any(), "TException").Return(errors.New("Just random exception")), |
| 126 | handler.EXPECT().TestMultiException(gomock.Any(), "Xception", "ignoreme").Return(nil, &thrifttest.Xception{ErrorCode: 1001, Message: "This is an Xception"}), |
| 127 | handler.EXPECT().TestMultiException(gomock.Any(), "Xception2", "ignoreme").Return(nil, &thrifttest.Xception2{ErrorCode: 2002, StructThing: &thrifttest.Xtruct{StringThing: "This is an Xception2"}}), |
| 128 | handler.EXPECT().TestOneway(gomock.Any(), int32(2)).Return(nil), |
| 129 | handler.EXPECT().TestVoid(gomock.Any()), |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 130 | ) |
| 131 | var err error |
taozle | 5c302e0 | 2017-07-23 15:21:44 +0200 | [diff] [blame] | 132 | if err = client.TestVoid(defaultCtx); err != nil { |
D. Can Celasun | a9efd1a | 2018-03-15 12:52:37 +0100 | [diff] [blame] | 133 | t.Errorf("Unexpected error in TestVoid() call: %s", err) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 134 | } |
| 135 | |
taozle | 5c302e0 | 2017-07-23 15:21:44 +0200 | [diff] [blame] | 136 | thing, err := client.TestString(defaultCtx, "thing") |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 137 | if err != nil { |
D. Can Celasun | a9efd1a | 2018-03-15 12:52:37 +0100 | [diff] [blame] | 138 | t.Errorf("Unexpected error in TestString() call: %s", err) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 139 | } |
| 140 | if thing != "thing" { |
| 141 | t.Errorf("Unexpected TestString() result, expected 'thing' got '%s' ", thing) |
| 142 | } |
| 143 | |
taozle | 5c302e0 | 2017-07-23 15:21:44 +0200 | [diff] [blame] | 144 | bl, err := client.TestBool(defaultCtx, true) |
Nobuaki Sukegawa | a649e74 | 2015-09-21 13:53:25 +0900 | [diff] [blame] | 145 | if err != nil { |
D. Can Celasun | a9efd1a | 2018-03-15 12:52:37 +0100 | [diff] [blame] | 146 | t.Errorf("Unexpected error in TestBool() call: %s", err) |
Nobuaki Sukegawa | a649e74 | 2015-09-21 13:53:25 +0900 | [diff] [blame] | 147 | } |
| 148 | if !bl { |
D. Can Celasun | a9efd1a | 2018-03-15 12:52:37 +0100 | [diff] [blame] | 149 | t.Errorf("Unexpected TestBool() result expected true, got %v ", bl) |
Nobuaki Sukegawa | a649e74 | 2015-09-21 13:53:25 +0900 | [diff] [blame] | 150 | } |
taozle | 5c302e0 | 2017-07-23 15:21:44 +0200 | [diff] [blame] | 151 | bl, err = client.TestBool(defaultCtx, false) |
Nobuaki Sukegawa | a649e74 | 2015-09-21 13:53:25 +0900 | [diff] [blame] | 152 | if err != nil { |
D. Can Celasun | a9efd1a | 2018-03-15 12:52:37 +0100 | [diff] [blame] | 153 | t.Errorf("Unexpected error in TestBool() call: %s", err) |
Nobuaki Sukegawa | a649e74 | 2015-09-21 13:53:25 +0900 | [diff] [blame] | 154 | } |
| 155 | if bl { |
D. Can Celasun | a9efd1a | 2018-03-15 12:52:37 +0100 | [diff] [blame] | 156 | t.Errorf("Unexpected TestBool() result expected false, got %v ", bl) |
Nobuaki Sukegawa | a649e74 | 2015-09-21 13:53:25 +0900 | [diff] [blame] | 157 | } |
| 158 | |
taozle | 5c302e0 | 2017-07-23 15:21:44 +0200 | [diff] [blame] | 159 | b, err := client.TestByte(defaultCtx, 42) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 160 | if err != nil { |
D. Can Celasun | a9efd1a | 2018-03-15 12:52:37 +0100 | [diff] [blame] | 161 | t.Errorf("Unexpected error in TestByte() call: %s", err) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 162 | } |
| 163 | if b != 42 { |
| 164 | t.Errorf("Unexpected TestByte() result expected 42, got %d ", b) |
| 165 | } |
| 166 | |
taozle | 5c302e0 | 2017-07-23 15:21:44 +0200 | [diff] [blame] | 167 | i32, err := client.TestI32(defaultCtx, 4242) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 168 | if err != nil { |
D. Can Celasun | a9efd1a | 2018-03-15 12:52:37 +0100 | [diff] [blame] | 169 | t.Errorf("Unexpected error in TestI32() call: %s", err) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 170 | } |
| 171 | if i32 != 4242 { |
| 172 | t.Errorf("Unexpected TestI32() result expected 4242, got %d ", i32) |
| 173 | } |
| 174 | |
taozle | 5c302e0 | 2017-07-23 15:21:44 +0200 | [diff] [blame] | 175 | i64, err := client.TestI64(defaultCtx, 424242) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 176 | if err != nil { |
D. Can Celasun | a9efd1a | 2018-03-15 12:52:37 +0100 | [diff] [blame] | 177 | t.Errorf("Unexpected error in TestI64() call: %s", err) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 178 | } |
| 179 | if i64 != 424242 { |
| 180 | t.Errorf("Unexpected TestI64() result expected 424242, got %d ", i64) |
| 181 | } |
| 182 | |
taozle | 5c302e0 | 2017-07-23 15:21:44 +0200 | [diff] [blame] | 183 | d, err := client.TestDouble(defaultCtx, 42.42) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 184 | if err != nil { |
D. Can Celasun | a9efd1a | 2018-03-15 12:52:37 +0100 | [diff] [blame] | 185 | t.Errorf("Unexpected error in TestDouble() call: %s", err) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 186 | } |
| 187 | if d != 42.42 { |
| 188 | t.Errorf("Unexpected TestDouble() result expected 42.42, got %f ", d) |
| 189 | } |
| 190 | |
Jens Geyer | 8bcfdd9 | 2014-12-14 03:14:26 +0100 | [diff] [blame] | 191 | // TODO: add TestBinary() call |
claudemiro | f8ca055 | 2016-01-10 23:31:30 -0200 | [diff] [blame] | 192 | |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 193 | xs := thrifttest.NewXtruct() |
| 194 | xs.StringThing = "thing" |
| 195 | xs.ByteThing = 42 |
| 196 | xs.I32Thing = 4242 |
| 197 | xs.I64Thing = 424242 |
taozle | 5c302e0 | 2017-07-23 15:21:44 +0200 | [diff] [blame] | 198 | xsret, err := client.TestStruct(defaultCtx, xs) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 199 | if err != nil { |
D. Can Celasun | a9efd1a | 2018-03-15 12:52:37 +0100 | [diff] [blame] | 200 | t.Errorf("Unexpected error in TestStruct() call: %s", err) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 201 | } |
| 202 | if *xs != *xsret { |
| 203 | t.Errorf("Unexpected TestStruct() result expected %#v, got %#v ", xs, xsret) |
| 204 | } |
| 205 | |
| 206 | x2 := thrifttest.NewXtruct2() |
| 207 | x2.StructThing = xs |
taozle | 5c302e0 | 2017-07-23 15:21:44 +0200 | [diff] [blame] | 208 | x2ret, err := client.TestNest(defaultCtx, x2) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 209 | if err != nil { |
D. Can Celasun | a9efd1a | 2018-03-15 12:52:37 +0100 | [diff] [blame] | 210 | t.Errorf("Unexpected error in TestNest() call: %s", err) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 211 | } |
| 212 | if !reflect.DeepEqual(x2, x2ret) { |
| 213 | t.Errorf("Unexpected TestNest() result expected %#v, got %#v ", x2, x2ret) |
| 214 | } |
| 215 | |
| 216 | m := map[int32]int32{1: 2, 3: 4, 5: 42} |
taozle | 5c302e0 | 2017-07-23 15:21:44 +0200 | [diff] [blame] | 217 | mret, err := client.TestMap(defaultCtx, m) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 218 | if err != nil { |
D. Can Celasun | a9efd1a | 2018-03-15 12:52:37 +0100 | [diff] [blame] | 219 | t.Errorf("Unexpected error in TestMap() call: %s", err) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 220 | } |
| 221 | if !reflect.DeepEqual(m, mret) { |
| 222 | t.Errorf("Unexpected TestMap() result expected %#v, got %#v ", m, mret) |
| 223 | } |
| 224 | |
| 225 | sm := map[string]string{"a": "2", "b": "blah", "some": "thing"} |
taozle | 5c302e0 | 2017-07-23 15:21:44 +0200 | [diff] [blame] | 226 | smret, err := client.TestStringMap(defaultCtx, sm) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 227 | if err != nil { |
D. Can Celasun | a9efd1a | 2018-03-15 12:52:37 +0100 | [diff] [blame] | 228 | t.Errorf("Unexpected error in TestStringMap() call: %s", err) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 229 | } |
| 230 | if !reflect.DeepEqual(sm, smret) { |
| 231 | t.Errorf("Unexpected TestStringMap() result expected %#v, got %#v ", sm, smret) |
| 232 | } |
| 233 | |
D. Can Celasun | 43fb34d | 2017-01-15 10:53:19 +0100 | [diff] [blame] | 234 | s := []int32{1, 2, 42} |
taozle | 5c302e0 | 2017-07-23 15:21:44 +0200 | [diff] [blame] | 235 | sret, err := client.TestSet(defaultCtx, s) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 236 | if err != nil { |
D. Can Celasun | a9efd1a | 2018-03-15 12:52:37 +0100 | [diff] [blame] | 237 | t.Errorf("Unexpected error in TestSet() call: %s", err) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 238 | } |
D. Can Celasun | 43fb34d | 2017-01-15 10:53:19 +0100 | [diff] [blame] | 239 | // Sets can be in any order, but Go slices are ordered, so reflect.DeepEqual won't work. |
| 240 | stemp := map[int32]struct{}{} |
| 241 | for _, val := range s { |
| 242 | stemp[val] = struct{}{} |
| 243 | } |
| 244 | for _, val := range sret { |
| 245 | if _, ok := stemp[val]; !ok { |
| 246 | t.Fatalf("Unexpected TestSet() result expected %#v, got %#v ", s, sret) |
| 247 | } |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | l := []int32{1, 2, 42} |
taozle | 5c302e0 | 2017-07-23 15:21:44 +0200 | [diff] [blame] | 251 | lret, err := client.TestList(defaultCtx, l) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 252 | if err != nil { |
D. Can Celasun | a9efd1a | 2018-03-15 12:52:37 +0100 | [diff] [blame] | 253 | t.Errorf("Unexpected error in TestList() call: %s", err) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 254 | } |
| 255 | if !reflect.DeepEqual(l, lret) { |
D. Can Celasun | 43fb34d | 2017-01-15 10:53:19 +0100 | [diff] [blame] | 256 | t.Errorf("Unexpected TestList() result expected %#v, got %#v ", l, lret) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 257 | } |
| 258 | |
taozle | 5c302e0 | 2017-07-23 15:21:44 +0200 | [diff] [blame] | 259 | eret, err := client.TestEnum(defaultCtx, thrifttest.Numberz_TWO) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 260 | if err != nil { |
D. Can Celasun | a9efd1a | 2018-03-15 12:52:37 +0100 | [diff] [blame] | 261 | t.Errorf("Unexpected error in TestEnum() call: %s", err) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 262 | } |
| 263 | if eret != thrifttest.Numberz_TWO { |
| 264 | t.Errorf("Unexpected TestEnum() result expected %#v, got %#v ", thrifttest.Numberz_TWO, eret) |
| 265 | } |
| 266 | |
taozle | 5c302e0 | 2017-07-23 15:21:44 +0200 | [diff] [blame] | 267 | tret, err := client.TestTypedef(defaultCtx, thrifttest.UserId(42)) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 268 | if err != nil { |
D. Can Celasun | a9efd1a | 2018-03-15 12:52:37 +0100 | [diff] [blame] | 269 | t.Errorf("Unexpected error in TestTypedef() call: %s", err) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 270 | } |
| 271 | if tret != thrifttest.UserId(42) { |
| 272 | t.Errorf("Unexpected TestTypedef() result expected %#v, got %#v ", thrifttest.UserId(42), tret) |
| 273 | } |
| 274 | |
taozle | 5c302e0 | 2017-07-23 15:21:44 +0200 | [diff] [blame] | 275 | mapmap, err := client.TestMapMap(defaultCtx, 42) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 276 | if err != nil { |
D. Can Celasun | a9efd1a | 2018-03-15 12:52:37 +0100 | [diff] [blame] | 277 | t.Errorf("Unexpected error in TestMapmap() call: %s", err) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 278 | } |
| 279 | if !reflect.DeepEqual(mapmap, rmapmap) { |
| 280 | t.Errorf("Unexpected TestMapmap() result expected %#v, got %#v ", rmapmap, mapmap) |
| 281 | } |
| 282 | |
taozle | 5c302e0 | 2017-07-23 15:21:44 +0200 | [diff] [blame] | 283 | xxsret, err := client.TestMulti(defaultCtx, 42, 4242, 424242, map[int16]string{1: "blah", 2: "thing"}, thrifttest.Numberz_EIGHT, thrifttest.UserId(24)) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 284 | if err != nil { |
D. Can Celasun | a9efd1a | 2018-03-15 12:52:37 +0100 | [diff] [blame] | 285 | t.Errorf("Unexpected error in TestMulti() call: %s", err) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 286 | } |
| 287 | if !reflect.DeepEqual(xxs, xxsret) { |
| 288 | t.Errorf("Unexpected TestMulti() result expected %#v, got %#v ", xxs, xxsret) |
| 289 | } |
| 290 | |
taozle | 5c302e0 | 2017-07-23 15:21:44 +0200 | [diff] [blame] | 291 | err = client.TestException(defaultCtx, "some") |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 292 | if err == nil { |
| 293 | t.Errorf("Expecting exception in TestException() call") |
| 294 | } |
| 295 | if !reflect.DeepEqual(err, xcept) { |
| 296 | t.Errorf("Unexpected TestException() result expected %#v, got %#v ", xcept, err) |
| 297 | } |
| 298 | |
| 299 | // TODO: connection is being closed on this |
taozle | 5c302e0 | 2017-07-23 15:21:44 +0200 | [diff] [blame] | 300 | err = client.TestException(defaultCtx, "TException") |
D. Can Celasun | 4f77ab8 | 2017-09-21 15:21:00 +0200 | [diff] [blame] | 301 | if err == nil { |
| 302 | t.Error("expected exception got nil") |
| 303 | } else if tex, ok := err.(thrift.TApplicationException); !ok { |
| 304 | t.Errorf("Unexpected TestException() result expected ApplicationError, got %T ", err) |
| 305 | } else if tex.TypeId() != thrift.INTERNAL_ERROR { |
| 306 | t.Errorf("expected internal_error got %v", tex.TypeId()) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 307 | } |
| 308 | |
taozle | 5c302e0 | 2017-07-23 15:21:44 +0200 | [diff] [blame] | 309 | ign, err := client.TestMultiException(defaultCtx, "Xception", "ignoreme") |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 310 | if ign != nil || err == nil { |
| 311 | t.Errorf("Expecting exception in TestMultiException() call") |
| 312 | } |
| 313 | if !reflect.DeepEqual(err, &thrifttest.Xception{ErrorCode: 1001, Message: "This is an Xception"}) { |
| 314 | t.Errorf("Unexpected TestMultiException() %#v ", err) |
| 315 | } |
| 316 | |
taozle | 5c302e0 | 2017-07-23 15:21:44 +0200 | [diff] [blame] | 317 | ign, err = client.TestMultiException(defaultCtx, "Xception2", "ignoreme") |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 318 | if ign != nil || err == nil { |
| 319 | t.Errorf("Expecting exception in TestMultiException() call") |
| 320 | } |
| 321 | expecting := &thrifttest.Xception2{ErrorCode: 2002, StructThing: &thrifttest.Xtruct{StringThing: "This is an Xception2"}} |
| 322 | |
| 323 | if !reflect.DeepEqual(err, expecting) { |
| 324 | t.Errorf("Unexpected TestMultiException() %#v ", err) |
| 325 | } |
| 326 | |
taozle | 5c302e0 | 2017-07-23 15:21:44 +0200 | [diff] [blame] | 327 | err = client.TestOneway(defaultCtx, 2) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 328 | if err != nil { |
D. Can Celasun | a9efd1a | 2018-03-15 12:52:37 +0100 | [diff] [blame] | 329 | t.Errorf("Unexpected error in TestOneway() call: %s", err) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | //Make sure the connection still alive |
taozle | 5c302e0 | 2017-07-23 15:21:44 +0200 | [diff] [blame] | 333 | if err = client.TestVoid(defaultCtx); err != nil { |
D. Can Celasun | a9efd1a | 2018-03-15 12:52:37 +0100 | [diff] [blame] | 334 | t.Errorf("Unexpected error in TestVoid() call: %s", err) |
Jens Geyer | f459868 | 2014-05-08 23:18:44 +0200 | [diff] [blame] | 335 | } |
| 336 | } |