blob: 4119e76b0522063f1da861e19e6b522675f4a248 [file] [log] [blame]
James E. King, III375bfee2017-10-26 00:09:34 -04001/*
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
bforbisda1169d2018-10-28 11:27:38 -040020"use strict";
21const test = require("tape");
22const thrift = require("../lib/thrift/thrift.js");
Cameron Martin7fe4bf52025-02-04 17:46:53 +000023const { InputBufferUnderrunError } = require("../lib/thrift");
Andrew de Andrade5e0f7752015-07-29 15:43:15 -070024
bforbisda1169d2018-10-28 11:27:38 -040025test("TApplicationException", function t(assert) {
26 const e = new thrift.TApplicationException(1, "foo");
27 assert.ok(
28 e instanceof thrift.TApplicationException,
Cameron Martincaef0ed2025-01-15 11:58:39 +010029 "is instanceof TApplicationException",
bforbisda1169d2018-10-28 11:27:38 -040030 );
31 assert.ok(e instanceof thrift.TException, "is instanceof TException");
32 assert.ok(e instanceof Error, "is instanceof Error");
33 assert.equal(typeof e.stack, "string", "has stack trace");
34 assert.ok(
35 /^TApplicationException: foo/.test(e.stack),
Cameron Martincaef0ed2025-01-15 11:58:39 +010036 "Stack trace has correct error name and message",
bforbisda1169d2018-10-28 11:27:38 -040037 );
38 assert.ok(
39 e.stack.indexOf("test/exceptions.js:7:11") !== -1,
Cameron Martincaef0ed2025-01-15 11:58:39 +010040 "stack trace starts on correct line and column",
bforbisda1169d2018-10-28 11:27:38 -040041 );
42 assert.equal(
43 e.name,
44 "TApplicationException",
Cameron Martincaef0ed2025-01-15 11:58:39 +010045 "has function name TApplicationException",
bforbisda1169d2018-10-28 11:27:38 -040046 );
47 assert.equal(e.message, "foo", 'has error message "foo"');
48 assert.equal(e.type, 1, "has type 1");
Andrew de Andrade5e0f7752015-07-29 15:43:15 -070049 assert.end();
50});
51
bforbisda1169d2018-10-28 11:27:38 -040052test("unexpected TApplicationException ", function t(assert) {
53 const e = new thrift.TApplicationException(1, 100);
54 assert.ok(
55 e instanceof thrift.TApplicationException,
Cameron Martincaef0ed2025-01-15 11:58:39 +010056 "is instanceof TApplicationException",
bforbisda1169d2018-10-28 11:27:38 -040057 );
58 assert.ok(e instanceof thrift.TException, "is instanceof TException");
59 assert.ok(e instanceof Error, "is instanceof Error");
60 assert.equal(typeof e.stack, "string", "has stack trace");
61 assert.ok(
62 /^TApplicationException: 100/.test(e.stack),
Cameron Martincaef0ed2025-01-15 11:58:39 +010063 "Stack trace has correct error name and message",
bforbisda1169d2018-10-28 11:27:38 -040064 );
65 assert.ok(
66 e.stack.indexOf("test/exceptions.js:7:11") !== -1,
Cameron Martincaef0ed2025-01-15 11:58:39 +010067 "stack trace starts on correct line and column",
bforbisda1169d2018-10-28 11:27:38 -040068 );
69 assert.equal(
70 e.name,
71 "TApplicationException",
Cameron Martincaef0ed2025-01-15 11:58:39 +010072 "has function name TApplicationException",
bforbisda1169d2018-10-28 11:27:38 -040073 );
74 assert.equal(e.message, 100, "has error message 100");
75 assert.equal(e.type, 1, "has type 1");
Kerri Devine91c74b62018-01-05 17:04:46 -060076 assert.end();
77});
78
bforbisda1169d2018-10-28 11:27:38 -040079test("TException", function t(assert) {
80 const e = new thrift.TException("foo");
81 assert.ok(e instanceof thrift.TException, "is instanceof TException");
82 assert.ok(e instanceof Error, "is instanceof Error");
83 assert.equal(typeof e.stack, "string", "has stack trace");
84 assert.ok(
85 /^TException: foo/.test(e.stack),
Cameron Martincaef0ed2025-01-15 11:58:39 +010086 "Stack trace has correct error name and message",
bforbisda1169d2018-10-28 11:27:38 -040087 );
88 assert.ok(
89 e.stack.indexOf("test/exceptions.js:21:11") !== -1,
Cameron Martincaef0ed2025-01-15 11:58:39 +010090 "stack trace starts on correct line and column",
bforbisda1169d2018-10-28 11:27:38 -040091 );
92 assert.equal(e.name, "TException", "has function name TException");
93 assert.equal(e.message, "foo", 'has error message "foo"');
Andrew de Andrade5e0f7752015-07-29 15:43:15 -070094 assert.end();
95});
96
bforbisda1169d2018-10-28 11:27:38 -040097test("TProtocolException", function t(assert) {
98 const e = new thrift.TProtocolException(1, "foo");
99 assert.ok(
100 e instanceof thrift.TProtocolException,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100101 "is instanceof TProtocolException",
bforbisda1169d2018-10-28 11:27:38 -0400102 );
103 assert.ok(e instanceof Error, "is instanceof Error");
104 assert.equal(typeof e.stack, "string", "has stack trace");
105 assert.ok(
106 /^TProtocolException: foo/.test(e.stack),
Cameron Martincaef0ed2025-01-15 11:58:39 +0100107 "Stack trace has correct error name and message",
bforbisda1169d2018-10-28 11:27:38 -0400108 );
109 assert.ok(
110 e.stack.indexOf("test/exceptions.js:33:11") !== -1,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100111 "stack trace starts on correct line and column",
bforbisda1169d2018-10-28 11:27:38 -0400112 );
113 assert.equal(
114 e.name,
115 "TProtocolException",
Cameron Martincaef0ed2025-01-15 11:58:39 +0100116 "has function name TProtocolException",
bforbisda1169d2018-10-28 11:27:38 -0400117 );
118 assert.equal(e.message, "foo", 'has error message "foo"');
119 assert.equal(e.type, 1, "has type 1");
Andrew de Andrade5e0f7752015-07-29 15:43:15 -0700120 assert.end();
121});
122
bforbisda1169d2018-10-28 11:27:38 -0400123test("InputBufferUnderrunError", function t(assert) {
124 const e = new InputBufferUnderrunError("foo");
125 assert.ok(
126 e instanceof InputBufferUnderrunError,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100127 "is instanceof InputBufferUnderrunError",
bforbisda1169d2018-10-28 11:27:38 -0400128 );
129 assert.ok(e instanceof Error, "is instanceof Error");
130 assert.equal(typeof e.stack, "string", "has stack trace");
131 assert.ok(
132 /^InputBufferUnderrunError: foo/.test(e.stack),
Cameron Martincaef0ed2025-01-15 11:58:39 +0100133 "Stack trace has correct error name and message",
bforbisda1169d2018-10-28 11:27:38 -0400134 );
135 assert.ok(
136 e.stack.indexOf("test/exceptions.js:46:11") !== -1,
Cameron Martincaef0ed2025-01-15 11:58:39 +0100137 "stack trace starts on correct line and column",
bforbisda1169d2018-10-28 11:27:38 -0400138 );
139 assert.equal(
140 e.name,
141 "InputBufferUnderrunError",
Cameron Martincaef0ed2025-01-15 11:58:39 +0100142 "has function name InputBufferUnderrunError",
bforbisda1169d2018-10-28 11:27:38 -0400143 );
144 assert.equal(e.message, "foo", 'has error message "foo"');
Andrew de Andrade5e0f7752015-07-29 15:43:15 -0700145 assert.end();
146});