murgatroid99 | 749666e | 2015-01-12 18:25:58 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 0605995 | 2015-02-18 08:34:56 -0800 | [diff] [blame] | 3 | * Copyright 2015, Google Inc. |
murgatroid99 | 749666e | 2015-01-12 18:25:58 -0800 | [diff] [blame] | 4 | * 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 | |
murgatroid99 | dca966d | 2015-02-19 14:37:18 -0800 | [diff] [blame] | 34 | 'use strict'; |
| 35 | |
murgatroid99 | e506151 | 2015-01-12 18:14:35 -0800 | [diff] [blame] | 36 | var assert = require('assert'); |
| 37 | var grpc = require('bindings')('grpc.node'); |
| 38 | |
| 39 | describe('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 | }); |
murgatroid99 | ea12b97 | 2015-07-24 10:43:27 -0700 | [diff] [blame] | 90 | 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 Tiller | ce5021b | 2015-02-18 09:25:21 -0800 | [diff] [blame] | 96 | }); |