blob: 93b93b71519dee004ea73bea8101620daaaa2a1a [file] [log] [blame]
Randy Abernethy2e091f62014-11-15 23:05:22 -08001/*
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//This is the client side test for the standard Apache Thrift
21//"ThriftTest" suite. This client will test any protocol/transport
22//combination specified on the command line.
23
24var fs = require('fs');
25var assert = require('assert');
26var thrift = require('thrift');
27var ThriftTest = require('./gen-nodejs/ThriftTest');
28var ThriftTestDriver = require('./thrift_test_driver').ThriftTestDriver;
29var ThriftTestDriverPromise = require('./thrift_test_driver_promise').ThriftTestDriver;
30
31var program = require('commander');
32
33program
34 .option('-p, --protocol <protocol>', 'Set thrift protocol (binary|json) [protocol]')
35 .option('-t, --transport <transport>', 'Set thrift transport (buffered|framed) [transport]')
36 .option('--ssl', 'use wss instead of ws')
37 .option('--promise', 'test with promise style functions')
38 .parse(process.argv);
39
40var protocol = thrift.TBinaryProtocol;
41if (program.protocol === "json") {
42 protocol = thrift.TJSONProtocol;
Randy Abernethy96f4f072015-02-10 02:29:15 -080043}
Randy Abernethy2e091f62014-11-15 23:05:22 -080044
45var transport = thrift.TBufferedTransport;
46if (program.transport === "framed") {
47 transport = thrift.TFramedTransport;
48}
49
50var options = {
51 transport: transport,
52 protocol: protocol,
53 path: "/test"
54};
55
56if (program.ssl) {
57 options.wsOptions = { rejectUnauthorized: false };
58 options.secure = true;
Randy Abernethy96f4f072015-02-10 02:29:15 -080059}
Randy Abernethy2e091f62014-11-15 23:05:22 -080060
61var connection = thrift.createWSConnection("localhost", 9090, options);
62connection.open();
63
64var client = thrift.createWSClient(ThriftTest, connection);
65
66connection.on('error', function(err) {
67 assert(false, err);
68});
69
70var testDriver = ThriftTestDriver;
71if (program.promise) {
72 console.log(" --Testing promise style client");
73 testDriver = ThriftTestDriverPromise;
Randy Abernethy96f4f072015-02-10 02:29:15 -080074}
Randy Abernethy2e091f62014-11-15 23:05:22 -080075testDriver(client, function (status) {
76 console.log(status);
77 process.exit(0);
78});
79
80// to make it also run on expresso
81exports.expressoTest = function() {};