blob: afb3f67b7b102ba118e8ad93420e45eb842696e2 [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
Andrew de Andrade5e0f7752015-07-29 15:43:15 -070020'use strict';
21var test = require('tape');
22var thrift = require('../lib/thrift/thrift.js');
23var InputBufferUnderrunError = require('../lib/thrift/input_buffer_underrun_error');
24
25test('TApplicationException', function t(assert) {
26 var e = new thrift.TApplicationException(1, 'foo');
27 assert.ok(e instanceof thrift.TApplicationException, 'is instanceof TApplicationException');
28 assert.ok(e instanceof thrift.TException, 'is instanceof TException');
29 assert.ok(e instanceof Error, 'is instanceof Error');
30 assert.equal(typeof e.stack, 'string', 'has stack trace');
31 assert.ok(/^TApplicationException: foo/.test(e.stack), 'Stack trace has correct error name and message');
32 assert.ok(e.stack.indexOf('test/exceptions.js:7:11') !== -1, 'stack trace starts on correct line and column');
33 assert.equal(e.name, 'TApplicationException', 'has function name TApplicationException');
34 assert.equal(e.message, 'foo', 'has error message "foo"');
35 assert.equal(e.type, 1, 'has type 1');
36 assert.end();
37});
38
Kerri Devine91c74b62018-01-05 17:04:46 -060039test('unexpected TApplicationException ', function t(assert) {
40 var e = new thrift.TApplicationException(1, 100);
41 assert.ok(e instanceof thrift.TApplicationException, 'is instanceof TApplicationException');
42 assert.ok(e instanceof thrift.TException, 'is instanceof TException');
43 assert.ok(e instanceof Error, 'is instanceof Error');
44 assert.equal(typeof e.stack, 'string', 'has stack trace');
45 assert.ok(/^TApplicationException: 100/.test(e.stack), 'Stack trace has correct error name and message');
46 assert.ok(e.stack.indexOf('test/exceptions.js:7:11') !== -1, 'stack trace starts on correct line and column');
47 assert.equal(e.name, 'TApplicationException', 'has function name TApplicationException');
48 assert.equal(e.message, 100, 'has error message 100');
49 assert.equal(e.type, 1, 'has type 1');
50 assert.end();
51});
52
Andrew de Andrade5e0f7752015-07-29 15:43:15 -070053test('TException', function t(assert) {
54 var e = new thrift.TException('foo');
55 assert.ok(e instanceof thrift.TException, 'is instanceof TException');
56 assert.ok(e instanceof Error, 'is instanceof Error');
57 assert.equal(typeof e.stack, 'string', 'has stack trace');
58 assert.ok(/^TException: foo/.test(e.stack), 'Stack trace has correct error name and message');
59 assert.ok(e.stack.indexOf('test/exceptions.js:21:11') !== -1, 'stack trace starts on correct line and column');
60 assert.equal(e.name, 'TException', 'has function name TException');
61 assert.equal(e.message, 'foo', 'has error message "foo"');
62 assert.end();
63});
64
65test('TProtocolException', function t(assert) {
66 var e = new thrift.TProtocolException(1, 'foo');
67 assert.ok(e instanceof thrift.TProtocolException, 'is instanceof TProtocolException');
68 assert.ok(e instanceof Error, 'is instanceof Error');
69 assert.equal(typeof e.stack, 'string', 'has stack trace');
70 assert.ok(/^TProtocolException: foo/.test(e.stack), 'Stack trace has correct error name and message');
71 assert.ok(e.stack.indexOf('test/exceptions.js:33:11') !== -1, 'stack trace starts on correct line and column');
72 assert.equal(e.name, 'TProtocolException', 'has function name TProtocolException');
73 assert.equal(e.message, 'foo', 'has error message "foo"');
74 assert.equal(e.type, 1, 'has type 1');
75 assert.end();
76});
77
78test('InputBufferUnderrunError', function t(assert) {
79 var e = new InputBufferUnderrunError('foo');
80 assert.ok(e instanceof InputBufferUnderrunError, 'is instanceof InputBufferUnderrunError');
81 assert.ok(e instanceof Error, 'is instanceof Error');
82 assert.equal(typeof e.stack, 'string', 'has stack trace');
83 assert.ok(/^InputBufferUnderrunError: foo/.test(e.stack), 'Stack trace has correct error name and message');
84 assert.ok(e.stack.indexOf('test/exceptions.js:46:11') !== -1, 'stack trace starts on correct line and column');
85 assert.equal(e.name, 'InputBufferUnderrunError', 'has function name InputBufferUnderrunError');
86 assert.equal(e.message, 'foo', 'has error message "foo"');
87 assert.end();
88});