3 const assert = require('assert');
5 const RemoteAPI = require('../tools/js/remote.js').RemoteAPI;
7 describe('RemoteAPI', function () {
8 describe('configure', function () {
9 it('should accept a valid configuration', function () {
10 let remote = new RemoteAPI();
11 assert.doesNotThrow(function () { remote.configure({scheme: 'http', host: 'build.webkit.org', port: 80}); });
14 it('should reject a scheme other than http and https', function () {
15 let remote = new RemoteAPI();
16 assert.doesNotThrow(function () { remote.configure({scheme: 'http', host: 'build.webkit.org', port: 80}); });
17 assert.doesNotThrow(function () { remote.configure({scheme: 'https', host: 'build.webkit.org', port: 9999}); });
18 assert.throws(function () { remote.configure({scheme: 'ftp', host: 'build.webkit.org', port: 9999}); });
21 it('should accept a configuration without port', function () {
22 let remote = new RemoteAPI();
23 assert.doesNotThrow(function () { remote.configure({scheme: 'http', host: 'build.webkit.org'}); });
26 it('should reject non-string value for scheme', function () {
27 let remote = new RemoteAPI();
28 assert.throws(function () { remote.configure({scheme: 1, host: 'build.webkit.org', port: 80}); });
29 assert.throws(function () { remote.configure({scheme: {}, host: 'build.webkit.org', port: 80}); });
30 assert.throws(function () { remote.configure({scheme: [], host: 'build.webkit.org', port: 80}); });
33 it('should reject non-string value for host', function () {
34 let remote = new RemoteAPI();
35 assert.throws(function () { remote.configure({scheme: 'http', host: 1, port: 80}); });
36 assert.throws(function () { remote.configure({scheme: 'http', host: {}, port: 80}); });
37 assert.throws(function () { remote.configure({scheme: 'http', host: [], port: 80}); });
40 it('should reject non-object value for auth', function () {
41 let remote = new RemoteAPI();
42 assert.throws(function () { remote.configure({scheme: 'http', host: 'build.webkit.org', port: 80, auth: 'a'}); });
43 assert.throws(function () { remote.configure({scheme: 'http', host: 'build.webkit.org', port: 80, auth: 1}); });
46 it('should accept a configuration with auth', function () {
47 let remote = new RemoteAPI();
48 assert.doesNotThrow(function () {
51 host: 'build.webkit.org',
61 it('should reject auth without username or password or when either is not a string', function () {
62 let remote = new RemoteAPI();
63 assert.throws(function () { remote.configure({scheme: 'http', host: 'build.webkit.org', port: 80, auth: {}}); });
64 assert.throws(function () { remote.configure({scheme: 'http', host: 'build.webkit.org', port: 80, auth: {username: 'a'}}); });
65 assert.throws(function () { remote.configure({scheme: 'http', host: 'build.webkit.org', port: 80, auth: {password: 'b'}}); });
66 assert.throws(function () { remote.configure({scheme: 'http', host: 'build.webkit.org', port: 80, auth: {username: 1, password: 'a'}}); });
67 assert.throws(function () { remote.configure({scheme: 'http', host: 'build.webkit.org', port: 80, auth: {username: 'a', password: 1}}); });
71 describe('url', function () {
72 it('should be able to serialize http://build.webkit.org', function () {
73 let remote = new RemoteAPI({scheme: 'http', host: 'build.webkit.org', port: 80});
74 assert.equal(remote.url('/json/builders'), 'http://build.webkit.org/json/builders');
77 it('should be able to serialize http://build.webkit.org when port is not specified', function () {
78 let remote = new RemoteAPI({scheme: 'http', host: 'build.webkit.org'});
79 assert.equal(remote.url('/json/builders'), 'http://build.webkit.org/json/builders');
82 it('should be able to serialize https://build.webkit.org when port is 80', function () {
83 let remote = new RemoteAPI({scheme: 'http', host: 'build.webkit.org', port: 80});
84 assert.equal(remote.url('/json/builders'), 'http://build.webkit.org/json/builders');
87 it('should be able to serialize http://build.webkit.org:8080', function () {
88 let remote = new RemoteAPI({scheme: 'http', host: 'build.webkit.org', port: 8080});
89 assert.equal(remote.url('/json/builders'), 'http://build.webkit.org:8080/json/builders');
92 it('should be able to serialize https://build.webkit.org when port is not specified', function () {
93 let remote = new RemoteAPI({scheme: 'https', host: 'build.webkit.org'});
94 assert.equal(remote.url('/json/builders'), 'https://build.webkit.org/json/builders');
97 it('should be able to serialize https://build.webkit.org when port is 443', function () {
98 let remote = new RemoteAPI({scheme: 'https', host: 'build.webkit.org', port: 443});
99 assert.equal(remote.url('/json/builders'), 'https://build.webkit.org/json/builders');
102 it('should be able to serialize https://build.webkit.org:8443', function () {
103 let remote = new RemoteAPI({scheme: 'https', host: 'build.webkit.org', port: 8443});
104 assert.equal(remote.url('/json/builders'), 'https://build.webkit.org:8443/json/builders');
107 it('should automatically prefix the path with /', function () {
108 let remote = new RemoteAPI({scheme: 'http', host: 'build.webkit.org'});
109 assert.equal(remote.url('json/builders'), 'http://build.webkit.org/json/builders');