blob: 0a7577062e8286bffb5c5090b2a9dceafdd14907 [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
39test('TException', function t(assert) {
40 var e = new thrift.TException('foo');
41 assert.ok(e instanceof thrift.TException, 'is instanceof TException');
42 assert.ok(e instanceof Error, 'is instanceof Error');
43 assert.equal(typeof e.stack, 'string', 'has stack trace');
44 assert.ok(/^TException: foo/.test(e.stack), 'Stack trace has correct error name and message');
45 assert.ok(e.stack.indexOf('test/exceptions.js:21:11') !== -1, 'stack trace starts on correct line and column');
46 assert.equal(e.name, 'TException', 'has function name TException');
47 assert.equal(e.message, 'foo', 'has error message "foo"');
48 assert.end();
49});
50
51test('TProtocolException', function t(assert) {
52 var e = new thrift.TProtocolException(1, 'foo');
53 assert.ok(e instanceof thrift.TProtocolException, 'is instanceof TProtocolException');
54 assert.ok(e instanceof Error, 'is instanceof Error');
55 assert.equal(typeof e.stack, 'string', 'has stack trace');
56 assert.ok(/^TProtocolException: foo/.test(e.stack), 'Stack trace has correct error name and message');
57 assert.ok(e.stack.indexOf('test/exceptions.js:33:11') !== -1, 'stack trace starts on correct line and column');
58 assert.equal(e.name, 'TProtocolException', 'has function name TProtocolException');
59 assert.equal(e.message, 'foo', 'has error message "foo"');
60 assert.equal(e.type, 1, 'has type 1');
61 assert.end();
62});
63
64test('InputBufferUnderrunError', function t(assert) {
65 var e = new InputBufferUnderrunError('foo');
66 assert.ok(e instanceof InputBufferUnderrunError, 'is instanceof InputBufferUnderrunError');
67 assert.ok(e instanceof Error, 'is instanceof Error');
68 assert.equal(typeof e.stack, 'string', 'has stack trace');
69 assert.ok(/^InputBufferUnderrunError: foo/.test(e.stack), 'Stack trace has correct error name and message');
70 assert.ok(e.stack.indexOf('test/exceptions.js:46:11') !== -1, 'stack trace starts on correct line and column');
71 assert.equal(e.name, 'InputBufferUnderrunError', 'has function name InputBufferUnderrunError');
72 assert.equal(e.message, 'foo', 'has error message "foo"');
73 assert.end();
74});