blob: 14c1a29b05fea46d5f5a2a095b7e4c7a73e890a3 [file] [log] [blame]
ra8f697cb2014-04-23 02:23:18 -07001/*
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 SSL transport')
37 .option('--promise', 'test with promise style functions')
38 .parse(process.argv);
39
40
41var protocol = thrift.TBinaryProtocol;
42if (program.protocol === "json") {
43 protocol = thrift.TJSONProtocol;
44}
45
46var transport = thrift.TBufferedTransport;
47if (program.transport === "framed") {
48 transport = thrift.TFramedTransport;
49}
50
51var options = {
52 transport: transport,
53 protocol: protocol,
54 headers: {"Connection": "close"},
55 path: "/test"
56};
57
ra8f697cb2014-04-23 02:23:18 -070058if (program.ssl) {
ra779b9ac2014-04-23 20:04:23 -070059 options.nodeOptions = { rejectUnauthorized: false };
60 options.https = true;
61}
62
63var connection = thrift.createHttpConnection("localhost", 9090, options);
ra8f697cb2014-04-23 02:23:18 -070064
65var client = thrift.createHttpClient(ThriftTest, connection);
66
ra779b9ac2014-04-23 20:04:23 -070067connection.on('error', function(err) {
68 assert(false, err);
69});
ra8f697cb2014-04-23 02:23:18 -070070
71var testDriver = ThriftTestDriver;
72if (program.promise) {
ra779b9ac2014-04-23 20:04:23 -070073 console.log(" --Testing promise style client");
ra8f697cb2014-04-23 02:23:18 -070074 testDriver = ThriftTestDriverPromise;
75}
76testDriver(client, function (status) {
77 console.log(status);
78 process.exit(0);
79});
80
81// to make it also run on expresso
82exports.expressoTest = function() {};