Skip to content

Commit

Permalink
fix: no cluster url should return a rejected Promise
Browse files Browse the repository at this point in the history
  • Loading branch information
lholmquist committed Jan 23, 2019
1 parent 65093a3 commit fa2a549
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/openshift-rest-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function openshiftClient (settings = {}) {
if (client.settings.config !== undefined) {
const url = client.settings.config.cluster;
if (!url) {
throw new Error('Please provide an url of your OpenShift cluster in your configuration settings.');
return Promise.reject(new Error('Please provide an url of your OpenShift cluster in your configuration settings.'));
} else {
client.settings.config.cluster = url.endsWith('/') ? url.slice(0, url.length - 1) : url;
}
Expand Down
53 changes: 52 additions & 1 deletion test/openshift-client-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,59 @@ test('openshift client settings test', (t) => {

osClient.then((client) => {
t.ok(client.settings, 'client object should have a settings object');
console.log(client.settings);
t.ok(client.settings.request, 'client object should have a settings.request object');
t.end();
});
});

test('openshift client config settings test', (t) => {
// Need to stub the config loader for these tests
const stubbedConfigLoader = (client) => {
return Promise.resolve(client);
};

const openshiftRestClient = proxyquire('../lib/openshift-rest-client', {
'./config-loader': stubbedConfigLoader
});

const settings = {
request: {
strictSSL: true
},
config: {
cluster: 'https://192.168.99.100:8443/'
}
};

const osClient = openshiftRestClient(settings);

osClient.then((client) => {
t.ok(client.settings.config.cluster, 'https://192.168.99.100:8443', 'should have the trailing slash removed');
t.end();
});
});

test('openshift client config settings test - no url', (t) => {
// Need to stub the config loader for these tests
const stubbedConfigLoader = (client) => {
return Promise.resolve(client);
};

const openshiftRestClient = proxyquire('../lib/openshift-rest-client', {
'./config-loader': stubbedConfigLoader
});

const settings = {
request: {
strictSSL: true
},
config: {}
};

const osClient = openshiftRestClient(settings);

osClient.catch(error => {
t.equal(error.message, 'Please provide an url of your OpenShift cluster in your configuration settings.', 'should have error message');
t.end();
});
});

0 comments on commit fa2a549

Please sign in to comment.