blob: 3e61d3bbc62da47cad37b75e7b7ea9817c864477 [file] [log] [blame]
murgatroid99749666e2015-01-12 18:25:58 -08001/*
2 *
Craig Tiller06059952015-02-18 08:34:56 -08003 * Copyright 2015, Google Inc.
murgatroid99749666e2015-01-12 18:25:58 -08004 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
murgatroid99dca966d2015-02-19 14:37:18 -080034'use strict';
35
murgatroid99e5061512015-01-12 18:14:35 -080036var assert = require('assert');
37var grpc = require('bindings')('grpc.node');
38
39describe('channel', function() {
40 describe('constructor', function() {
41 it('should require a string for the first argument', function() {
42 assert.doesNotThrow(function() {
43 new grpc.Channel('hostname');
44 });
45 assert.throws(function() {
46 new grpc.Channel();
47 }, TypeError);
48 assert.throws(function() {
49 new grpc.Channel(5);
50 });
51 });
52 it('should accept an object for the second parameter', function() {
53 assert.doesNotThrow(function() {
54 new grpc.Channel('hostname', {});
55 });
56 assert.throws(function() {
57 new grpc.Channel('hostname', 5);
58 });
59 });
60 it('should only accept objects with string or int values', function() {
61 assert.doesNotThrow(function() {
62 new grpc.Channel('hostname', {'key' : 'value'});
63 });
64 assert.doesNotThrow(function() {
65 new grpc.Channel('hostname', {'key' : 5});
66 });
67 assert.throws(function() {
68 new grpc.Channel('hostname', {'key' : null});
69 });
70 assert.throws(function() {
71 new grpc.Channel('hostname', {'key' : new Date()});
72 });
73 });
74 });
75 describe('close', function() {
76 it('should succeed silently', function() {
77 var channel = new grpc.Channel('hostname', {});
78 assert.doesNotThrow(function() {
79 channel.close();
80 });
81 });
82 it('should be idempotent', function() {
83 var channel = new grpc.Channel('hostname', {});
84 assert.doesNotThrow(function() {
85 channel.close();
86 channel.close();
87 });
88 });
89 });
murgatroid99ea12b972015-07-24 10:43:27 -070090 describe('getTarget', function() {
91 it('should return a string', function() {
92 var channel = new grpc.Channel('localhost', {});
93 assert.strictEqual(typeof channel.getTarget(), 'string');
94 });
95 });
Craig Tillerce5021b2015-02-18 09:25:21 -080096});