UNPKG

4.35 kBJavaScriptView Raw
1'use strict';
2
3var assert = require('assertthat');
4
5var crew = require('../lib/crew'),
6 settings = require('./settings');
7
8suite('crew', function () {
9 test('is a function.', function (done) {
10 assert.that(crew).is.ofType('function');
11 done();
12 });
13
14 test('throws an error when the options are missing.', function (done) {
15 assert.that(function () {
16 crew();
17 }).is.throwing('Options are missing.');
18 done();
19 });
20
21 test('throws an error when the host is missing.', function (done) {
22 assert.that(function () {
23 crew({
24 port: settings.port,
25 keys: {
26 privateKey: settings.privateKey,
27 certificate: settings.certificate,
28 caCertificate: settings.caCertificate
29 }
30 });
31 }).is.throwing('Host is missing.');
32 done();
33 });
34
35 test('throws an error when the port is missing.', function (done) {
36 assert.that(function () {
37 crew({
38 host: settings.host,
39 keys: {
40 privateKey: settings.privateKey,
41 certificate: settings.certificate,
42 caCertificate: settings.caCertificate
43 }
44 });
45 }).is.throwing('Port is missing.');
46 done();
47 });
48
49 test('throws an error when the keys are missing.', function (done) {
50 assert.that(function () {
51 crew({
52 host: settings.host,
53 port: settings.port
54 });
55 }).is.throwing('Keys are missing.');
56 done();
57 });
58
59 test('throws an error when the private key is missing.', function (done) {
60 assert.that(function () {
61 crew({
62 host: settings.host,
63 port: settings.port,
64 keys: {
65 certificate: settings.certificate,
66 caCertificate: settings.caCertificate
67 }
68 });
69 }).is.throwing('Private key is missing.');
70 done();
71 });
72
73 test('throws an error when the certificate is missing.', function (done) {
74 assert.that(function () {
75 crew({
76 host: settings.host,
77 port: settings.port,
78 keys: {
79 privateKey: settings.privateKey,
80 caCertificate: settings.caCertificate
81 }
82 });
83 }).is.throwing('Certificate is missing.');
84 done();
85 });
86
87 test('throws an error when the CA certificate is missing.', function (done) {
88 assert.that(function () {
89 crew({
90 host: settings.host,
91 port: settings.port,
92 keys: {
93 privateKey: settings.privateKey,
94 certificate: settings.certificate
95 }
96 });
97 }).is.throwing('CA certificate is missing.');
98 done();
99 });
100
101 test('throws an error when the callback is missing, but an options object is given.', function (done) {
102 assert.that(function () {
103 crew({
104 host: settings.host,
105 port: settings.port,
106 keys: {
107 privateKey: settings.privateKey,
108 certificate: settings.certificate,
109 caCertificate: settings.caCertificate
110 }
111 });
112 }).is.throwing('Callback is missing.');
113 done();
114 });
115
116 test('returns an error when the given Docker server is not reachable.', function (done) {
117 crew({
118 host: settings.host,
119 port: 12345,
120 keys: {
121 privateKey: settings.privateKey,
122 certificate: settings.certificate,
123 caCertificate: settings.caCertificate
124 }
125 }, function (err) {
126 assert.that(err).is.not.null();
127 done();
128 });
129 });
130
131 test('returns an error when the given Docker server is reachable, but the certificate does not match.', function (done) {
132 // In this test, the CA certificate is being used as client certificate,
133 // which does not match what the Docker server expects.
134 crew({
135 host: settings.host,
136 port: settings.port,
137 keys: {
138 privateKey: settings.privateKey,
139 certificate: settings.caCertificate,
140 caCertificate: settings.caCertificate
141 }
142 }, function (err) {
143 assert.that(err).is.not.null();
144 done();
145 });
146 });
147
148 test('returns an object when the given Docker server is reachable.', function (done) {
149 crew({
150 host: settings.host,
151 port: settings.port,
152 keys: {
153 privateKey: settings.privateKey,
154 certificate: settings.certificate,
155 caCertificate: settings.caCertificate
156 }
157 }, function (err) {
158 assert.that(err).is.null();
159 done();
160 });
161 });
162});