]> git.proxmox.com Git - ceph.git/blame - ceph/src/jaegertracing/thrift/lib/nodejs/test/exceptions.js
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / thrift / lib / nodejs / test / exceptions.js
CommitLineData
f67539c2
TL
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"use strict";
21const test = require("tape");
22const thrift = require("../lib/thrift/thrift.js");
23const InputBufferUnderrunError = require("../lib/thrift/input_buffer_underrun_error");
24
25test("TApplicationException", function t(assert) {
26 const e = new thrift.TApplicationException(1, "foo");
27 assert.ok(
28 e instanceof thrift.TApplicationException,
29 "is instanceof TApplicationException"
30 );
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),
36 "Stack trace has correct error name and message"
37 );
38 assert.ok(
39 e.stack.indexOf("test/exceptions.js:7:11") !== -1,
40 "stack trace starts on correct line and column"
41 );
42 assert.equal(
43 e.name,
44 "TApplicationException",
45 "has function name TApplicationException"
46 );
47 assert.equal(e.message, "foo", 'has error message "foo"');
48 assert.equal(e.type, 1, "has type 1");
49 assert.end();
50});
51
52test("unexpected TApplicationException ", function t(assert) {
53 const e = new thrift.TApplicationException(1, 100);
54 assert.ok(
55 e instanceof thrift.TApplicationException,
56 "is instanceof TApplicationException"
57 );
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),
63 "Stack trace has correct error name and message"
64 );
65 assert.ok(
66 e.stack.indexOf("test/exceptions.js:7:11") !== -1,
67 "stack trace starts on correct line and column"
68 );
69 assert.equal(
70 e.name,
71 "TApplicationException",
72 "has function name TApplicationException"
73 );
74 assert.equal(e.message, 100, "has error message 100");
75 assert.equal(e.type, 1, "has type 1");
76 assert.end();
77});
78
79test("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),
86 "Stack trace has correct error name and message"
87 );
88 assert.ok(
89 e.stack.indexOf("test/exceptions.js:21:11") !== -1,
90 "stack trace starts on correct line and column"
91 );
92 assert.equal(e.name, "TException", "has function name TException");
93 assert.equal(e.message, "foo", 'has error message "foo"');
94 assert.end();
95});
96
97test("TProtocolException", function t(assert) {
98 const e = new thrift.TProtocolException(1, "foo");
99 assert.ok(
100 e instanceof thrift.TProtocolException,
101 "is instanceof TProtocolException"
102 );
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),
107 "Stack trace has correct error name and message"
108 );
109 assert.ok(
110 e.stack.indexOf("test/exceptions.js:33:11") !== -1,
111 "stack trace starts on correct line and column"
112 );
113 assert.equal(
114 e.name,
115 "TProtocolException",
116 "has function name TProtocolException"
117 );
118 assert.equal(e.message, "foo", 'has error message "foo"');
119 assert.equal(e.type, 1, "has type 1");
120 assert.end();
121});
122
123test("InputBufferUnderrunError", function t(assert) {
124 const e = new InputBufferUnderrunError("foo");
125 assert.ok(
126 e instanceof InputBufferUnderrunError,
127 "is instanceof InputBufferUnderrunError"
128 );
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),
133 "Stack trace has correct error name and message"
134 );
135 assert.ok(
136 e.stack.indexOf("test/exceptions.js:46:11") !== -1,
137 "stack trace starts on correct line and column"
138 );
139 assert.equal(
140 e.name,
141 "InputBufferUnderrunError",
142 "has function name InputBufferUnderrunError"
143 );
144 assert.equal(e.message, "foo", 'has error message "foo"');
145 assert.end();
146});