'use strict';

var test = require('tape');
var TChannel = require('tchannel');

var AutobahnClient = require('../index.js');

test('getting client subChannel without serviceName', function t(assert) {
    var client = AutobahnClient({
        tchannel: TChannel(),
        serviceName: 'foo',
        callerName: 'foo-test',
        hostPortList: []
    });

    assert.throws(function throwIt() {
        client.getClientChannel();
    }, /invalid option serviceName/);

    assert.throws(function throwIt() {
        client.getClientChannel({});
    }, /invalid option serviceName/);

    assert.end();
});

test('getting a client subChannel', function t(assert) {
    var client = AutobahnClient({
        tchannel: TChannel(),
        serviceName: 'foo',
        callerName: 'foo-test',
        hostPortList: []
    });

    var subChannel = client.getClientChannel({
        serviceName: 'bar'
    });

    assert.equal(subChannel.topChannel, client.tchannel);

    assert.end();
});

test('double getting a client subChannel', function t(assert) {
    var client = AutobahnClient({
        tchannel: TChannel(),
        serviceName: 'foo',
        callerName: 'foo-test',
        hostPortList: []
    });

    var subChannel1 = client.getClientChannel({
        serviceName: 'bar'
    });
    var subChannel2 = client.getClientChannel({
        serviceName: 'bar'
    });

    assert.equal(subChannel1, subChannel2);

    assert.end();
});

@@ -60,24 +60,22 @@
 equire('
-tchannel
+../../
 ');%0A%0Avar
@@ -75,20 +75,21 @@
 );%0A%0Avar 
-Auto
+Hyper
 bahnClie
@@ -105,16 +105,29 @@
 ire('../
+../hyperbahn/
 index.js
@@ -215,36 +215,37 @@
    var client = 
-Auto
+Hyper
 bahnClient(%7B%0A   
@@ -682,36 +682,37 @@
    var client = 
-Auto
+Hyper
 bahnClient(%7B%0A   
@@ -1082,12 +1082,13 @@
 t = 
-Auto
+Hyper
 bahn

refactor sub-channel test to work