diff --git a/.travis.yml b/.travis.yml index 8b4f5e4..d1a2604 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,7 @@ dist: trusty language: node_js node_js: - "8" - - "7" - - "6" + - "9" before_install: - npm install -g npm - npm install -g greenkeeper-lockfile@1 diff --git a/lib/config-loader.js b/lib/config-loader.js index febc883..6418580 100644 --- a/lib/config-loader.js +++ b/lib/config-loader.js @@ -19,21 +19,26 @@ */ const privates = require('./private-map'); +const openshiftConfigLoader = require('openshift-config-loader'); + +function load (settings) { + if (settings.config) { + return Promise.resolve(settings.config); + } + + return openshiftConfigLoader(settings.openshiftConfigLoader); +} // Takes a config object as JSON // Returns a promise -function loadConfig (client, config) { - return new Promise((resolve, reject) => { - if (!config) { - return reject(new Error('Config object is require')); - } - +function loadConfig (client) { + return load(client.settings).then((config) => { client.apiUrl = `${config.cluster}/oapi/${config.apiVersion}`; client.kubeUrl = `${config.cluster}/api/${config.apiVersion}`; privates.get(client).config = config; - resolve(client); + return client; }); } diff --git a/lib/openshift-rest-client.js b/lib/openshift-rest-client.js index 07b9be7..4ed1cec 100644 --- a/lib/openshift-rest-client.js +++ b/lib/openshift-rest-client.js @@ -51,9 +51,7 @@ function bindModule (client, input) { } } -function openshiftClient (config, settings) { - settings = settings || {}; - +function openshiftClient (settings = {}) { const data = {}; const client = {}; @@ -82,7 +80,7 @@ function openshiftClient (config, settings) { privates.set(client, data); // Maybe load the config here? - return loadConfig(client, config); + return loadConfig(client); } module.exports = exports = openshiftClient; diff --git a/package-lock.json b/package-lock.json index 9061c5c..de63181 100644 --- a/package-lock.json +++ b/package-lock.json @@ -98,7 +98,6 @@ "version": "1.0.9", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.9.tgz", "integrity": "sha1-c9g7wmP4bpf4zE9rrhsOkKfSLIY=", - "dev": true, "requires": { "sprintf-js": "1.0.3" } @@ -3891,25 +3890,22 @@ } }, "openshift-config-loader": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/openshift-config-loader/-/openshift-config-loader-0.3.0.tgz", - "integrity": "sha512-9UxFIPWMRe7a9ZX63aPVqQpMbLNdofThYXbGiR1ypd92HICUcsyRLA4U/d5XJlLp4mCRDICPzFSnGnHbGyV/yw==", - "dev": true, + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/openshift-config-loader/-/openshift-config-loader-0.4.0.tgz", + "integrity": "sha512-/FMAxwvHTdXurj7OcsZ3uhMd8a6l2wvMhp8lyoh7L3JjByEFjmebezVVMl73VE11HW+i+k4K+svGFgSh192ZXQ==", "requires": { - "js-yaml": "3.9.1" + "js-yaml": "3.10.0" }, "dependencies": { "esprima": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.0.tgz", - "integrity": "sha512-oftTcaMu/EGrEIu904mWteKIv8vMuOgGYo7EhVJJN00R/EED9DCua/xxHRdYnKtcECzVg7xOWhflvJMnqcFZjw==", - "dev": true + "integrity": "sha512-oftTcaMu/EGrEIu904mWteKIv8vMuOgGYo7EhVJJN00R/EED9DCua/xxHRdYnKtcECzVg7xOWhflvJMnqcFZjw==" }, "js-yaml": { - "version": "3.9.1", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.9.1.tgz", - "integrity": "sha512-CbcG379L1e+mWBnLvHWWeLs8GyV/EMw862uLI3c+GxVyDHWZcjZinwuBd3iW2pgxgIlksW/1vNJa4to+RvDOww==", - "dev": true, + "version": "3.10.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.10.0.tgz", + "integrity": "sha512-O2v52ffjLa9VeM43J4XocZE//WT9N0IiwDa3KSHH7Tu8CtH+1qM8SIZvnsTh6v+4yFy5KUY3BHUVwjpfAWsjIA==", "requires": { "argparse": "1.0.9", "esprima": "4.0.0" @@ -4450,8 +4446,7 @@ "sprintf-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", - "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", - "dev": true + "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=" }, "sshpk": { "version": "1.13.1", diff --git a/package.json b/package.json index 766cd82..5f983ab 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "email": "lholmqui@redhat.com" }, "engines": { - "node": ">= 4.0.0" + "node": ">= 8.0.0" }, "repository": { "type": "git", @@ -39,6 +39,7 @@ "bugs": "https://github.com/bucharest-gold/openshift-rest-client/issues", "license": "Apache-2.0", "dependencies": { + "openshift-config-loader": "^0.4.0", "request": "^2.83.0" }, "devDependencies": { @@ -55,7 +56,6 @@ "nock": "^9.0.14", "nsp": "^3.1.0", "nyc": "^11.1.0", - "openshift-config-loader": "^0.3.0", "proxyquire": "^1.8.0", "tap-spec": "^4.1.1", "tape": "^4.6.3" diff --git a/test/build-config-test.js b/test/build-config-test.js index 4983c2f..8b6a60b 100644 --- a/test/build-config-test.js +++ b/test/build-config-test.js @@ -4,215 +4,171 @@ const test = require('tape'); const nock = require('nock'); const openshiftRestClient = require('../'); -const openshiftConfigLoader = require('openshift-config-loader'); const privates = require('../lib/private-map'); -test('find - buildconfigs - basic findAll', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.buildconfigs.findAll, 'function', 'There is a findAll method on the buildconfigs object'); +const settings = { + config: { + apiVersion: 'v1', + context: + { cluster: '192-168-99-100:8443', + namespace: 'for-node-client-testing', + user: 'developer/192-168-99-100:8443' }, + user: { token: 'zVBd1ZFeJqEAILJgimm4-gZJauaw3PW4EVqV_peEZ3U' }, + cluster: 'https://192.168.99.100:8443' } +}; - const clientConfig = privates.get(client).config; +test('find - buildconfigs - basic findAll', (t) => { + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.buildconfigs.findAll, 'function', 'There is a findAll method on the buildconfigs object'); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .get(`/oapi/v1/namespaces/${clientConfig.context.namespace}/buildconfigs`) - .reply(200, {kind: 'BuildConfigList'}); + const clientConfig = privates.get(client).config; - const findResult = client.buildconfigs.findAll().then((buildConfigList) => { - t.equal(buildConfigList.kind, 'BuildConfigList', 'returns an object with BuildConfigList'); - t.end(); - }); + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .get(`/oapi/v1/namespaces/${clientConfig.context.namespace}/buildconfigs`) + .reply(200, {kind: 'BuildConfigList'}); - t.equal(findResult instanceof Promise, true, 'should return a Promise'); + const findResult = client.buildconfigs.findAll().then((buildConfigList) => { + t.equal(buildConfigList.kind, 'BuildConfigList', 'returns an object with BuildConfigList'); + t.end(); }); + + t.equal(findResult instanceof Promise, true, 'should return a Promise'); }); }); test('find - buildconfigs - basic find', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.buildconfigs.find, 'function', 'There is a find method on the buildconfigs object'); - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.buildconfigs.find, 'function', 'There is a find method on the buildconfigs object'); + const clientConfig = privates.get(client).config; + const buildConfigName = 'cool-buildconfig-name-1'; - const clientConfig = privates.get(client).config; - const buildConfigName = 'cool-buildconfig-name-1'; + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .get(`/oapi/v1/namespaces/${clientConfig.context.namespace}/buildconfigs/${buildConfigName}`) + .reply(200, {kind: 'BuildConfig'}); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .get(`/oapi/v1/namespaces/${clientConfig.context.namespace}/buildconfigs/${buildConfigName}`) - .reply(200, {kind: 'BuildConfig'}); - - const findResult = client.buildconfigs.find(buildConfigName).then((buildconfig) => { - t.equal(buildconfig.kind, 'BuildConfig', 'returns an object with BuildConfig'); - t.end(); - }); - - t.equal(findResult instanceof Promise, true, 'should return a Promise'); + const findResult = client.buildconfigs.find(buildConfigName).then((buildconfig) => { + t.equal(buildconfig.kind, 'BuildConfig', 'returns an object with BuildConfig'); + t.end(); }); + + t.equal(findResult instanceof Promise, true, 'should return a Promise'); }); }); test('find - buildconfigs - find - no buildconfig name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.buildconfigs.find().catch((err) => { - t.equal(err.message, 'Build Config Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.buildconfigs.find().catch((err) => { + t.equal(err.message, 'Build Config Name is required', 'error message should return'); + t.end(); }); }); }); test('create - buildconfig', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.buildconfigs.create, 'function', 'There is a create method on the buildconfigs object'); - - const clientConfig = privates.get(client).config; - const buildconfig = { - kind: 'BuildConfig' - }; - - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .post(`/oapi/v1/namespaces/${clientConfig.context.namespace}/buildconfigs`) - .reply(200, {kind: 'BuildConfig'}); - - const createResult = client.buildconfigs.create(buildconfig).then((buildconfig) => { - t.equal(buildconfig.kind, 'BuildConfig', 'returns an object with BuildConfig'); - t.end(); - }); - - t.equal(createResult instanceof Promise, true, 'should return a Promise'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.buildconfigs.create, 'function', 'There is a create method on the buildconfigs object'); + + const clientConfig = privates.get(client).config; + const buildconfig = { + kind: 'BuildConfig' + }; + + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .post(`/oapi/v1/namespaces/${clientConfig.context.namespace}/buildconfigs`) + .reply(200, {kind: 'BuildConfig'}); + + const createResult = client.buildconfigs.create(buildconfig).then((buildconfig) => { + t.equal(buildconfig.kind, 'BuildConfig', 'returns an object with BuildConfig'); + t.end(); }); + + t.equal(createResult instanceof Promise, true, 'should return a Promise'); }); }); test('update - buildconfig', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.buildconfigs.create, 'function', 'There is a create method on the buildconfigs object'); - - const clientConfig = privates.get(client).config; - const buildconfig = { - kind: 'BuildConfig' - }; - const buildConfigName = 'cool-buildconfig-name-1'; - - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .put(`/oapi/v1/namespaces/${clientConfig.context.namespace}/buildconfigs/${buildConfigName}`) - .reply(200, {kind: 'BuildConfig'}); - - const createResult = client.buildconfigs.update(buildConfigName, buildconfig).then((buildconfig) => { - t.equal(buildconfig.kind, 'BuildConfig', 'returns an object with BuildConfig'); - t.end(); - }); - - t.equal(createResult instanceof Promise, true, 'should return a Promise'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.buildconfigs.create, 'function', 'There is a create method on the buildconfigs object'); + + const clientConfig = privates.get(client).config; + const buildconfig = { + kind: 'BuildConfig' + }; + const buildConfigName = 'cool-buildconfig-name-1'; + + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .put(`/oapi/v1/namespaces/${clientConfig.context.namespace}/buildconfigs/${buildConfigName}`) + .reply(200, {kind: 'BuildConfig'}); + + const createResult = client.buildconfigs.update(buildConfigName, buildconfig).then((buildconfig) => { + t.equal(buildconfig.kind, 'BuildConfig', 'returns an object with BuildConfig'); + t.end(); }); + + t.equal(createResult instanceof Promise, true, 'should return a Promise'); }); }); test('update - buildconfigs - update - no buildconfig name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.buildconfigs.update().catch((err) => { - t.equal(err.message, 'Build Config Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.buildconfigs.update().catch((err) => { + t.equal(err.message, 'Build Config Name is required', 'error message should return'); + t.end(); }); }); }); test('remove - buildconfigs - basic removeAll', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.buildconfigs.removeAll, 'function', 'There is a removeAll method on the buildconfigs object'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.buildconfigs.removeAll, 'function', 'There is a removeAll method on the buildconfigs object'); - const clientConfig = privates.get(client).config; + const clientConfig = privates.get(client).config; - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .delete(`/oapi/v1/namespaces/${clientConfig.context.namespace}/buildconfigs`) - .reply(200, {kind: 'Status'}); + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .delete(`/oapi/v1/namespaces/${clientConfig.context.namespace}/buildconfigs`) + .reply(200, {kind: 'Status'}); - const removeResult = client.buildconfigs.removeAll().then((buildConfigList) => { - t.equal(buildConfigList.kind, 'Status', 'returns an object with Status'); - t.end(); - }); - - t.equal(removeResult instanceof Promise, true, 'should return a Promise'); + const removeResult = client.buildconfigs.removeAll().then((buildConfigList) => { + t.equal(buildConfigList.kind, 'Status', 'returns an object with Status'); + t.end(); }); + + t.equal(removeResult instanceof Promise, true, 'should return a Promise'); }); }); test('remove - buildconfigs - basic remove', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.buildconfigs.remove, 'function', 'There is a remove method on the buildconfigs object'); - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.buildconfigs.remove, 'function', 'There is a remove method on the buildconfigs object'); + const clientConfig = privates.get(client).config; + const buildConfigName = 'cool-buildconfig-name-1'; - const clientConfig = privates.get(client).config; - const buildConfigName = 'cool-buildconfig-name-1'; + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .delete(`/oapi/v1/namespaces/${clientConfig.context.namespace}/buildconfigs/${buildConfigName}`) + .reply(200, {kind: 'Status'}); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .delete(`/oapi/v1/namespaces/${clientConfig.context.namespace}/buildconfigs/${buildConfigName}`) - .reply(200, {kind: 'Status'}); - - const removeResult = client.buildconfigs.remove(buildConfigName).then((status) => { - t.equal(status.kind, 'Status', 'returns an object with Status'); - t.end(); - }); - - t.equal(removeResult instanceof Promise, true, 'should return a Promise'); + const removeResult = client.buildconfigs.remove(buildConfigName).then((status) => { + t.equal(status.kind, 'Status', 'returns an object with Status'); + t.end(); }); + + t.equal(removeResult instanceof Promise, true, 'should return a Promise'); }); }); test('remove - buildconfigs - remove - no buildconfig name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.buildconfigs.remove().catch((err) => { - t.equal(err.message, 'Build Config Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.buildconfigs.remove().catch((err) => { + t.equal(err.message, 'Build Config Name is required', 'error message should return'); + t.end(); }); }); }); diff --git a/test/build-test.js b/test/build-test.js index 54d164d..a7cafc4 100644 --- a/test/build-test.js +++ b/test/build-test.js @@ -4,215 +4,171 @@ const test = require('tape'); const nock = require('nock'); const openshiftRestClient = require('../'); -const openshiftConfigLoader = require('openshift-config-loader'); const privates = require('../lib/private-map'); -test('find - builds - basic findAll', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.builds.findAll, 'function', 'There is a findAll method on the builds object'); +const settings = { + config: { + apiVersion: 'v1', + context: + { cluster: '192-168-99-100:8443', + namespace: 'for-node-client-testing', + user: 'developer/192-168-99-100:8443' }, + user: { token: 'zVBd1ZFeJqEAILJgimm4-gZJauaw3PW4EVqV_peEZ3U' }, + cluster: 'https://192.168.99.100:8443' } +}; - const clientConfig = privates.get(client).config; +test('find - builds - basic findAll', (t) => { + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.builds.findAll, 'function', 'There is a findAll method on the builds object'); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .get(`/oapi/v1/namespaces/${clientConfig.context.namespace}/builds`) - .reply(200, {kind: 'BuildList'}); + const clientConfig = privates.get(client).config; - const findResult = client.builds.findAll().then((buildList) => { - t.equal(buildList.kind, 'BuildList', 'returns an object with BuildList'); - t.end(); - }); + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .get(`/oapi/v1/namespaces/${clientConfig.context.namespace}/builds`) + .reply(200, {kind: 'BuildList'}); - t.equal(findResult instanceof Promise, true, 'should return a Promise'); + const findResult = client.builds.findAll().then((buildList) => { + t.equal(buildList.kind, 'BuildList', 'returns an object with BuildList'); + t.end(); }); + + t.equal(findResult instanceof Promise, true, 'should return a Promise'); }); }); test('find - builds - basic find', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.builds.find, 'function', 'There is a find method on the builds object'); - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.builds.find, 'function', 'There is a find method on the builds object'); + const clientConfig = privates.get(client).config; + const buildName = 'cool-build-name-1'; - const clientConfig = privates.get(client).config; - const buildName = 'cool-build-name-1'; + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .get(`/oapi/v1/namespaces/${clientConfig.context.namespace}/builds/${buildName}`) + .reply(200, {kind: 'Build'}); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .get(`/oapi/v1/namespaces/${clientConfig.context.namespace}/builds/${buildName}`) - .reply(200, {kind: 'Build'}); - - const findResult = client.builds.find(buildName).then((build) => { - t.equal(build.kind, 'Build', 'returns an object with Build'); - t.end(); - }); - - t.equal(findResult instanceof Promise, true, 'should return a Promise'); + const findResult = client.builds.find(buildName).then((build) => { + t.equal(build.kind, 'Build', 'returns an object with Build'); + t.end(); }); + + t.equal(findResult instanceof Promise, true, 'should return a Promise'); }); }); test('find - builds - find - no build name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.builds.find().catch((err) => { - t.equal(err.message, 'Build Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.builds.find().catch((err) => { + t.equal(err.message, 'Build Name is required', 'error message should return'); + t.end(); }); }); }); test('create - build', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.builds.create, 'function', 'There is a create method on the builds object'); - - const clientConfig = privates.get(client).config; - const build = { - kind: 'Build' - }; - - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .post(`/oapi/v1/namespaces/${clientConfig.context.namespace}/builds`) - .reply(200, {kind: 'Build'}); - - const createResult = client.builds.create(build).then((build) => { - t.equal(build.kind, 'Build', 'returns an object with Build'); - t.end(); - }); - - t.equal(createResult instanceof Promise, true, 'should return a Promise'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.builds.create, 'function', 'There is a create method on the builds object'); + + const clientConfig = privates.get(client).config; + const build = { + kind: 'Build' + }; + + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .post(`/oapi/v1/namespaces/${clientConfig.context.namespace}/builds`) + .reply(200, {kind: 'Build'}); + + const createResult = client.builds.create(build).then((build) => { + t.equal(build.kind, 'Build', 'returns an object with Build'); + t.end(); }); + + t.equal(createResult instanceof Promise, true, 'should return a Promise'); }); }); test('update - build', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.builds.create, 'function', 'There is a create method on the builds object'); - - const clientConfig = privates.get(client).config; - const build = { - kind: 'Build' - }; - const buildName = 'cool-build-name-1'; - - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .put(`/oapi/v1/namespaces/${clientConfig.context.namespace}/builds/${buildName}`) - .reply(200, {kind: 'Build'}); - - const createResult = client.builds.update(buildName, build).then((build) => { - t.equal(build.kind, 'Build', 'returns an object with Build'); - t.end(); - }); - - t.equal(createResult instanceof Promise, true, 'should return a Promise'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.builds.create, 'function', 'There is a create method on the builds object'); + + const clientConfig = privates.get(client).config; + const build = { + kind: 'Build' + }; + const buildName = 'cool-build-name-1'; + + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .put(`/oapi/v1/namespaces/${clientConfig.context.namespace}/builds/${buildName}`) + .reply(200, {kind: 'Build'}); + + const createResult = client.builds.update(buildName, build).then((build) => { + t.equal(build.kind, 'Build', 'returns an object with Build'); + t.end(); }); + + t.equal(createResult instanceof Promise, true, 'should return a Promise'); }); }); test('update - builds - update - no build name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.builds.update().catch((err) => { - t.equal(err.message, 'Build Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.builds.update().catch((err) => { + t.equal(err.message, 'Build Name is required', 'error message should return'); + t.end(); }); }); }); test('remove - builds - basic removeAll', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.builds.removeAll, 'function', 'There is a removeAll method on the builds object'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.builds.removeAll, 'function', 'There is a removeAll method on the builds object'); - const clientConfig = privates.get(client).config; + const clientConfig = privates.get(client).config; - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .delete(`/oapi/v1/namespaces/${clientConfig.context.namespace}/builds`) - .reply(200, {kind: 'Status'}); + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .delete(`/oapi/v1/namespaces/${clientConfig.context.namespace}/builds`) + .reply(200, {kind: 'Status'}); - const removeResult = client.builds.removeAll().then((buildList) => { - t.equal(buildList.kind, 'Status', 'returns an object with Status'); - t.end(); - }); - - t.equal(removeResult instanceof Promise, true, 'should return a Promise'); + const removeResult = client.builds.removeAll().then((buildList) => { + t.equal(buildList.kind, 'Status', 'returns an object with Status'); + t.end(); }); + + t.equal(removeResult instanceof Promise, true, 'should return a Promise'); }); }); test('remove - builds - basic remove', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.builds.remove, 'function', 'There is a remove method on the builds object'); - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.builds.remove, 'function', 'There is a remove method on the builds object'); + const clientConfig = privates.get(client).config; + const buildName = 'cool-build-name-1'; - const clientConfig = privates.get(client).config; - const buildName = 'cool-build-name-1'; + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .delete(`/oapi/v1/namespaces/${clientConfig.context.namespace}/builds/${buildName}`) + .reply(200, {kind: 'Status'}); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .delete(`/oapi/v1/namespaces/${clientConfig.context.namespace}/builds/${buildName}`) - .reply(200, {kind: 'Status'}); - - const removeResult = client.builds.remove(buildName).then((status) => { - t.equal(status.kind, 'Status', 'returns an object with Status'); - t.end(); - }); - - t.equal(removeResult instanceof Promise, true, 'should return a Promise'); + const removeResult = client.builds.remove(buildName).then((status) => { + t.equal(status.kind, 'Status', 'returns an object with Status'); + t.end(); }); + + t.equal(removeResult instanceof Promise, true, 'should return a Promise'); }); }); test('remove - builds - remove - no build name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.builds.remove().catch((err) => { - t.equal(err.message, 'Build Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.builds.remove().catch((err) => { + t.equal(err.message, 'Build Name is required', 'error message should return'); + t.end(); }); }); }); diff --git a/test/cluster-role-binding-test.js b/test/cluster-role-binding-test.js index 65470d2..33795a4 100644 --- a/test/cluster-role-binding-test.js +++ b/test/cluster-role-binding-test.js @@ -4,144 +4,118 @@ const test = require('tape'); const nock = require('nock'); const openshiftRestClient = require('../'); -const openshiftConfigLoader = require('openshift-config-loader'); const privates = require('../lib/private-map'); -test('find - clusterrolebindings - basic findAll', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.clusterrolebindings.findAll, 'function', 'There is a findAll method on the clusterrolebindings object'); +const settings = { + config: { + apiVersion: 'v1', + context: + { cluster: '192-168-99-100:8443', + namespace: 'for-node-client-testing', + user: 'developer/192-168-99-100:8443' }, + user: { token: 'zVBd1ZFeJqEAILJgimm4-gZJauaw3PW4EVqV_peEZ3U' }, + cluster: 'https://192.168.99.100:8443' } +}; - const clientConfig = privates.get(client).config; +test('find - clusterrolebindings - basic findAll', (t) => { + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.clusterrolebindings.findAll, 'function', 'There is a findAll method on the clusterrolebindings object'); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .get(`/oapi/v1/clusterrolebindings`) - .reply(200, {kind: 'ClusterRoleBindingList'}); + const clientConfig = privates.get(client).config; - const findResult = client.clusterrolebindings.findAll().then((clusterRoleBindingList) => { - t.equal(clusterRoleBindingList.kind, 'ClusterRoleBindingList', 'returns an object with ClusterRoleBindingList'); - t.end(); - }); + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .get(`/oapi/v1/clusterrolebindings`) + .reply(200, {kind: 'ClusterRoleBindingList'}); - t.equal(findResult instanceof Promise, true, 'should return a Promise'); + const findResult = client.clusterrolebindings.findAll().then((clusterRoleBindingList) => { + t.equal(clusterRoleBindingList.kind, 'ClusterRoleBindingList', 'returns an object with ClusterRoleBindingList'); + t.end(); }); + + t.equal(findResult instanceof Promise, true, 'should return a Promise'); }); }); test('find - clusterrolebindings - basic find', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.clusterrolebindings.find, 'function', 'There is a find method on the clusterrolebindings object'); - - const clientConfig = privates.get(client).config; - const clusterRoleBindingName = 'cool-clusterrolebinding-name-1'; + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.clusterrolebindings.find, 'function', 'There is a find method on the clusterrolebindings object'); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .get(`/oapi/v1/clusterrolebindings/${clusterRoleBindingName}`) - .reply(200, {kind: 'ClusterRoleBinding'}); + const clientConfig = privates.get(client).config; + const clusterRoleBindingName = 'cool-clusterrolebinding-name-1'; - const findResult = client.clusterrolebindings.find(clusterRoleBindingName).then((clusterrolebinding) => { - t.equal(clusterrolebinding.kind, 'ClusterRoleBinding', 'returns an object with ClusterRoleBinding'); - t.end(); - }); + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .get(`/oapi/v1/clusterrolebindings/${clusterRoleBindingName}`) + .reply(200, {kind: 'ClusterRoleBinding'}); - t.equal(findResult instanceof Promise, true, 'should return a Promise'); + const findResult = client.clusterrolebindings.find(clusterRoleBindingName).then((clusterrolebinding) => { + t.equal(clusterrolebinding.kind, 'ClusterRoleBinding', 'returns an object with ClusterRoleBinding'); + t.end(); }); + + t.equal(findResult instanceof Promise, true, 'should return a Promise'); }); }); test('find - clusterrolebindings - find - no clusterrolebinding name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.clusterrolebindings.find().catch((err) => { - t.equal(err.message, 'Cluster Role Binding Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.clusterrolebindings.find().catch((err) => { + t.equal(err.message, 'Cluster Role Binding Name is required', 'error message should return'); + t.end(); }); }); }); test('create - clusterrolebinding', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.clusterrolebindings.create, 'function', 'There is a create method on the clusterrolebindings object'); - - const clientConfig = privates.get(client).config; - const clusterrolebinding = { - kind: 'ClusterRoleBinding' - }; - - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .post(`/oapi/v1/clusterrolebindings`) - .reply(200, {kind: 'ClusterRoleBinding'}); - - const createResult = client.clusterrolebindings.create(clusterrolebinding).then((clusterrolebinding) => { - t.equal(clusterrolebinding.kind, 'ClusterRoleBinding', 'returns an object with ClusterRoleBinding'); - t.end(); - }); - - t.equal(createResult instanceof Promise, true, 'should return a Promise'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.clusterrolebindings.create, 'function', 'There is a create method on the clusterrolebindings object'); + + const clientConfig = privates.get(client).config; + const clusterrolebinding = { + kind: 'ClusterRoleBinding' + }; + + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .post(`/oapi/v1/clusterrolebindings`) + .reply(200, {kind: 'ClusterRoleBinding'}); + + const createResult = client.clusterrolebindings.create(clusterrolebinding).then((clusterrolebinding) => { + t.equal(clusterrolebinding.kind, 'ClusterRoleBinding', 'returns an object with ClusterRoleBinding'); + t.end(); }); + + t.equal(createResult instanceof Promise, true, 'should return a Promise'); }); }); test('remove - clusterrolebindings - basic remove', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.clusterrolebindings.remove, 'function', 'There is a remove method on the clusterrolebindings object'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.clusterrolebindings.remove, 'function', 'There is a remove method on the clusterrolebindings object'); - const clientConfig = privates.get(client).config; - const clusterRoleBindingName = 'cool-clusterrolebinding-name-1'; + const clientConfig = privates.get(client).config; + const clusterRoleBindingName = 'cool-clusterrolebinding-name-1'; - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .delete(`/oapi/v1/clusterrolebindings/${clusterRoleBindingName}`) - .reply(200, {kind: 'Status'}); + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .delete(`/oapi/v1/clusterrolebindings/${clusterRoleBindingName}`) + .reply(200, {kind: 'Status'}); - const removeResult = client.clusterrolebindings.remove(clusterRoleBindingName).then((status) => { - t.equal(status.kind, 'Status', 'returns an object with Status'); - t.end(); - }); - - t.equal(removeResult instanceof Promise, true, 'should return a Promise'); + const removeResult = client.clusterrolebindings.remove(clusterRoleBindingName).then((status) => { + t.equal(status.kind, 'Status', 'returns an object with Status'); + t.end(); }); + + t.equal(removeResult instanceof Promise, true, 'should return a Promise'); }); }); test('remove - clusterrolebindings - remove - no clusterrolebinding name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.clusterrolebindings.remove().catch((err) => { - t.equal(err.message, 'Cluster Role Binding Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.clusterrolebindings.remove().catch((err) => { + t.equal(err.message, 'Cluster Role Binding Name is required', 'error message should return'); + t.end(); }); }); }); diff --git a/test/config-loader-test.js b/test/config-loader-test.js index b895363..3ad0c30 100644 --- a/test/config-loader-test.js +++ b/test/config-loader-test.js @@ -2,37 +2,92 @@ const test = require('tape'); const privates = require('../lib/private-map'); -const openshiftConfigLoader = require('openshift-config-loader'); +const proxyquire = require('proxyquire'); -test('test loading config', (t) => { - const openshiftRestClient = require('../'); - const settings = { - configLocation: `${__dirname}/test-config` +test('test loading config as settings', (t) => { + const configLoader = proxyquire('../lib/config-loader', { + 'openshift-config-loader': () => { + t.fail('should not call this method'); + return Promise.reject(new Error('reject')); + } + }); + t.plan(7); + const client = { + settings: { + config: { + apiVersion: 'v1', + context: + { cluster: '192-168-99-100:8443', + namespace: 'for-node-client-testing', + user: 'developer/192-168-99-100:8443' }, + user: { token: 'zVBd1ZFeJqEAILJgimm4-gZJauaw3PW4EVqV_peEZ3U' }, + cluster: 'https://192.168.99.100:8443' } + } }; - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equals(client.apiUrl, 'https://192.168.99.100:8443/oapi/v1', 'apiUrl should be https://192.168.99.100:8443/oapi/v1'); - t.equals(client.kubeUrl, 'https://192.168.99.100:8443/api/v1', 'kubeUrl should be https://192.168.99.100:8443/api/v1'); - const clientConfig = privates.get(client).config; - // context cluster object - t.ok(clientConfig.context.cluster, 'should have the context cluster prop'); - t.ok(clientConfig.context.namespace, 'should have the context namespace prop'); - t.ok(clientConfig.context.user, 'should have the context user prop'); - - // context user object - t.ok(clientConfig.user.token, 'should have the user token prop'); - t.ok(clientConfig.cluster, 'should have the cluster prop'); - t.end(); - }); + privates.set(client, {}); + + configLoader(client).then((config) => { + t.equals(config.apiUrl, 'https://192.168.99.100:8443/oapi/v1', 'apiUrl should be https://192.168.99.100:8443/oapi/v1'); + t.equals(config.kubeUrl, 'https://192.168.99.100:8443/api/v1', 'kubeUrl should be https://192.168.99.100:8443/api/v1'); + const clientConfig = privates.get(client).config; + // context cluster object + t.ok(clientConfig.context.cluster, 'should have the context cluster prop'); + t.ok(clientConfig.context.namespace, 'should have the context namespace prop'); + t.ok(clientConfig.context.user, 'should have the context user prop'); + + // context user object + t.ok(clientConfig.user.token, 'should have the user token prop'); + t.ok(clientConfig.cluster, 'should have the cluster prop'); + t.end(); }); }); -test('test loading of config, error', (t) => { - const openshiftRestClient = require('../'); +test('test loading config - default', (t) => { + const configLoader = proxyquire('../lib/config-loader', { + 'openshift-config-loader': () => { + t.pass('default should call this method'); + return Promise.resolve({ + apiVersion: 'v1', + context: + { cluster: '192-168-99-100:8443', + namespace: 'for-node-client-testing', + user: 'developer/192-168-99-100:8443' }, + user: { token: 'zVBd1ZFeJqEAILJgimm4-gZJauaw3PW4EVqV_peEZ3U' }, + cluster: 'https://192.168.99.100:8443' + }); + } + }); + + t.plan(8); - openshiftRestClient().catch((err) => { - t.equal(err.message, 'Config object is require', 'Should throw an error for not finding the config file'); + const client = { + settings: {} + }; + + privates.set(client, {}); + + configLoader(client).then((config) => { + t.equals(config.apiUrl, 'https://192.168.99.100:8443/oapi/v1', 'apiUrl should be https://192.168.99.100:8443/oapi/v1'); + t.equals(config.kubeUrl, 'https://192.168.99.100:8443/api/v1', 'kubeUrl should be https://192.168.99.100:8443/api/v1'); + const clientConfig = privates.get(client).config; + // context cluster object + t.ok(clientConfig.context.cluster, 'should have the context cluster prop'); + t.ok(clientConfig.context.namespace, 'should have the context namespace prop'); + t.ok(clientConfig.context.user, 'should have the context user prop'); + + // context user object + t.ok(clientConfig.user.token, 'should have the user token prop'); + t.ok(clientConfig.cluster, 'should have the cluster prop'); t.end(); }); }); + +// test('test loading of config, error', (t) => { +// const openshiftRestClient = require('../'); + +// openshiftRestClient().catch((err) => { +// t.equal(err.message, 'Config object is require', 'Should throw an error for not finding the config file'); +// t.end(); +// }); +// }); diff --git a/test/configmaps-test.js b/test/configmaps-test.js index a8a89ab..196e20b 100644 --- a/test/configmaps-test.js +++ b/test/configmaps-test.js @@ -4,215 +4,171 @@ const test = require('tape'); const nock = require('nock'); const openshiftRestClient = require('../'); -const openshiftConfigLoader = require('openshift-config-loader'); const privates = require('../lib/private-map'); -test('find - configmaps - basic findAll', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.configmaps.findAll, 'function', 'There is a findAll method on the configmaps object'); +const settings = { + config: { + apiVersion: 'v1', + context: + { cluster: '192-168-99-100:8443', + namespace: 'for-node-client-testing', + user: 'developer/192-168-99-100:8443' }, + user: { token: 'zVBd1ZFeJqEAILJgimm4-gZJauaw3PW4EVqV_peEZ3U' }, + cluster: 'https://192.168.99.100:8443' } +}; - const clientConfig = privates.get(client).config; +test('find - configmaps - basic findAll', (t) => { + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.configmaps.findAll, 'function', 'There is a findAll method on the configmaps object'); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .get(`/api/v1/namespaces/${clientConfig.context.namespace}/configmaps`) - .reply(200, {kind: 'ConfigMapList'}); + const clientConfig = privates.get(client).config; - const findResult = client.configmaps.findAll().then((configMapList) => { - t.equal(configMapList.kind, 'ConfigMapList', 'returns an object with ConfigMapList'); - t.end(); - }); + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .get(`/api/v1/namespaces/${clientConfig.context.namespace}/configmaps`) + .reply(200, {kind: 'ConfigMapList'}); - t.equal(findResult instanceof Promise, true, 'should return a Promise'); + const findResult = client.configmaps.findAll().then((configMapList) => { + t.equal(configMapList.kind, 'ConfigMapList', 'returns an object with ConfigMapList'); + t.end(); }); + + t.equal(findResult instanceof Promise, true, 'should return a Promise'); }); }); test('find - configmaps - basic find', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.configmaps.find, 'function', 'There is a find method on the configmaps object'); - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.configmaps.find, 'function', 'There is a find method on the configmaps object'); + const clientConfig = privates.get(client).config; + const configMapName = 'cool-configmap-name-1'; - const clientConfig = privates.get(client).config; - const configMapName = 'cool-configmap-name-1'; + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .get(`/api/v1/namespaces/${clientConfig.context.namespace}/configmaps/${configMapName}`) + .reply(200, {kind: 'ConfigMap'}); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .get(`/api/v1/namespaces/${clientConfig.context.namespace}/configmaps/${configMapName}`) - .reply(200, {kind: 'ConfigMap'}); - - const findResult = client.configmaps.find(configMapName).then((configmap) => { - t.equal(configmap.kind, 'ConfigMap', 'returns an object with ConfigMap'); - t.end(); - }); - - t.equal(findResult instanceof Promise, true, 'should return a Promise'); + const findResult = client.configmaps.find(configMapName).then((configmap) => { + t.equal(configmap.kind, 'ConfigMap', 'returns an object with ConfigMap'); + t.end(); }); + + t.equal(findResult instanceof Promise, true, 'should return a Promise'); }); }); test('find - configmaps - find - no configmap name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.configmaps.find().catch((err) => { - t.equal(err.message, 'Config Map Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.configmaps.find().catch((err) => { + t.equal(err.message, 'Config Map Name is required', 'error message should return'); + t.end(); }); }); }); test('create - configmap', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.configmaps.create, 'function', 'There is a create method on the configmaps object'); - - const clientConfig = privates.get(client).config; - const configmap = { - kind: 'ConfigMap' - }; - - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .post(`/api/v1/namespaces/${clientConfig.context.namespace}/configmaps`) - .reply(200, {kind: 'ConfigMap'}); - - const createResult = client.configmaps.create(configmap).then((configmap) => { - t.equal(configmap.kind, 'ConfigMap', 'returns an object with ConfigMap'); - t.end(); - }); - - t.equal(createResult instanceof Promise, true, 'should return a Promise'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.configmaps.create, 'function', 'There is a create method on the configmaps object'); + + const clientConfig = privates.get(client).config; + const configmap = { + kind: 'ConfigMap' + }; + + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .post(`/api/v1/namespaces/${clientConfig.context.namespace}/configmaps`) + .reply(200, {kind: 'ConfigMap'}); + + const createResult = client.configmaps.create(configmap).then((configmap) => { + t.equal(configmap.kind, 'ConfigMap', 'returns an object with ConfigMap'); + t.end(); }); + + t.equal(createResult instanceof Promise, true, 'should return a Promise'); }); }); test('update - configmap', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.configmaps.create, 'function', 'There is a create method on the configmaps object'); - - const clientConfig = privates.get(client).config; - const configmap = { - kind: 'ConfigMap' - }; - const configMapName = 'cool-configmap-name-1'; - - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .put(`/api/v1/namespaces/${clientConfig.context.namespace}/configmaps/${configMapName}`) - .reply(200, {kind: 'ConfigMap'}); - - const createResult = client.configmaps.update(configMapName, configmap).then((configmap) => { - t.equal(configmap.kind, 'ConfigMap', 'returns an object with ConfigMap'); - t.end(); - }); - - t.equal(createResult instanceof Promise, true, 'should return a Promise'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.configmaps.create, 'function', 'There is a create method on the configmaps object'); + + const clientConfig = privates.get(client).config; + const configmap = { + kind: 'ConfigMap' + }; + const configMapName = 'cool-configmap-name-1'; + + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .put(`/api/v1/namespaces/${clientConfig.context.namespace}/configmaps/${configMapName}`) + .reply(200, {kind: 'ConfigMap'}); + + const createResult = client.configmaps.update(configMapName, configmap).then((configmap) => { + t.equal(configmap.kind, 'ConfigMap', 'returns an object with ConfigMap'); + t.end(); }); + + t.equal(createResult instanceof Promise, true, 'should return a Promise'); }); }); test('update - configmaps - update - no configmap name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.configmaps.update().catch((err) => { - t.equal(err.message, 'Config Map Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.configmaps.update().catch((err) => { + t.equal(err.message, 'Config Map Name is required', 'error message should return'); + t.end(); }); }); }); test('remove - configmaps - basic removeAll', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.configmaps.removeAll, 'function', 'There is a removeAll method on the configmaps object'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.configmaps.removeAll, 'function', 'There is a removeAll method on the configmaps object'); - const clientConfig = privates.get(client).config; + const clientConfig = privates.get(client).config; - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .delete(`/api/v1/namespaces/${clientConfig.context.namespace}/configmaps`) - .reply(200, {kind: 'Status'}); + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .delete(`/api/v1/namespaces/${clientConfig.context.namespace}/configmaps`) + .reply(200, {kind: 'Status'}); - const removeResult = client.configmaps.removeAll().then((configMapList) => { - t.equal(configMapList.kind, 'Status', 'returns an object with Status'); - t.end(); - }); - - t.equal(removeResult instanceof Promise, true, 'should return a Promise'); + const removeResult = client.configmaps.removeAll().then((configMapList) => { + t.equal(configMapList.kind, 'Status', 'returns an object with Status'); + t.end(); }); + + t.equal(removeResult instanceof Promise, true, 'should return a Promise'); }); }); test('remove - configmaps - basic remove', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.configmaps.remove, 'function', 'There is a remove method on the configmaps object'); - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.configmaps.remove, 'function', 'There is a remove method on the configmaps object'); + const clientConfig = privates.get(client).config; + const configMapName = 'cool-configmap-name-1'; - const clientConfig = privates.get(client).config; - const configMapName = 'cool-configmap-name-1'; + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .delete(`/api/v1/namespaces/${clientConfig.context.namespace}/configmaps/${configMapName}`) + .reply(200, {kind: 'Status'}); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .delete(`/api/v1/namespaces/${clientConfig.context.namespace}/configmaps/${configMapName}`) - .reply(200, {kind: 'Status'}); - - const removeResult = client.configmaps.remove(configMapName).then((status) => { - t.equal(status.kind, 'Status', 'returns an object with Status'); - t.end(); - }); - - t.equal(removeResult instanceof Promise, true, 'should return a Promise'); + const removeResult = client.configmaps.remove(configMapName).then((status) => { + t.equal(status.kind, 'Status', 'returns an object with Status'); + t.end(); }); + + t.equal(removeResult instanceof Promise, true, 'should return a Promise'); }); }); test('remove - configmaps - remove - no configmap name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.configmaps.remove().catch((err) => { - t.equal(err.message, 'Config Map Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.configmaps.remove().catch((err) => { + t.equal(err.message, 'Config Map Name is required', 'error message should return'); + t.end(); }); }); }); diff --git a/test/deployment-config-test.js b/test/deployment-config-test.js index e041004..fddac9c 100644 --- a/test/deployment-config-test.js +++ b/test/deployment-config-test.js @@ -4,215 +4,171 @@ const test = require('tape'); const nock = require('nock'); const openshiftRestClient = require('../'); -const openshiftConfigLoader = require('openshift-config-loader'); const privates = require('../lib/private-map'); -test('find - deploymentconfigs - basic findAll', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.deploymentconfigs.findAll, 'function', 'There is a findAll method on the deploymentconfigs object'); +const settings = { + config: { + apiVersion: 'v1', + context: + { cluster: '192-168-99-100:8443', + namespace: 'for-node-client-testing', + user: 'developer/192-168-99-100:8443' }, + user: { token: 'zVBd1ZFeJqEAILJgimm4-gZJauaw3PW4EVqV_peEZ3U' }, + cluster: 'https://192.168.99.100:8443' } +}; - const clientConfig = privates.get(client).config; +test('find - deploymentconfigs - basic findAll', (t) => { + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.deploymentconfigs.findAll, 'function', 'There is a findAll method on the deploymentconfigs object'); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .get(`/oapi/v1/namespaces/${clientConfig.context.namespace}/deploymentconfigs`) - .reply(200, {kind: 'DeploymentConfigList'}); + const clientConfig = privates.get(client).config; - const findResult = client.deploymentconfigs.findAll().then((deploymentConfigList) => { - t.equal(deploymentConfigList.kind, 'DeploymentConfigList', 'returns an object with DeploymentConfigList'); - t.end(); - }); + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .get(`/oapi/v1/namespaces/${clientConfig.context.namespace}/deploymentconfigs`) + .reply(200, {kind: 'DeploymentConfigList'}); - t.equal(findResult instanceof Promise, true, 'should return a Promise'); + const findResult = client.deploymentconfigs.findAll().then((deploymentConfigList) => { + t.equal(deploymentConfigList.kind, 'DeploymentConfigList', 'returns an object with DeploymentConfigList'); + t.end(); }); + + t.equal(findResult instanceof Promise, true, 'should return a Promise'); }); }); test('find - deploymentconfigs - basic find', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.deploymentconfigs.find, 'function', 'There is a find method on the deploymentconfigs object'); - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.deploymentconfigs.find, 'function', 'There is a find method on the deploymentconfigs object'); + const clientConfig = privates.get(client).config; + const deploymentConfigName = 'cool-deploymentconfig-name-1'; - const clientConfig = privates.get(client).config; - const deploymentConfigName = 'cool-deploymentconfig-name-1'; + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .get(`/oapi/v1/namespaces/${clientConfig.context.namespace}/deploymentconfigs/${deploymentConfigName}`) + .reply(200, {kind: 'DeploymentConfig'}); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .get(`/oapi/v1/namespaces/${clientConfig.context.namespace}/deploymentconfigs/${deploymentConfigName}`) - .reply(200, {kind: 'DeploymentConfig'}); - - const findResult = client.deploymentconfigs.find(deploymentConfigName).then((deploymentconfig) => { - t.equal(deploymentconfig.kind, 'DeploymentConfig', 'returns an object with DeploymentConfig'); - t.end(); - }); - - t.equal(findResult instanceof Promise, true, 'should return a Promise'); + const findResult = client.deploymentconfigs.find(deploymentConfigName).then((deploymentconfig) => { + t.equal(deploymentconfig.kind, 'DeploymentConfig', 'returns an object with DeploymentConfig'); + t.end(); }); + + t.equal(findResult instanceof Promise, true, 'should return a Promise'); }); }); test('find - deploymentconfigs - find - no deploymentconfig name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.deploymentconfigs.find().catch((err) => { - t.equal(err.message, 'Deployment Config Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.deploymentconfigs.find().catch((err) => { + t.equal(err.message, 'Deployment Config Name is required', 'error message should return'); + t.end(); }); }); }); test('create - deploymentconfig', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.deploymentconfigs.create, 'function', 'There is a create method on the deploymentconfigs object'); - - const clientConfig = privates.get(client).config; - const deploymentconfig = { - kind: 'DeploymentConfig' - }; - - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .post(`/oapi/v1/namespaces/${clientConfig.context.namespace}/deploymentconfigs`) - .reply(200, {kind: 'DeploymentConfig'}); - - const createResult = client.deploymentconfigs.create(deploymentconfig).then((deploymentconfig) => { - t.equal(deploymentconfig.kind, 'DeploymentConfig', 'returns an object with DeploymentConfig'); - t.end(); - }); - - t.equal(createResult instanceof Promise, true, 'should return a Promise'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.deploymentconfigs.create, 'function', 'There is a create method on the deploymentconfigs object'); + + const clientConfig = privates.get(client).config; + const deploymentconfig = { + kind: 'DeploymentConfig' + }; + + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .post(`/oapi/v1/namespaces/${clientConfig.context.namespace}/deploymentconfigs`) + .reply(200, {kind: 'DeploymentConfig'}); + + const createResult = client.deploymentconfigs.create(deploymentconfig).then((deploymentconfig) => { + t.equal(deploymentconfig.kind, 'DeploymentConfig', 'returns an object with DeploymentConfig'); + t.end(); }); + + t.equal(createResult instanceof Promise, true, 'should return a Promise'); }); }); test('update - deploymentconfig', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.deploymentconfigs.create, 'function', 'There is a create method on the deploymentconfigs object'); - - const clientConfig = privates.get(client).config; - const deploymentconfig = { - kind: 'DeploymentConfig' - }; - const deploymentConfigName = 'cool-deploymentconfig-name-1'; - - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .put(`/oapi/v1/namespaces/${clientConfig.context.namespace}/deploymentconfigs/${deploymentConfigName}`) - .reply(200, {kind: 'DeploymentConfig'}); - - const createResult = client.deploymentconfigs.update(deploymentConfigName, deploymentconfig).then((deploymentconfig) => { - t.equal(deploymentconfig.kind, 'DeploymentConfig', 'returns an object with DeploymentConfig'); - t.end(); - }); - - t.equal(createResult instanceof Promise, true, 'should return a Promise'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.deploymentconfigs.create, 'function', 'There is a create method on the deploymentconfigs object'); + + const clientConfig = privates.get(client).config; + const deploymentconfig = { + kind: 'DeploymentConfig' + }; + const deploymentConfigName = 'cool-deploymentconfig-name-1'; + + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .put(`/oapi/v1/namespaces/${clientConfig.context.namespace}/deploymentconfigs/${deploymentConfigName}`) + .reply(200, {kind: 'DeploymentConfig'}); + + const createResult = client.deploymentconfigs.update(deploymentConfigName, deploymentconfig).then((deploymentconfig) => { + t.equal(deploymentconfig.kind, 'DeploymentConfig', 'returns an object with DeploymentConfig'); + t.end(); }); + + t.equal(createResult instanceof Promise, true, 'should return a Promise'); }); }); test('update - deploymentconfigs - update - no deploymentconfig name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.deploymentconfigs.update().catch((err) => { - t.equal(err.message, 'Deployment Config Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.deploymentconfigs.update().catch((err) => { + t.equal(err.message, 'Deployment Config Name is required', 'error message should return'); + t.end(); }); }); }); test('remove - deploymentconfigs - basic removeAll', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.deploymentconfigs.removeAll, 'function', 'There is a removeAll method on the deploymentconfigs object'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.deploymentconfigs.removeAll, 'function', 'There is a removeAll method on the deploymentconfigs object'); - const clientConfig = privates.get(client).config; + const clientConfig = privates.get(client).config; - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .delete(`/oapi/v1/namespaces/${clientConfig.context.namespace}/deploymentconfigs`) - .reply(200, {kind: 'Status'}); + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .delete(`/oapi/v1/namespaces/${clientConfig.context.namespace}/deploymentconfigs`) + .reply(200, {kind: 'Status'}); - const removeResult = client.deploymentconfigs.removeAll().then((deploymentConfigList) => { - t.equal(deploymentConfigList.kind, 'Status', 'returns an object with Status'); - t.end(); - }); - - t.equal(removeResult instanceof Promise, true, 'should return a Promise'); + const removeResult = client.deploymentconfigs.removeAll().then((deploymentConfigList) => { + t.equal(deploymentConfigList.kind, 'Status', 'returns an object with Status'); + t.end(); }); + + t.equal(removeResult instanceof Promise, true, 'should return a Promise'); }); }); test('remove - deploymentconfigs - basic remove', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.deploymentconfigs.remove, 'function', 'There is a remove method on the deploymentconfigs object'); - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.deploymentconfigs.remove, 'function', 'There is a remove method on the deploymentconfigs object'); + const clientConfig = privates.get(client).config; + const deploymentConfigName = 'cool-deploymentconfig-name-1'; - const clientConfig = privates.get(client).config; - const deploymentConfigName = 'cool-deploymentconfig-name-1'; + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .delete(`/oapi/v1/namespaces/${clientConfig.context.namespace}/deploymentconfigs/${deploymentConfigName}`) + .reply(200, {kind: 'Status'}); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .delete(`/oapi/v1/namespaces/${clientConfig.context.namespace}/deploymentconfigs/${deploymentConfigName}`) - .reply(200, {kind: 'Status'}); - - const removeResult = client.deploymentconfigs.remove(deploymentConfigName).then((status) => { - t.equal(status.kind, 'Status', 'returns an object with Status'); - t.end(); - }); - - t.equal(removeResult instanceof Promise, true, 'should return a Promise'); + const removeResult = client.deploymentconfigs.remove(deploymentConfigName).then((status) => { + t.equal(status.kind, 'Status', 'returns an object with Status'); + t.end(); }); + + t.equal(removeResult instanceof Promise, true, 'should return a Promise'); }); }); test('remove - deploymentconfigs - remove - no deploymentconfig name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.deploymentconfigs.remove().catch((err) => { - t.equal(err.message, 'Deployment Config Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.deploymentconfigs.remove().catch((err) => { + t.equal(err.message, 'Deployment Config Name is required', 'error message should return'); + t.end(); }); }); }); diff --git a/test/group-test.js b/test/group-test.js index 2f4abb3..6d6b96c 100644 --- a/test/group-test.js +++ b/test/group-test.js @@ -4,216 +4,172 @@ const test = require('tape'); const nock = require('nock'); const openshiftRestClient = require('../'); -const openshiftConfigLoader = require('openshift-config-loader'); const privates = require('../lib/private-map'); -test('find - groups - basic findAll', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.groups.findAll, 'function', 'There is a findAll method on the groups object'); +const settings = { + config: { + apiVersion: 'v1', + context: + { cluster: '192-168-99-100:8443', + namespace: 'for-node-client-testing', + user: 'developer/192-168-99-100:8443' }, + user: { token: 'zVBd1ZFeJqEAILJgimm4-gZJauaw3PW4EVqV_peEZ3U' }, + cluster: 'https://192.168.99.100:8443' } +}; - const clientConfig = privates.get(client).config; +test('find - groups - basic findAll', (t) => { + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.groups.findAll, 'function', 'There is a findAll method on the groups object'); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .get(`/oapi/v1/groups`) - .reply(200, {kind: 'GroupList'}); + const clientConfig = privates.get(client).config; - const findResult = client.groups.findAll().then((groupList) => { - t.equal(groupList.kind, 'GroupList', 'returns an object with GroupList'); - t.end(); - }); + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .get(`/oapi/v1/groups`) + .reply(200, {kind: 'GroupList'}); - t.equal(findResult instanceof Promise, true, 'should return a Promise'); + const findResult = client.groups.findAll().then((groupList) => { + t.equal(groupList.kind, 'GroupList', 'returns an object with GroupList'); + t.end(); }); + + t.equal(findResult instanceof Promise, true, 'should return a Promise'); }); }); test('find - groups - basic find', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.groups.find, 'function', 'There is a find method on the groups object'); - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.groups.find, 'function', 'There is a find method on the groups object'); + const clientConfig = privates.get(client).config; + const groupName = 'cool-group-name-1'; - const clientConfig = privates.get(client).config; - const groupName = 'cool-group-name-1'; + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .get(`/oapi/v1/groups/${groupName}`) + .reply(200, {kind: 'Group'}); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .get(`/oapi/v1/groups/${groupName}`) - .reply(200, {kind: 'Group'}); - - const findResult = client.groups.find(groupName).then((group) => { - t.equal(group.kind, 'Group', 'returns an object with Group'); - t.end(); - }); - - t.equal(findResult instanceof Promise, true, 'should return a Promise'); + const findResult = client.groups.find(groupName).then((group) => { + t.equal(group.kind, 'Group', 'returns an object with Group'); + t.end(); }); + + t.equal(findResult instanceof Promise, true, 'should return a Promise'); }); }); test('find - groups - find - no group name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.groups.find().catch((err) => { - t.equal(err.message, 'Group Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.groups.find().catch((err) => { + t.equal(err.message, 'Group Name is required', 'error message should return'); + t.end(); }); }); }); test('create - group', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.groups.create, 'function', 'There is a create method on the groups object'); - - const clientConfig = privates.get(client).config; - const group = { - kind: 'Group' - }; - - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .post(`/oapi/v1/groups`) - .reply(200, {kind: 'Group'}); - - const createResult = client.groups.create(group).then((group) => { - t.equal(group.kind, 'Group', 'returns an object with Group'); - t.end(); - }); - - t.equal(createResult instanceof Promise, true, 'should return a Promise'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.groups.create, 'function', 'There is a create method on the groups object'); + + const clientConfig = privates.get(client).config; + const group = { + kind: 'Group' + }; + + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .post(`/oapi/v1/groups`) + .reply(200, {kind: 'Group'}); + + const createResult = client.groups.create(group).then((group) => { + t.equal(group.kind, 'Group', 'returns an object with Group'); + t.end(); }); + + t.equal(createResult instanceof Promise, true, 'should return a Promise'); }); }); test('update - group', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.groups.create, 'function', 'There is a create method on the groups object'); - - const clientConfig = privates.get(client).config; - const group = { - kind: 'Group' - }; - const groupName = 'cool-group-name-1'; - - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .put(`/oapi/v1/groups/${groupName}`) - .reply(200, {kind: 'Group'}); - - const createResult = client.groups.update(groupName, group).then((group) => { - t.equal(group.kind, 'Group', 'returns an object with Group'); - t.end(); - }); - - t.equal(createResult instanceof Promise, true, 'should return a Promise'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.groups.create, 'function', 'There is a create method on the groups object'); + + const clientConfig = privates.get(client).config; + const group = { + kind: 'Group' + }; + const groupName = 'cool-group-name-1'; + + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .put(`/oapi/v1/groups/${groupName}`) + .reply(200, {kind: 'Group'}); + + const createResult = client.groups.update(groupName, group).then((group) => { + t.equal(group.kind, 'Group', 'returns an object with Group'); + t.end(); }); + + t.equal(createResult instanceof Promise, true, 'should return a Promise'); }); }); test('update - groups - update - no group name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.groups.update().catch(( - err) => { - t.equal(err.message, 'Group Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.groups.update().catch(( + err) => { + t.equal(err.message, 'Group Name is required', 'error message should return'); + t.end(); }); }); }); test('remove - groups - basic removeAll', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.groups.removeAll, 'function', 'There is a removeAll method on the groups object'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.groups.removeAll, 'function', 'There is a removeAll method on the groups object'); - const clientConfig = privates.get(client).config; + const clientConfig = privates.get(client).config; - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .delete(`/oapi/v1/groups`) - .reply(200, {kind: 'Status'}); + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .delete(`/oapi/v1/groups`) + .reply(200, {kind: 'Status'}); - const removeResult = client.groups.removeAll().then((groupList) => { - t.equal(groupList.kind, 'Status', 'returns an object with Status'); - t.end(); - }); - - t.equal(removeResult instanceof Promise, true, 'should return a Promise'); + const removeResult = client.groups.removeAll().then((groupList) => { + t.equal(groupList.kind, 'Status', 'returns an object with Status'); + t.end(); }); + + t.equal(removeResult instanceof Promise, true, 'should return a Promise'); }); }); test('remove - groups - basic remove', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.groups.remove, 'function', 'There is a remove method on the groups object'); - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.groups.remove, 'function', 'There is a remove method on the groups object'); + const clientConfig = privates.get(client).config; + const groupName = 'cool-group-name-1'; - const clientConfig = privates.get(client).config; - const groupName = 'cool-group-name-1'; + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .delete(`/oapi/v1/groups/${groupName}`) + .reply(200, {kind: 'Status'}); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .delete(`/oapi/v1/groups/${groupName}`) - .reply(200, {kind: 'Status'}); - - const removeResult = client.groups.remove(groupName).then((status) => { - t.equal(status.kind, 'Status', 'returns an object with Status'); - t.end(); - }); - - t.equal(removeResult instanceof Promise, true, 'should return a Promise'); + const removeResult = client.groups.remove(groupName).then((status) => { + t.equal(status.kind, 'Status', 'returns an object with Status'); + t.end(); }); + + t.equal(removeResult instanceof Promise, true, 'should return a Promise'); }); }); test('remove - groups - remove - no group name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.groups.remove().catch((err) => { - t.equal(err.message, 'Group Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.groups.remove().catch((err) => { + t.equal(err.message, 'Group Name is required', 'error message should return'); + t.end(); }); }); }); diff --git a/test/imagestream-test.js b/test/imagestream-test.js index e310064..54ef957 100644 --- a/test/imagestream-test.js +++ b/test/imagestream-test.js @@ -4,215 +4,171 @@ const test = require('tape'); const nock = require('nock'); const openshiftRestClient = require('../'); -const openshiftConfigLoader = require('openshift-config-loader'); const privates = require('../lib/private-map'); -test('find - imagestreams - basic findAll', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.imagestreams.findAll, 'function', 'There is a findAll method on the imagestreams object'); +const settings = { + config: { + apiVersion: 'v1', + context: + { cluster: '192-168-99-100:8443', + namespace: 'for-node-client-testing', + user: 'developer/192-168-99-100:8443' }, + user: { token: 'zVBd1ZFeJqEAILJgimm4-gZJauaw3PW4EVqV_peEZ3U' }, + cluster: 'https://192.168.99.100:8443' } +}; - const clientConfig = privates.get(client).config; +test('find - imagestreams - basic findAll', (t) => { + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.imagestreams.findAll, 'function', 'There is a findAll method on the imagestreams object'); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .get(`/oapi/v1/namespaces/${clientConfig.context.namespace}/imagestreams`) - .reply(200, {kind: 'ImageStreamList'}); + const clientConfig = privates.get(client).config; - const findResult = client.imagestreams.findAll().then((imageStreamList) => { - t.equal(imageStreamList.kind, 'ImageStreamList', 'returns an object with ImageStreamList'); - t.end(); - }); + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .get(`/oapi/v1/namespaces/${clientConfig.context.namespace}/imagestreams`) + .reply(200, {kind: 'ImageStreamList'}); - t.equal(findResult instanceof Promise, true, 'should return a Promise'); + const findResult = client.imagestreams.findAll().then((imageStreamList) => { + t.equal(imageStreamList.kind, 'ImageStreamList', 'returns an object with ImageStreamList'); + t.end(); }); + + t.equal(findResult instanceof Promise, true, 'should return a Promise'); }); }); test('find - imagestreams - basic find', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.imagestreams.find, 'function', 'There is a find method on the imagestreams object'); - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.imagestreams.find, 'function', 'There is a find method on the imagestreams object'); + const clientConfig = privates.get(client).config; + const imageStreamName = 'cool-imagestream-name-1'; - const clientConfig = privates.get(client).config; - const imageStreamName = 'cool-imagestream-name-1'; + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .get(`/oapi/v1/namespaces/${clientConfig.context.namespace}/imagestreams/${imageStreamName}`) + .reply(200, {kind: 'ImageStream'}); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .get(`/oapi/v1/namespaces/${clientConfig.context.namespace}/imagestreams/${imageStreamName}`) - .reply(200, {kind: 'ImageStream'}); - - const findResult = client.imagestreams.find(imageStreamName).then((imagestream) => { - t.equal(imagestream.kind, 'ImageStream', 'returns an object with ImageStream'); - t.end(); - }); - - t.equal(findResult instanceof Promise, true, 'should return a Promise'); + const findResult = client.imagestreams.find(imageStreamName).then((imagestream) => { + t.equal(imagestream.kind, 'ImageStream', 'returns an object with ImageStream'); + t.end(); }); + + t.equal(findResult instanceof Promise, true, 'should return a Promise'); }); }); test('find - imagestreams - find - no imagestream name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.imagestreams.find().catch((err) => { - t.equal(err.message, 'Image Stream Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.imagestreams.find().catch((err) => { + t.equal(err.message, 'Image Stream Name is required', 'error message should return'); + t.end(); }); }); }); test('create - imagestream', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.imagestreams.create, 'function', 'There is a create method on the imagestreams object'); - - const clientConfig = privates.get(client).config; - const imagestream = { - kind: 'ImageStream' - }; - - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .post(`/oapi/v1/namespaces/${clientConfig.context.namespace}/imagestreams`) - .reply(200, {kind: 'ImageStream'}); - - const createResult = client.imagestreams.create(imagestream).then((imagestream) => { - t.equal(imagestream.kind, 'ImageStream', 'returns an object with ImageStream'); - t.end(); - }); - - t.equal(createResult instanceof Promise, true, 'should return a Promise'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.imagestreams.create, 'function', 'There is a create method on the imagestreams object'); + + const clientConfig = privates.get(client).config; + const imagestream = { + kind: 'ImageStream' + }; + + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .post(`/oapi/v1/namespaces/${clientConfig.context.namespace}/imagestreams`) + .reply(200, {kind: 'ImageStream'}); + + const createResult = client.imagestreams.create(imagestream).then((imagestream) => { + t.equal(imagestream.kind, 'ImageStream', 'returns an object with ImageStream'); + t.end(); }); + + t.equal(createResult instanceof Promise, true, 'should return a Promise'); }); }); test('update - imagestream', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.imagestreams.create, 'function', 'There is a create method on the imagestreams object'); - - const clientConfig = privates.get(client).config; - const imagestream = { - kind: 'ImageStream' - }; - const imageStreamName = 'cool-imagestream-name-1'; - - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .put(`/oapi/v1/namespaces/${clientConfig.context.namespace}/imagestreams/${imageStreamName}`) - .reply(200, {kind: 'ImageStream'}); - - const createResult = client.imagestreams.update(imageStreamName, imagestream).then((imagestream) => { - t.equal(imagestream.kind, 'ImageStream', 'returns an object with ImageStream'); - t.end(); - }); - - t.equal(createResult instanceof Promise, true, 'should return a Promise'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.imagestreams.create, 'function', 'There is a create method on the imagestreams object'); + + const clientConfig = privates.get(client).config; + const imagestream = { + kind: 'ImageStream' + }; + const imageStreamName = 'cool-imagestream-name-1'; + + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .put(`/oapi/v1/namespaces/${clientConfig.context.namespace}/imagestreams/${imageStreamName}`) + .reply(200, {kind: 'ImageStream'}); + + const createResult = client.imagestreams.update(imageStreamName, imagestream).then((imagestream) => { + t.equal(imagestream.kind, 'ImageStream', 'returns an object with ImageStream'); + t.end(); }); + + t.equal(createResult instanceof Promise, true, 'should return a Promise'); }); }); test('update - imagestreams - update - no imagestream name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.imagestreams.update().catch((err) => { - t.equal(err.message, 'Image Stream Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.imagestreams.update().catch((err) => { + t.equal(err.message, 'Image Stream Name is required', 'error message should return'); + t.end(); }); }); }); test('remove - imagestreams - basic removeAll', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.imagestreams.removeAll, 'function', 'There is a removeAll method on the imagestreams object'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.imagestreams.removeAll, 'function', 'There is a removeAll method on the imagestreams object'); - const clientConfig = privates.get(client).config; + const clientConfig = privates.get(client).config; - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .delete(`/oapi/v1/namespaces/${clientConfig.context.namespace}/imagestreams`) - .reply(200, {kind: 'Status'}); + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .delete(`/oapi/v1/namespaces/${clientConfig.context.namespace}/imagestreams`) + .reply(200, {kind: 'Status'}); - const removeResult = client.imagestreams.removeAll().then((imageStreamList) => { - t.equal(imageStreamList.kind, 'Status', 'returns an object with Status'); - t.end(); - }); - - t.equal(removeResult instanceof Promise, true, 'should return a Promise'); + const removeResult = client.imagestreams.removeAll().then((imageStreamList) => { + t.equal(imageStreamList.kind, 'Status', 'returns an object with Status'); + t.end(); }); + + t.equal(removeResult instanceof Promise, true, 'should return a Promise'); }); }); test('remove - imagestreams - basic remove', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.imagestreams.remove, 'function', 'There is a remove method on the imagestreams object'); - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.imagestreams.remove, 'function', 'There is a remove method on the imagestreams object'); + const clientConfig = privates.get(client).config; + const imageStreamName = 'cool-imagestream-name-1'; - const clientConfig = privates.get(client).config; - const imageStreamName = 'cool-imagestream-name-1'; + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .delete(`/oapi/v1/namespaces/${clientConfig.context.namespace}/imagestreams/${imageStreamName}`) + .reply(200, {kind: 'Status'}); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .delete(`/oapi/v1/namespaces/${clientConfig.context.namespace}/imagestreams/${imageStreamName}`) - .reply(200, {kind: 'Status'}); - - const removeResult = client.imagestreams.remove(imageStreamName).then((status) => { - t.equal(status.kind, 'Status', 'returns an object with Status'); - t.end(); - }); - - t.equal(removeResult instanceof Promise, true, 'should return a Promise'); + const removeResult = client.imagestreams.remove(imageStreamName).then((status) => { + t.equal(status.kind, 'Status', 'returns an object with Status'); + t.end(); }); + + t.equal(removeResult instanceof Promise, true, 'should return a Promise'); }); }); test('remove - imagestreams - remove - no imagestream name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.imagestreams.remove().catch((err) => { - t.equal(err.message, 'Image Stream Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.imagestreams.remove().catch((err) => { + t.equal(err.message, 'Image Stream Name is required', 'error message should return'); + t.end(); }); }); }); diff --git a/test/openshift-client-test.js b/test/openshift-client-test.js index a2010dd..02519c1 100644 --- a/test/openshift-client-test.js +++ b/test/openshift-client-test.js @@ -42,7 +42,7 @@ test('openshift client settings test', (t) => { } }; - const osClient = openshiftRestClient(null, settings); + const osClient = openshiftRestClient(settings); osClient.then((client) => { t.ok(client.settings, 'client object should have a settings object'); diff --git a/test/pods-test.js b/test/pods-test.js index e800f0a..bf81d63 100644 --- a/test/pods-test.js +++ b/test/pods-test.js @@ -4,215 +4,171 @@ const test = require('tape'); const nock = require('nock'); const openshiftRestClient = require('../'); -const openshiftConfigLoader = require('openshift-config-loader'); const privates = require('../lib/private-map'); -test('find - pods - basic findAll', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.pods.findAll, 'function', 'There is a findAll method on the pods object'); +const settings = { + config: { + apiVersion: 'v1', + context: + { cluster: '192-168-99-100:8443', + namespace: 'for-node-client-testing', + user: 'developer/192-168-99-100:8443' }, + user: { token: 'zVBd1ZFeJqEAILJgimm4-gZJauaw3PW4EVqV_peEZ3U' }, + cluster: 'https://192.168.99.100:8443' } +}; - const clientConfig = privates.get(client).config; +test('find - pods - basic findAll', (t) => { + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.pods.findAll, 'function', 'There is a findAll method on the pods object'); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .get(`/api/v1/namespaces/${clientConfig.context.namespace}/pods`) - .reply(200, {kind: 'PodList'}); + const clientConfig = privates.get(client).config; - const findResult = client.pods.findAll().then((podsList) => { - t.equal(podsList.kind, 'PodList', 'returns an object with PodList'); - t.end(); - }); + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .get(`/api/v1/namespaces/${clientConfig.context.namespace}/pods`) + .reply(200, {kind: 'PodList'}); - t.equal(findResult instanceof Promise, true, 'should return a Promise'); + const findResult = client.pods.findAll().then((podsList) => { + t.equal(podsList.kind, 'PodList', 'returns an object with PodList'); + t.end(); }); + + t.equal(findResult instanceof Promise, true, 'should return a Promise'); }); }); test('find - pods - basic find', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.pods.find, 'function', 'There is a find method on the pods object'); - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.pods.find, 'function', 'There is a find method on the pods object'); + const clientConfig = privates.get(client).config; + const podName = 'cool-pod-name-1'; - const clientConfig = privates.get(client).config; - const podName = 'cool-pod-name-1'; + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .get(`/api/v1/namespaces/${clientConfig.context.namespace}/pods/${podName}`) + .reply(200, {kind: 'Pod'}); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .get(`/api/v1/namespaces/${clientConfig.context.namespace}/pods/${podName}`) - .reply(200, {kind: 'Pod'}); - - const findResult = client.pods.find(podName).then((pod) => { - t.equal(pod.kind, 'Pod', 'returns an object with Pod'); - t.end(); - }); - - t.equal(findResult instanceof Promise, true, 'should return a Promise'); + const findResult = client.pods.find(podName).then((pod) => { + t.equal(pod.kind, 'Pod', 'returns an object with Pod'); + t.end(); }); + + t.equal(findResult instanceof Promise, true, 'should return a Promise'); }); }); test('find - pods - find - no pod name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.pods.find().catch((err) => { - t.equal(err.message, 'Pod Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.pods.find().catch((err) => { + t.equal(err.message, 'Pod Name is required', 'error message should return'); + t.end(); }); }); }); test('create - pod', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.pods.create, 'function', 'There is a create method on the pods object'); - - const clientConfig = privates.get(client).config; - const pod = { - kind: 'Pod' - }; - - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .post(`/api/v1/namespaces/${clientConfig.context.namespace}/pods`) - .reply(200, {kind: 'Pod'}); - - const createResult = client.pods.create(pod).then((pod) => { - t.equal(pod.kind, 'Pod', 'returns an object with Pod'); - t.end(); - }); - - t.equal(createResult instanceof Promise, true, 'should return a Promise'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.pods.create, 'function', 'There is a create method on the pods object'); + + const clientConfig = privates.get(client).config; + const pod = { + kind: 'Pod' + }; + + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .post(`/api/v1/namespaces/${clientConfig.context.namespace}/pods`) + .reply(200, {kind: 'Pod'}); + + const createResult = client.pods.create(pod).then((pod) => { + t.equal(pod.kind, 'Pod', 'returns an object with Pod'); + t.end(); }); + + t.equal(createResult instanceof Promise, true, 'should return a Promise'); }); }); test('update - pod', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.pods.create, 'function', 'There is a create method on the pods object'); - - const clientConfig = privates.get(client).config; - const pod = { - kind: 'Pod' - }; - const podName = 'cool-pod-name-1'; - - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .put(`/api/v1/namespaces/${clientConfig.context.namespace}/pods/${podName}`) - .reply(200, {kind: 'Pod'}); - - const createResult = client.pods.update(podName, pod).then((pod) => { - t.equal(pod.kind, 'Pod', 'returns an object with Pod'); - t.end(); - }); - - t.equal(createResult instanceof Promise, true, 'should return a Promise'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.pods.create, 'function', 'There is a create method on the pods object'); + + const clientConfig = privates.get(client).config; + const pod = { + kind: 'Pod' + }; + const podName = 'cool-pod-name-1'; + + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .put(`/api/v1/namespaces/${clientConfig.context.namespace}/pods/${podName}`) + .reply(200, {kind: 'Pod'}); + + const createResult = client.pods.update(podName, pod).then((pod) => { + t.equal(pod.kind, 'Pod', 'returns an object with Pod'); + t.end(); }); + + t.equal(createResult instanceof Promise, true, 'should return a Promise'); }); }); test('update - pods - update - no pod name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.pods.update().catch((err) => { - t.equal(err.message, 'Pod Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.pods.update().catch((err) => { + t.equal(err.message, 'Pod Name is required', 'error message should return'); + t.end(); }); }); }); test('remove - pods - basic removeAll', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.pods.removeAll, 'function', 'There is a removeAll method on the pods object'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.pods.removeAll, 'function', 'There is a removeAll method on the pods object'); - const clientConfig = privates.get(client).config; + const clientConfig = privates.get(client).config; - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .delete(`/api/v1/namespaces/${clientConfig.context.namespace}/pods`) - .reply(200, {kind: 'Status'}); + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .delete(`/api/v1/namespaces/${clientConfig.context.namespace}/pods`) + .reply(200, {kind: 'Status'}); - const removeResult = client.pods.removeAll().then((podsList) => { - t.equal(podsList.kind, 'Status', 'returns an object with Status'); - t.end(); - }); - - t.equal(removeResult instanceof Promise, true, 'should return a Promise'); + const removeResult = client.pods.removeAll().then((podsList) => { + t.equal(podsList.kind, 'Status', 'returns an object with Status'); + t.end(); }); + + t.equal(removeResult instanceof Promise, true, 'should return a Promise'); }); }); test('remove - pods - basic remove', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.pods.remove, 'function', 'There is a remove method on the pods object'); - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.pods.remove, 'function', 'There is a remove method on the pods object'); + const clientConfig = privates.get(client).config; + const podName = 'cool-pod-name-1'; - const clientConfig = privates.get(client).config; - const podName = 'cool-pod-name-1'; + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .delete(`/api/v1/namespaces/${clientConfig.context.namespace}/pods/${podName}`) + .reply(200, {kind: 'Status'}); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .delete(`/api/v1/namespaces/${clientConfig.context.namespace}/pods/${podName}`) - .reply(200, {kind: 'Status'}); - - const removeResult = client.pods.remove(podName).then((status) => { - t.equal(status.kind, 'Status', 'returns an object with Status'); - t.end(); - }); - - t.equal(removeResult instanceof Promise, true, 'should return a Promise'); + const removeResult = client.pods.remove(podName).then((status) => { + t.equal(status.kind, 'Status', 'returns an object with Status'); + t.end(); }); + + t.equal(removeResult instanceof Promise, true, 'should return a Promise'); }); }); test('remove - pods - remove - no pod name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.pods.remove().catch((err) => { - t.equal(err.message, 'Pod Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.pods.remove().catch((err) => { + t.equal(err.message, 'Pod Name is required', 'error message should return'); + t.end(); }); }); }); diff --git a/test/project-request-test.js b/test/project-request-test.js index fa8ec0a..f06a201 100644 --- a/test/project-request-test.js +++ b/test/project-request-test.js @@ -4,60 +4,58 @@ const test = require('tape'); const nock = require('nock'); const openshiftRestClient = require('../'); -const openshiftConfigLoader = require('openshift-config-loader'); const privates = require('../lib/private-map'); -test('find - projectrequests - basic findAll', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.projectrequests.findAll, 'function', 'There is a findAll method on the projectrequests object'); +const settings = { + config: { + apiVersion: 'v1', + context: + { cluster: '192-168-99-100:8443', + namespace: 'for-node-client-testing', + user: 'developer/192-168-99-100:8443' }, + user: { token: 'zVBd1ZFeJqEAILJgimm4-gZJauaw3PW4EVqV_peEZ3U' }, + cluster: 'https://192.168.99.100:8443' } +}; - const clientConfig = privates.get(client).config; +test('find - projectrequests - basic findAll', (t) => { + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.projectrequests.findAll, 'function', 'There is a findAll method on the projectrequests object'); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .get(`/oapi/v1/projectrequests`) - .reply(200, {kind: 'ProjectRequestList'}); + const clientConfig = privates.get(client).config; - const findResult = client.projectrequests.findAll().then((projectRequestList) => { - t.equal(projectRequestList.kind, 'ProjectRequestList', 'returns an object with ProjectRequestList'); - t.end(); - }); + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .get(`/oapi/v1/projectrequests`) + .reply(200, {kind: 'ProjectRequestList'}); - t.equal(findResult instanceof Promise, true, 'should return a Promise'); + const findResult = client.projectrequests.findAll().then((projectRequestList) => { + t.equal(projectRequestList.kind, 'ProjectRequestList', 'returns an object with ProjectRequestList'); + t.end(); }); + + t.equal(findResult instanceof Promise, true, 'should return a Promise'); }); }); test('create - projectrequest', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.projectrequests.create, 'function', 'There is a create method on the projectrequests object'); - - const clientConfig = privates.get(client).config; - const projectrequest = { - kind: 'ProjectRequest' - }; - - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .post(`/oapi/v1/projectrequests`) - .reply(200, {kind: 'ProjectRequest'}); - - const createResult = client.projectrequests.create(projectrequest).then((projectrequest) => { - t.equal(projectrequest.kind, 'ProjectRequest', 'returns an object with ProjectRequest'); - t.end(); - }); - - t.equal(createResult instanceof Promise, true, 'should return a Promise'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.projectrequests.create, 'function', 'There is a create method on the projectrequests object'); + + const clientConfig = privates.get(client).config; + const projectrequest = { + kind: 'ProjectRequest' + }; + + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .post(`/oapi/v1/projectrequests`) + .reply(200, {kind: 'ProjectRequest'}); + + const createResult = client.projectrequests.create(projectrequest).then((projectrequest) => { + t.equal(projectrequest.kind, 'ProjectRequest', 'returns an object with ProjectRequest'); + t.end(); }); + + t.equal(createResult instanceof Promise, true, 'should return a Promise'); }); }); diff --git a/test/projects-test.js b/test/projects-test.js index a65f85b..c474521 100644 --- a/test/projects-test.js +++ b/test/projects-test.js @@ -4,215 +4,171 @@ const test = require('tape'); const nock = require('nock'); const openshiftRestClient = require('../'); -const openshiftConfigLoader = require('openshift-config-loader'); const privates = require('../lib/private-map'); -test('find - projects - basic findAll', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.projects.findAll, 'function', 'There is a findAll method on the projects object'); +const settings = { + config: { + apiVersion: 'v1', + context: + { cluster: '192-168-99-100:8443', + namespace: 'for-node-client-testing', + user: 'developer/192-168-99-100:8443' }, + user: { token: 'zVBd1ZFeJqEAILJgimm4-gZJauaw3PW4EVqV_peEZ3U' }, + cluster: 'https://192.168.99.100:8443' } +}; - const clientConfig = privates.get(client).config; +test('find - projects - basic findAll', (t) => { + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.projects.findAll, 'function', 'There is a findAll method on the projects object'); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .get(`/oapi/v1/projects`) - .reply(200, {kind: 'ProjectList'}); + const clientConfig = privates.get(client).config; - const findResult = client.projects.findAll().then((projectList) => { - t.equal(projectList.kind, 'ProjectList', 'returns an object with ProjectList'); - t.end(); - }); + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .get(`/oapi/v1/projects`) + .reply(200, {kind: 'ProjectList'}); - t.equal(findResult instanceof Promise, true, 'should return a Promise'); + const findResult = client.projects.findAll().then((projectList) => { + t.equal(projectList.kind, 'ProjectList', 'returns an object with ProjectList'); + t.end(); }); + + t.equal(findResult instanceof Promise, true, 'should return a Promise'); }); }); test('find - projects - basic find', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.projects.find, 'function', 'There is a find method on the projects object'); - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.projects.find, 'function', 'There is a find method on the projects object'); + const clientConfig = privates.get(client).config; + const projectName = 'cool-project-name-1'; - const clientConfig = privates.get(client).config; - const projectName = 'cool-project-name-1'; + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .get(`/oapi/v1/projects/${projectName}`) + .reply(200, {kind: 'Project'}); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .get(`/oapi/v1/projects/${projectName}`) - .reply(200, {kind: 'Project'}); - - const findResult = client.projects.find(projectName).then((project) => { - t.equal(project.kind, 'Project', 'returns an object with Project'); - t.end(); - }); - - t.equal(findResult instanceof Promise, true, 'should return a Promise'); + const findResult = client.projects.find(projectName).then((project) => { + t.equal(project.kind, 'Project', 'returns an object with Project'); + t.end(); }); + + t.equal(findResult instanceof Promise, true, 'should return a Promise'); }); }); test('find - projects - find - no project name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.projects.find().catch((err) => { - t.equal(err.message, 'Project Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.projects.find().catch((err) => { + t.equal(err.message, 'Project Name is required', 'error message should return'); + t.end(); }); }); }); test('create - project', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.projects.create, 'function', 'There is a create method on the projects object'); - - const clientConfig = privates.get(client).config; - const project = { - kind: 'Project' - }; - - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .post(`/oapi/v1/projects`) - .reply(200, {kind: 'Project'}); - - const createResult = client.projects.create(project).then((project) => { - t.equal(project.kind, 'Project', 'returns an object with Project'); - t.end(); - }); - - t.equal(createResult instanceof Promise, true, 'should return a Promise'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.projects.create, 'function', 'There is a create method on the projects object'); + + const clientConfig = privates.get(client).config; + const project = { + kind: 'Project' + }; + + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .post(`/oapi/v1/projects`) + .reply(200, {kind: 'Project'}); + + const createResult = client.projects.create(project).then((project) => { + t.equal(project.kind, 'Project', 'returns an object with Project'); + t.end(); }); + + t.equal(createResult instanceof Promise, true, 'should return a Promise'); }); }); test('update - project', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.projects.create, 'function', 'There is a create method on the projects object'); - - const clientConfig = privates.get(client).config; - const project = { - kind: 'Project' - }; - const projectName = 'cool-project-name-1'; - - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .put(`/oapi/v1/projects/${projectName}`) - .reply(200, {kind: 'Project'}); - - const createResult = client.projects.update(projectName, project).then((project) => { - t.equal(project.kind, 'Project', 'returns an object with Project'); - t.end(); - }); - - t.equal(createResult instanceof Promise, true, 'should return a Promise'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.projects.create, 'function', 'There is a create method on the projects object'); + + const clientConfig = privates.get(client).config; + const project = { + kind: 'Project' + }; + const projectName = 'cool-project-name-1'; + + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .put(`/oapi/v1/projects/${projectName}`) + .reply(200, {kind: 'Project'}); + + const createResult = client.projects.update(projectName, project).then((project) => { + t.equal(project.kind, 'Project', 'returns an object with Project'); + t.end(); }); + + t.equal(createResult instanceof Promise, true, 'should return a Promise'); }); }); test('update - projects - update - no project name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.projects.update().catch((err) => { - t.equal(err.message, 'Project Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.projects.update().catch((err) => { + t.equal(err.message, 'Project Name is required', 'error message should return'); + t.end(); }); }); }); test('remove - projects - basic removeAll', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.projects.removeAll, 'function', 'There is a removeAll method on the projects object'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.projects.removeAll, 'function', 'There is a removeAll method on the projects object'); - const clientConfig = privates.get(client).config; + const clientConfig = privates.get(client).config; - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .delete(`/oapi/v1/projects`) - .reply(200, {kind: 'Status'}); + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .delete(`/oapi/v1/projects`) + .reply(200, {kind: 'Status'}); - const removeResult = client.projects.removeAll().then((projectList) => { - t.equal(projectList.kind, 'Status', 'returns an object with Status'); - t.end(); - }); - - t.equal(removeResult instanceof Promise, true, 'should return a Promise'); + const removeResult = client.projects.removeAll().then((projectList) => { + t.equal(projectList.kind, 'Status', 'returns an object with Status'); + t.end(); }); + + t.equal(removeResult instanceof Promise, true, 'should return a Promise'); }); }); test('remove - projects - basic remove', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.projects.remove, 'function', 'There is a remove method on the projects object'); - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.projects.remove, 'function', 'There is a remove method on the projects object'); + const clientConfig = privates.get(client).config; + const projectName = 'cool-project-name-1'; - const clientConfig = privates.get(client).config; - const projectName = 'cool-project-name-1'; + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .delete(`/oapi/v1/projects/${projectName}`) + .reply(200, {kind: 'Status'}); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .delete(`/oapi/v1/projects/${projectName}`) - .reply(200, {kind: 'Status'}); - - const removeResult = client.projects.remove(projectName).then((status) => { - t.equal(status.kind, 'Status', 'returns an object with Status'); - t.end(); - }); - - t.equal(removeResult instanceof Promise, true, 'should return a Promise'); + const removeResult = client.projects.remove(projectName).then((status) => { + t.equal(status.kind, 'Status', 'returns an object with Status'); + t.end(); }); + + t.equal(removeResult instanceof Promise, true, 'should return a Promise'); }); }); test('remove - projects - remove - no project name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.projects.remove().catch((err) => { - t.equal(err.message, 'Project Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.projects.remove().catch((err) => { + t.equal(err.message, 'Project Name is required', 'error message should return'); + t.end(); }); }); }); diff --git a/test/replication-controllers-test.js b/test/replication-controllers-test.js index 539a017..c566769 100644 --- a/test/replication-controllers-test.js +++ b/test/replication-controllers-test.js @@ -4,215 +4,171 @@ const test = require('tape'); const nock = require('nock'); const openshiftRestClient = require('../'); -const openshiftConfigLoader = require('openshift-config-loader'); const privates = require('../lib/private-map'); -test('find - replicationcontrollers - basic findAll', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.replicationcontrollers.findAll, 'function', 'There is a findAll method on the replicationcontrollers object'); +const settings = { + config: { + apiVersion: 'v1', + context: + { cluster: '192-168-99-100:8443', + namespace: 'for-node-client-testing', + user: 'developer/192-168-99-100:8443' }, + user: { token: 'zVBd1ZFeJqEAILJgimm4-gZJauaw3PW4EVqV_peEZ3U' }, + cluster: 'https://192.168.99.100:8443' } +}; - const clientConfig = privates.get(client).config; +test('find - replicationcontrollers - basic findAll', (t) => { + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.replicationcontrollers.findAll, 'function', 'There is a findAll method on the replicationcontrollers object'); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .get(`/api/v1/namespaces/${clientConfig.context.namespace}/replicationcontrollers`) - .reply(200, {kind: 'ReplicationControllerList'}); + const clientConfig = privates.get(client).config; - const findResult = client.replicationcontrollers.findAll().then((replicationControllerList) => { - t.equal(replicationControllerList.kind, 'ReplicationControllerList', 'returns an object with ReplicationControllerList'); - t.end(); - }); + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .get(`/api/v1/namespaces/${clientConfig.context.namespace}/replicationcontrollers`) + .reply(200, {kind: 'ReplicationControllerList'}); - t.equal(findResult instanceof Promise, true, 'should return a Promise'); + const findResult = client.replicationcontrollers.findAll().then((replicationControllerList) => { + t.equal(replicationControllerList.kind, 'ReplicationControllerList', 'returns an object with ReplicationControllerList'); + t.end(); }); + + t.equal(findResult instanceof Promise, true, 'should return a Promise'); }); }); test('find - replicationcontrollers - basic find', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.replicationcontrollers.find, 'function', 'There is a find method on the replicationcontrollers object'); - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.replicationcontrollers.find, 'function', 'There is a find method on the replicationcontrollers object'); + const clientConfig = privates.get(client).config; + const replicationControllerName = 'cool-replicationcontroller-name-1'; - const clientConfig = privates.get(client).config; - const replicationControllerName = 'cool-replicationcontroller-name-1'; + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .get(`/api/v1/namespaces/${clientConfig.context.namespace}/replicationcontrollers/${replicationControllerName}`) + .reply(200, {kind: 'ReplicationController'}); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .get(`/api/v1/namespaces/${clientConfig.context.namespace}/replicationcontrollers/${replicationControllerName}`) - .reply(200, {kind: 'ReplicationController'}); - - const findResult = client.replicationcontrollers.find(replicationControllerName).then((replicationcontroller) => { - t.equal(replicationcontroller.kind, 'ReplicationController', 'returns an object with ReplicationController'); - t.end(); - }); - - t.equal(findResult instanceof Promise, true, 'should return a Promise'); + const findResult = client.replicationcontrollers.find(replicationControllerName).then((replicationcontroller) => { + t.equal(replicationcontroller.kind, 'ReplicationController', 'returns an object with ReplicationController'); + t.end(); }); + + t.equal(findResult instanceof Promise, true, 'should return a Promise'); }); }); test('find - replicationcontrollers - find - no replicationcontroller name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.replicationcontrollers.find().catch((err) => { - t.equal(err.message, 'Replication Controller Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.replicationcontrollers.find().catch((err) => { + t.equal(err.message, 'Replication Controller Name is required', 'error message should return'); + t.end(); }); }); }); test('create - replicationcontroller', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.replicationcontrollers.create, 'function', 'There is a create method on the replicationcontrollers object'); - - const clientConfig = privates.get(client).config; - const replicationcontroller = { - kind: 'ReplicationController' - }; - - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .post(`/api/v1/namespaces/${clientConfig.context.namespace}/replicationcontrollers`) - .reply(200, {kind: 'ReplicationController'}); - - const createResult = client.replicationcontrollers.create(replicationcontroller).then((replicationcontroller) => { - t.equal(replicationcontroller.kind, 'ReplicationController', 'returns an object with ReplicationController'); - t.end(); - }); - - t.equal(createResult instanceof Promise, true, 'should return a Promise'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.replicationcontrollers.create, 'function', 'There is a create method on the replicationcontrollers object'); + + const clientConfig = privates.get(client).config; + const replicationcontroller = { + kind: 'ReplicationController' + }; + + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .post(`/api/v1/namespaces/${clientConfig.context.namespace}/replicationcontrollers`) + .reply(200, {kind: 'ReplicationController'}); + + const createResult = client.replicationcontrollers.create(replicationcontroller).then((replicationcontroller) => { + t.equal(replicationcontroller.kind, 'ReplicationController', 'returns an object with ReplicationController'); + t.end(); }); + + t.equal(createResult instanceof Promise, true, 'should return a Promise'); }); }); test('update - replicationcontroller', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.replicationcontrollers.create, 'function', 'There is a create method on the replicationcontrollers object'); - - const clientConfig = privates.get(client).config; - const replicationcontroller = { - kind: 'ReplicationController' - }; - const replicationControllerName = 'cool-replicationcontroller-name-1'; - - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .put(`/api/v1/namespaces/${clientConfig.context.namespace}/replicationcontrollers/${replicationControllerName}`) - .reply(200, {kind: 'ReplicationController'}); - - const createResult = client.replicationcontrollers.update(replicationControllerName, replicationcontroller).then((replicationcontroller) => { - t.equal(replicationcontroller.kind, 'ReplicationController', 'returns an object with ReplicationController'); - t.end(); - }); - - t.equal(createResult instanceof Promise, true, 'should return a Promise'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.replicationcontrollers.create, 'function', 'There is a create method on the replicationcontrollers object'); + + const clientConfig = privates.get(client).config; + const replicationcontroller = { + kind: 'ReplicationController' + }; + const replicationControllerName = 'cool-replicationcontroller-name-1'; + + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .put(`/api/v1/namespaces/${clientConfig.context.namespace}/replicationcontrollers/${replicationControllerName}`) + .reply(200, {kind: 'ReplicationController'}); + + const createResult = client.replicationcontrollers.update(replicationControllerName, replicationcontroller).then((replicationcontroller) => { + t.equal(replicationcontroller.kind, 'ReplicationController', 'returns an object with ReplicationController'); + t.end(); }); + + t.equal(createResult instanceof Promise, true, 'should return a Promise'); }); }); test('update - replicationcontrollers - update - no replicationcontroller name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.replicationcontrollers.update().catch((err) => { - t.equal(err.message, 'Replication Controller Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.replicationcontrollers.update().catch((err) => { + t.equal(err.message, 'Replication Controller Name is required', 'error message should return'); + t.end(); }); }); }); test('remove - replicationcontrollers - basic removeAll', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.replicationcontrollers.removeAll, 'function', 'There is a removeAll method on the replicationcontrollers object'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.replicationcontrollers.removeAll, 'function', 'There is a removeAll method on the replicationcontrollers object'); - const clientConfig = privates.get(client).config; + const clientConfig = privates.get(client).config; - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .delete(`/api/v1/namespaces/${clientConfig.context.namespace}/replicationcontrollers`) - .reply(200, {kind: 'Status'}); + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .delete(`/api/v1/namespaces/${clientConfig.context.namespace}/replicationcontrollers`) + .reply(200, {kind: 'Status'}); - const removeResult = client.replicationcontrollers.removeAll().then((replicationControllerList) => { - t.equal(replicationControllerList.kind, 'Status', 'returns an object with Status'); - t.end(); - }); - - t.equal(removeResult instanceof Promise, true, 'should return a Promise'); + const removeResult = client.replicationcontrollers.removeAll().then((replicationControllerList) => { + t.equal(replicationControllerList.kind, 'Status', 'returns an object with Status'); + t.end(); }); + + t.equal(removeResult instanceof Promise, true, 'should return a Promise'); }); }); test('remove - replicationcontrollers - basic remove', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.replicationcontrollers.remove, 'function', 'There is a remove method on the replicationcontrollers object'); - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.replicationcontrollers.remove, 'function', 'There is a remove method on the replicationcontrollers object'); + const clientConfig = privates.get(client).config; + const replicationControllerName = 'cool-replicationcontroller-name-1'; - const clientConfig = privates.get(client).config; - const replicationControllerName = 'cool-replicationcontroller-name-1'; + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .delete(`/api/v1/namespaces/${clientConfig.context.namespace}/replicationcontrollers/${replicationControllerName}`) + .reply(200, {kind: 'Status'}); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .delete(`/api/v1/namespaces/${clientConfig.context.namespace}/replicationcontrollers/${replicationControllerName}`) - .reply(200, {kind: 'Status'}); - - const removeResult = client.replicationcontrollers.remove(replicationControllerName).then((status) => { - t.equal(status.kind, 'Status', 'returns an object with Status'); - t.end(); - }); - - t.equal(removeResult instanceof Promise, true, 'should return a Promise'); + const removeResult = client.replicationcontrollers.remove(replicationControllerName).then((status) => { + t.equal(status.kind, 'Status', 'returns an object with Status'); + t.end(); }); + + t.equal(removeResult instanceof Promise, true, 'should return a Promise'); }); }); test('remove - replicationcontrollers - remove - no replicationcontroller name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.replicationcontrollers.remove().catch((err) => { - t.equal(err.message, 'Replication Controller Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.replicationcontrollers.remove().catch((err) => { + t.equal(err.message, 'Replication Controller Name is required', 'error message should return'); + t.end(); }); }); }); diff --git a/test/role-binding-test.js b/test/role-binding-test.js index 828a373..0fe36b2 100644 --- a/test/role-binding-test.js +++ b/test/role-binding-test.js @@ -4,215 +4,171 @@ const test = require('tape'); const nock = require('nock'); const openshiftRestClient = require('../'); -const openshiftConfigLoader = require('openshift-config-loader'); const privates = require('../lib/private-map'); -test('find - rolebindings - basic findAll', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.rolebindings.findAll, 'function', 'There is a findAll method on the rolebindings object'); +const settings = { + config: { + apiVersion: 'v1', + context: + { cluster: '192-168-99-100:8443', + namespace: 'for-node-client-testing', + user: 'developer/192-168-99-100:8443' }, + user: { token: 'zVBd1ZFeJqEAILJgimm4-gZJauaw3PW4EVqV_peEZ3U' }, + cluster: 'https://192.168.99.100:8443' } +}; - const clientConfig = privates.get(client).config; +test('find - rolebindings - basic findAll', (t) => { + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.rolebindings.findAll, 'function', 'There is a findAll method on the rolebindings object'); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .get(`/oapi/v1/namespaces/${clientConfig.context.namespace}/rolebindings`) - .reply(200, {kind: 'RoleBindingList'}); + const clientConfig = privates.get(client).config; - const findResult = client.rolebindings.findAll().then((roleBindingList) => { - t.equal(roleBindingList.kind, 'RoleBindingList', 'returns an object with RoleBindingList'); - t.end(); - }); + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .get(`/oapi/v1/namespaces/${clientConfig.context.namespace}/rolebindings`) + .reply(200, {kind: 'RoleBindingList'}); - t.equal(findResult instanceof Promise, true, 'should return a Promise'); + const findResult = client.rolebindings.findAll().then((roleBindingList) => { + t.equal(roleBindingList.kind, 'RoleBindingList', 'returns an object with RoleBindingList'); + t.end(); }); + + t.equal(findResult instanceof Promise, true, 'should return a Promise'); }); }); test('find - rolebindings - basic find', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.rolebindings.find, 'function', 'There is a find method on the rolebindings object'); - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.rolebindings.find, 'function', 'There is a find method on the rolebindings object'); + const clientConfig = privates.get(client).config; + const roleBindingName = 'cool-rolebinding-name-1'; - const clientConfig = privates.get(client).config; - const roleBindingName = 'cool-rolebinding-name-1'; + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .get(`/oapi/v1/namespaces/${clientConfig.context.namespace}/rolebindings/${roleBindingName}`) + .reply(200, {kind: 'RoleBinding'}); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .get(`/oapi/v1/namespaces/${clientConfig.context.namespace}/rolebindings/${roleBindingName}`) - .reply(200, {kind: 'RoleBinding'}); - - const findResult = client.rolebindings.find(roleBindingName).then((rolebinding) => { - t.equal(rolebinding.kind, 'RoleBinding', 'returns an object with RoleBinding'); - t.end(); - }); - - t.equal(findResult instanceof Promise, true, 'should return a Promise'); + const findResult = client.rolebindings.find(roleBindingName).then((rolebinding) => { + t.equal(rolebinding.kind, 'RoleBinding', 'returns an object with RoleBinding'); + t.end(); }); + + t.equal(findResult instanceof Promise, true, 'should return a Promise'); }); }); test('find - rolebindings - find - no rolebinding name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.rolebindings.find().catch((err) => { - t.equal(err.message, 'Role Binding Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.rolebindings.find().catch((err) => { + t.equal(err.message, 'Role Binding Name is required', 'error message should return'); + t.end(); }); }); }); test('create - rolebinding', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.rolebindings.create, 'function', 'There is a create method on the rolebindings object'); - - const clientConfig = privates.get(client).config; - const rolebinding = { - kind: 'RoleBinding' - }; - - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .post(`/oapi/v1/namespaces/${clientConfig.context.namespace}/rolebindings`) - .reply(200, {kind: 'RoleBinding'}); - - const createResult = client.rolebindings.create(rolebinding).then((rolebinding) => { - t.equal(rolebinding.kind, 'RoleBinding', 'returns an object with RoleBinding'); - t.end(); - }); - - t.equal(createResult instanceof Promise, true, 'should return a Promise'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.rolebindings.create, 'function', 'There is a create method on the rolebindings object'); + + const clientConfig = privates.get(client).config; + const rolebinding = { + kind: 'RoleBinding' + }; + + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .post(`/oapi/v1/namespaces/${clientConfig.context.namespace}/rolebindings`) + .reply(200, {kind: 'RoleBinding'}); + + const createResult = client.rolebindings.create(rolebinding).then((rolebinding) => { + t.equal(rolebinding.kind, 'RoleBinding', 'returns an object with RoleBinding'); + t.end(); }); + + t.equal(createResult instanceof Promise, true, 'should return a Promise'); }); }); test('update - rolebinding', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.rolebindings.create, 'function', 'There is a create method on the rolebindings object'); - - const clientConfig = privates.get(client).config; - const rolebinding = { - kind: 'RoleBinding' - }; - const roleBindingName = 'cool-rolebinding-name-1'; - - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .put(`/oapi/v1/namespaces/${clientConfig.context.namespace}/rolebindings/${roleBindingName}`) - .reply(200, {kind: 'RoleBinding'}); - - const createResult = client.rolebindings.update(roleBindingName, rolebinding).then((rolebinding) => { - t.equal(rolebinding.kind, 'RoleBinding', 'returns an object with RoleBinding'); - t.end(); - }); - - t.equal(createResult instanceof Promise, true, 'should return a Promise'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.rolebindings.create, 'function', 'There is a create method on the rolebindings object'); + + const clientConfig = privates.get(client).config; + const rolebinding = { + kind: 'RoleBinding' + }; + const roleBindingName = 'cool-rolebinding-name-1'; + + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .put(`/oapi/v1/namespaces/${clientConfig.context.namespace}/rolebindings/${roleBindingName}`) + .reply(200, {kind: 'RoleBinding'}); + + const createResult = client.rolebindings.update(roleBindingName, rolebinding).then((rolebinding) => { + t.equal(rolebinding.kind, 'RoleBinding', 'returns an object with RoleBinding'); + t.end(); }); + + t.equal(createResult instanceof Promise, true, 'should return a Promise'); }); }); test('update - rolebindings - update - no rolebinding name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.rolebindings.update().catch((err) => { - t.equal(err.message, 'Role Binding Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.rolebindings.update().catch((err) => { + t.equal(err.message, 'Role Binding Name is required', 'error message should return'); + t.end(); }); }); }); test('remove - rolebindings - basic removeAll', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.rolebindings.removeAll, 'function', 'There is a removeAll method on the rolebindings object'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.rolebindings.removeAll, 'function', 'There is a removeAll method on the rolebindings object'); - const clientConfig = privates.get(client).config; + const clientConfig = privates.get(client).config; - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .delete(`/oapi/v1/namespaces/${clientConfig.context.namespace}/rolebindings`) - .reply(200, {kind: 'Status'}); + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .delete(`/oapi/v1/namespaces/${clientConfig.context.namespace}/rolebindings`) + .reply(200, {kind: 'Status'}); - const removeResult = client.rolebindings.removeAll().then((roleBindingList) => { - t.equal(roleBindingList.kind, 'Status', 'returns an object with Status'); - t.end(); - }); - - t.equal(removeResult instanceof Promise, true, 'should return a Promise'); + const removeResult = client.rolebindings.removeAll().then((roleBindingList) => { + t.equal(roleBindingList.kind, 'Status', 'returns an object with Status'); + t.end(); }); + + t.equal(removeResult instanceof Promise, true, 'should return a Promise'); }); }); test('remove - rolebindings - basic remove', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.rolebindings.remove, 'function', 'There is a remove method on the rolebindings object'); - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.rolebindings.remove, 'function', 'There is a remove method on the rolebindings object'); + const clientConfig = privates.get(client).config; + const roleBindingName = 'cool-rolebinding-name-1'; - const clientConfig = privates.get(client).config; - const roleBindingName = 'cool-rolebinding-name-1'; + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .delete(`/oapi/v1/namespaces/${clientConfig.context.namespace}/rolebindings/${roleBindingName}`) + .reply(200, {kind: 'Status'}); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .delete(`/oapi/v1/namespaces/${clientConfig.context.namespace}/rolebindings/${roleBindingName}`) - .reply(200, {kind: 'Status'}); - - const removeResult = client.rolebindings.remove(roleBindingName).then((status) => { - t.equal(status.kind, 'Status', 'returns an object with Status'); - t.end(); - }); - - t.equal(removeResult instanceof Promise, true, 'should return a Promise'); + const removeResult = client.rolebindings.remove(roleBindingName).then((status) => { + t.equal(status.kind, 'Status', 'returns an object with Status'); + t.end(); }); + + t.equal(removeResult instanceof Promise, true, 'should return a Promise'); }); }); test('remove - rolebindings - remove - no rolebinding name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.rolebindings.remove().catch((err) => { - t.equal(err.message, 'Role Binding Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.rolebindings.remove().catch((err) => { + t.equal(err.message, 'Role Binding Name is required', 'error message should return'); + t.end(); }); }); }); diff --git a/test/routes-test.js b/test/routes-test.js index de3861f..1ba2804 100644 --- a/test/routes-test.js +++ b/test/routes-test.js @@ -4,215 +4,171 @@ const test = require('tape'); const nock = require('nock'); const openshiftRestClient = require('../'); -const openshiftConfigLoader = require('openshift-config-loader'); const privates = require('../lib/private-map'); -test('find - routes - basic findAll', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.routes.findAll, 'function', 'There is a findAll method on the routes object'); +const settings = { + config: { + apiVersion: 'v1', + context: + { cluster: '192-168-99-100:8443', + namespace: 'for-node-client-testing', + user: 'developer/192-168-99-100:8443' }, + user: { token: 'zVBd1ZFeJqEAILJgimm4-gZJauaw3PW4EVqV_peEZ3U' }, + cluster: 'https://192.168.99.100:8443' } +}; - const clientConfig = privates.get(client).config; +test('find - routes - basic findAll', (t) => { + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.routes.findAll, 'function', 'There is a findAll method on the routes object'); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .get(`/oapi/v1/namespaces/${clientConfig.context.namespace}/routes`) - .reply(200, {kind: 'RouteList'}); + const clientConfig = privates.get(client).config; - const findResult = client.routes.findAll().then((routeList) => { - t.equal(routeList.kind, 'RouteList', 'returns an object with RouteList'); - t.end(); - }); + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .get(`/oapi/v1/namespaces/${clientConfig.context.namespace}/routes`) + .reply(200, {kind: 'RouteList'}); - t.equal(findResult instanceof Promise, true, 'should return a Promise'); + const findResult = client.routes.findAll().then((routeList) => { + t.equal(routeList.kind, 'RouteList', 'returns an object with RouteList'); + t.end(); }); + + t.equal(findResult instanceof Promise, true, 'should return a Promise'); }); }); test('find - routes - basic find', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.routes.find, 'function', 'There is a find method on the routes object'); - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.routes.find, 'function', 'There is a find method on the routes object'); + const clientConfig = privates.get(client).config; + const routeName = 'cool-route-name-1'; - const clientConfig = privates.get(client).config; - const routeName = 'cool-route-name-1'; + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .get(`/oapi/v1/namespaces/${clientConfig.context.namespace}/routes/${routeName}`) + .reply(200, {kind: 'Route'}); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .get(`/oapi/v1/namespaces/${clientConfig.context.namespace}/routes/${routeName}`) - .reply(200, {kind: 'Route'}); - - const findResult = client.routes.find(routeName).then((route) => { - t.equal(route.kind, 'Route', 'returns an object with Route'); - t.end(); - }); - - t.equal(findResult instanceof Promise, true, 'should return a Promise'); + const findResult = client.routes.find(routeName).then((route) => { + t.equal(route.kind, 'Route', 'returns an object with Route'); + t.end(); }); + + t.equal(findResult instanceof Promise, true, 'should return a Promise'); }); }); test('find - routes - find - no route name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.routes.find().catch((err) => { - t.equal(err.message, 'Route Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.routes.find().catch((err) => { + t.equal(err.message, 'Route Name is required', 'error message should return'); + t.end(); }); }); }); test('create - route', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.routes.create, 'function', 'There is a create method on the routes object'); - - const clientConfig = privates.get(client).config; - const route = { - kind: 'Route' - }; - - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .post(`/oapi/v1/namespaces/${clientConfig.context.namespace}/routes`) - .reply(200, {kind: 'Route'}); - - const createResult = client.routes.create(route).then((route) => { - t.equal(route.kind, 'Route', 'returns an object with Route'); - t.end(); - }); - - t.equal(createResult instanceof Promise, true, 'should return a Promise'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.routes.create, 'function', 'There is a create method on the routes object'); + + const clientConfig = privates.get(client).config; + const route = { + kind: 'Route' + }; + + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .post(`/oapi/v1/namespaces/${clientConfig.context.namespace}/routes`) + .reply(200, {kind: 'Route'}); + + const createResult = client.routes.create(route).then((route) => { + t.equal(route.kind, 'Route', 'returns an object with Route'); + t.end(); }); + + t.equal(createResult instanceof Promise, true, 'should return a Promise'); }); }); test('update - route', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.routes.create, 'function', 'There is a create method on the routes object'); - - const clientConfig = privates.get(client).config; - const route = { - kind: 'Route' - }; - const routeName = 'cool-route-name-1'; - - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .put(`/oapi/v1/namespaces/${clientConfig.context.namespace}/routes/${routeName}`) - .reply(200, {kind: 'Route'}); - - const createResult = client.routes.update(routeName, route).then((route) => { - t.equal(route.kind, 'Route', 'returns an object with Route'); - t.end(); - }); - - t.equal(createResult instanceof Promise, true, 'should return a Promise'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.routes.create, 'function', 'There is a create method on the routes object'); + + const clientConfig = privates.get(client).config; + const route = { + kind: 'Route' + }; + const routeName = 'cool-route-name-1'; + + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .put(`/oapi/v1/namespaces/${clientConfig.context.namespace}/routes/${routeName}`) + .reply(200, {kind: 'Route'}); + + const createResult = client.routes.update(routeName, route).then((route) => { + t.equal(route.kind, 'Route', 'returns an object with Route'); + t.end(); }); + + t.equal(createResult instanceof Promise, true, 'should return a Promise'); }); }); test('update - routes - update - no route name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.routes.update().catch((err) => { - t.equal(err.message, 'Route Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.routes.update().catch((err) => { + t.equal(err.message, 'Route Name is required', 'error message should return'); + t.end(); }); }); }); test('remove - routes - basic removeAll', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.routes.removeAll, 'function', 'There is a removeAll method on the routes object'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.routes.removeAll, 'function', 'There is a removeAll method on the routes object'); - const clientConfig = privates.get(client).config; + const clientConfig = privates.get(client).config; - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .delete(`/oapi/v1/namespaces/${clientConfig.context.namespace}/routes`) - .reply(200, {kind: 'Status'}); + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .delete(`/oapi/v1/namespaces/${clientConfig.context.namespace}/routes`) + .reply(200, {kind: 'Status'}); - const removeResult = client.routes.removeAll().then((routeList) => { - t.equal(routeList.kind, 'Status', 'returns an object with Status'); - t.end(); - }); - - t.equal(removeResult instanceof Promise, true, 'should return a Promise'); + const removeResult = client.routes.removeAll().then((routeList) => { + t.equal(routeList.kind, 'Status', 'returns an object with Status'); + t.end(); }); + + t.equal(removeResult instanceof Promise, true, 'should return a Promise'); }); }); test('remove - routes - basic remove', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.routes.remove, 'function', 'There is a remove method on the routes object'); - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.routes.remove, 'function', 'There is a remove method on the routes object'); + const clientConfig = privates.get(client).config; + const routeName = 'cool-route-name-1'; - const clientConfig = privates.get(client).config; - const routeName = 'cool-route-name-1'; + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .delete(`/oapi/v1/namespaces/${clientConfig.context.namespace}/routes/${routeName}`) + .reply(200, {kind: 'Status'}); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .delete(`/oapi/v1/namespaces/${clientConfig.context.namespace}/routes/${routeName}`) - .reply(200, {kind: 'Status'}); - - const removeResult = client.routes.remove(routeName).then((status) => { - t.equal(status.kind, 'Status', 'returns an object with Status'); - t.end(); - }); - - t.equal(removeResult instanceof Promise, true, 'should return a Promise'); + const removeResult = client.routes.remove(routeName).then((status) => { + t.equal(status.kind, 'Status', 'returns an object with Status'); + t.end(); }); + + t.equal(removeResult instanceof Promise, true, 'should return a Promise'); }); }); test('remove - routes - remove - no route name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.routes.remove().catch((err) => { - t.equal(err.message, 'Route Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.routes.remove().catch((err) => { + t.equal(err.message, 'Route Name is required', 'error message should return'); + t.end(); }); }); }); diff --git a/test/secrets-test.js b/test/secrets-test.js index 1935a37..1bb2f68 100644 --- a/test/secrets-test.js +++ b/test/secrets-test.js @@ -4,217 +4,173 @@ const test = require('tape'); const nock = require('nock'); const openshiftRestClient = require('../'); -const openshiftConfigLoader = require('openshift-config-loader'); const privates = require('../lib/private-map'); -test('find - secrets - basic findAll', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.secrets.findAll, 'function', 'There is a findAll method on the secrets object'); +const settings = { + config: { + apiVersion: 'v1', + context: + { cluster: '192-168-99-100:8443', + namespace: 'for-node-client-testing', + user: 'developer/192-168-99-100:8443' }, + user: { token: 'zVBd1ZFeJqEAILJgimm4-gZJauaw3PW4EVqV_peEZ3U' }, + cluster: 'https://192.168.99.100:8443' } +}; - const clientConfig = privates.get(client).config; +test('find - secrets - basic findAll', (t) => { + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.secrets.findAll, 'function', 'There is a findAll method on the secrets object'); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .get(`/api/v1/namespaces/${clientConfig.context.namespace}/secrets`) - .reply(200, {kind: 'SecretList'}); + const clientConfig = privates.get(client).config; - const findResult = client.secrets.findAll().then((secretsList) => { - t.equal(secretsList.kind, 'SecretList', 'returns an object with SecretList'); - t.end(); - }); + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .get(`/api/v1/namespaces/${clientConfig.context.namespace}/secrets`) + .reply(200, {kind: 'SecretList'}); - t.equal(findResult instanceof Promise, true, 'should return a Promise'); + const findResult = client.secrets.findAll().then((secretsList) => { + t.equal(secretsList.kind, 'SecretList', 'returns an object with SecretList'); + t.end(); }); + + t.equal(findResult instanceof Promise, true, 'should return a Promise'); }); }); test('find - secrets - basic find', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.secrets.find, 'function', 'There is a find method on the secrets object'); - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.secrets.find, 'function', 'There is a find method on the secrets object'); + const clientConfig = privates.get(client).config; + const secretName = 'cool-deployment-name-1'; - const clientConfig = privates.get(client).config; - const secretName = 'cool-deployment-name-1'; + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .get(`/api/v1/namespaces/${clientConfig.context.namespace}/secrets/${secretName}`) + .reply(200, {kind: 'Secret'}); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .get(`/api/v1/namespaces/${clientConfig.context.namespace}/secrets/${secretName}`) - .reply(200, {kind: 'Secret'}); - - const findResult = client.secrets.find(secretName).then((secret) => { - t.equal(secret.kind, 'Secret', 'returns an object with Secret'); - t.end(); - }); - - t.equal(findResult instanceof Promise, true, 'should return a Promise'); + const findResult = client.secrets.find(secretName).then((secret) => { + t.equal(secret.kind, 'Secret', 'returns an object with Secret'); + t.end(); }); + + t.equal(findResult instanceof Promise, true, 'should return a Promise'); }); }); test('find - secrets - find - no secret name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.secrets.find().catch((err) => { - t.equal(err.message, 'Secret Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.secrets.find().catch((err) => { + t.equal(err.message, 'Secret Name is required', 'error message should return'); + t.end(); }); }); }); test('create - secret', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.secrets.create, 'function', 'There is a create method on the secrets object'); - - const clientConfig = privates.get(client).config; - const secret = { - kind: 'Secret' - }; - - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .post(`/api/v1/namespaces/${clientConfig.context.namespace}/secrets`) - .reply(200, {kind: 'Secret'}); - - const createResult = client.secrets.create(secret).then((secret) => { - t.equal(secret.kind, 'Secret', 'returns an object with Secret'); - t.end(); - }); - - t.equal(createResult instanceof Promise, true, 'should return a Promise'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.secrets.create, 'function', 'There is a create method on the secrets object'); + + const clientConfig = privates.get(client).config; + const secret = { + kind: 'Secret' + }; + + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .post(`/api/v1/namespaces/${clientConfig.context.namespace}/secrets`) + .reply(200, {kind: 'Secret'}); + + const createResult = client.secrets.create(secret).then((secret) => { + t.equal(secret.kind, 'Secret', 'returns an object with Secret'); + t.end(); }); + + t.equal(createResult instanceof Promise, true, 'should return a Promise'); }); }); test('update - secret', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.secrets.create, 'function', 'There is a create method on the secrets object'); - - const clientConfig = privates.get(client).config; - const secret = { - kind: 'Secret' - }; - const secretName = 'cool-deployment-name-1'; - - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .put(`/api/v1/namespaces/${clientConfig.context.namespace}/secrets/${secretName}`) - .reply(200, {kind: 'Secret'}); - - const createResult = client.secrets.update(secretName, secret).then((secret) => { - t.equal(secret.kind, 'Secret', 'returns an object with Secret'); - t.end(); - }); - - t.equal(createResult instanceof Promise, true, 'should return a Promise'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.secrets.create, 'function', 'There is a create method on the secrets object'); + + const clientConfig = privates.get(client).config; + const secret = { + kind: 'Secret' + }; + const secretName = 'cool-deployment-name-1'; + + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .put(`/api/v1/namespaces/${clientConfig.context.namespace}/secrets/${secretName}`) + .reply(200, {kind: 'Secret'}); + + const createResult = client.secrets.update(secretName, secret).then((secret) => { + t.equal(secret.kind, 'Secret', 'returns an object with Secret'); + t.end(); }); + + t.equal(createResult instanceof Promise, true, 'should return a Promise'); }); }); test('update - secrets - update - no secret name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.secrets.update().catch((err) => { - t.equal(err.message, 'Secret Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.secrets.update().catch((err) => { + t.equal(err.message, 'Secret Name is required', 'error message should return'); + t.end(); }); }); }); test('remove - secrets - basic removeAll', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.secrets.removeAll, 'function', 'There is a removeAll method on the secrets object'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.secrets.removeAll, 'function', 'There is a removeAll method on the secrets object'); - const clientConfig = privates.get(client).config; + const clientConfig = privates.get(client).config; - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .delete(`/api/v1/namespaces/${clientConfig.context.namespace}/secrets`) - .reply(200, {kind: 'SecretList'}); + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .delete(`/api/v1/namespaces/${clientConfig.context.namespace}/secrets`) + .reply(200, {kind: 'SecretList'}); - // Note: https://docs.openshift.org/latest/rest_api/kubernetes_v1.html#delete-collection-of-secret says it return a Status object - // but it really returns a SecretList object, possible doc error? - const removeResult = client.secrets.removeAll().then((secretsList) => { - t.equal(secretsList.kind, 'SecretList', 'returns an object with SecretList'); - t.end(); - }); - - t.equal(removeResult instanceof Promise, true, 'should return a Promise'); + // Note: https://docs.openshift.org/latest/rest_api/kubernetes_v1.html#delete-collection-of-secret says it return a Status object + // but it really returns a SecretList object, possible doc error? + const removeResult = client.secrets.removeAll().then((secretsList) => { + t.equal(secretsList.kind, 'SecretList', 'returns an object with SecretList'); + t.end(); }); + + t.equal(removeResult instanceof Promise, true, 'should return a Promise'); }); }); test('remove - secrets - basic remove', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.secrets.remove, 'function', 'There is a remove method on the secrets object'); - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.secrets.remove, 'function', 'There is a remove method on the secrets object'); + const clientConfig = privates.get(client).config; + const secretName = 'cool-deployment-name-1'; - const clientConfig = privates.get(client).config; - const secretName = 'cool-deployment-name-1'; + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .delete(`/api/v1/namespaces/${clientConfig.context.namespace}/secrets/${secretName}`) + .reply(200, {kind: 'Status'}); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .delete(`/api/v1/namespaces/${clientConfig.context.namespace}/secrets/${secretName}`) - .reply(200, {kind: 'Status'}); - - const removeResult = client.secrets.remove(secretName).then((status) => { - t.equal(status.kind, 'Status', 'returns an object with Status'); - t.end(); - }); - - t.equal(removeResult instanceof Promise, true, 'should return a Promise'); + const removeResult = client.secrets.remove(secretName).then((status) => { + t.equal(status.kind, 'Status', 'returns an object with Status'); + t.end(); }); + + t.equal(removeResult instanceof Promise, true, 'should return a Promise'); }); }); test('remove - secrets - remove - no secret name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.secrets.remove().catch((err) => { - t.equal(err.message, 'Secret Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.secrets.remove().catch((err) => { + t.equal(err.message, 'Secret Name is required', 'error message should return'); + t.end(); }); }); }); diff --git a/test/services-test.js b/test/services-test.js index 73af6a7..0b7a0f2 100644 --- a/test/services-test.js +++ b/test/services-test.js @@ -4,215 +4,171 @@ const test = require('tape'); const nock = require('nock'); const openshiftRestClient = require('../'); -const openshiftConfigLoader = require('openshift-config-loader'); const privates = require('../lib/private-map'); -test('find - services - basic findAll', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.services.findAll, 'function', 'There is a findAll method on the services object'); +const settings = { + config: { + apiVersion: 'v1', + context: + { cluster: '192-168-99-100:8443', + namespace: 'for-node-client-testing', + user: 'developer/192-168-99-100:8443' }, + user: { token: 'zVBd1ZFeJqEAILJgimm4-gZJauaw3PW4EVqV_peEZ3U' }, + cluster: 'https://192.168.99.100:8443' } +}; - const clientConfig = privates.get(client).config; +test('find - services - basic findAll', (t) => { + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.services.findAll, 'function', 'There is a findAll method on the services object'); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .get(`/api/v1/namespaces/${clientConfig.context.namespace}/services`) - .reply(200, {kind: 'ServiceList'}); + const clientConfig = privates.get(client).config; - const findResult = client.services.findAll().then((serviceList) => { - t.equal(serviceList.kind, 'ServiceList', 'returns an object with ServiceList'); - t.end(); - }); + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .get(`/api/v1/namespaces/${clientConfig.context.namespace}/services`) + .reply(200, {kind: 'ServiceList'}); - t.equal(findResult instanceof Promise, true, 'should return a Promise'); + const findResult = client.services.findAll().then((serviceList) => { + t.equal(serviceList.kind, 'ServiceList', 'returns an object with ServiceList'); + t.end(); }); + + t.equal(findResult instanceof Promise, true, 'should return a Promise'); }); }); test('find - services - basic find', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.services.find, 'function', 'There is a find method on the services object'); - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.services.find, 'function', 'There is a find method on the services object'); + const clientConfig = privates.get(client).config; + const serviceName = 'cool-service-name-1'; - const clientConfig = privates.get(client).config; - const serviceName = 'cool-service-name-1'; + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .get(`/api/v1/namespaces/${clientConfig.context.namespace}/services/${serviceName}`) + .reply(200, {kind: 'Service'}); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .get(`/api/v1/namespaces/${clientConfig.context.namespace}/services/${serviceName}`) - .reply(200, {kind: 'Service'}); - - const findResult = client.services.find(serviceName).then((service) => { - t.equal(service.kind, 'Service', 'returns an object with Service'); - t.end(); - }); - - t.equal(findResult instanceof Promise, true, 'should return a Promise'); + const findResult = client.services.find(serviceName).then((service) => { + t.equal(service.kind, 'Service', 'returns an object with Service'); + t.end(); }); + + t.equal(findResult instanceof Promise, true, 'should return a Promise'); }); }); test('find - services - find - no service name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.services.find().catch((err) => { - t.equal(err.message, 'Service Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.services.find().catch((err) => { + t.equal(err.message, 'Service Name is required', 'error message should return'); + t.end(); }); }); }); test('create - service', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.services.create, 'function', 'There is a create method on the services object'); - - const clientConfig = privates.get(client).config; - const service = { - kind: 'Service' - }; - - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .post(`/api/v1/namespaces/${clientConfig.context.namespace}/services`) - .reply(200, {kind: 'Service'}); - - const createResult = client.services.create(service).then((service) => { - t.equal(service.kind, 'Service', 'returns an object with Service'); - t.end(); - }); - - t.equal(createResult instanceof Promise, true, 'should return a Promise'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.services.create, 'function', 'There is a create method on the services object'); + + const clientConfig = privates.get(client).config; + const service = { + kind: 'Service' + }; + + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .post(`/api/v1/namespaces/${clientConfig.context.namespace}/services`) + .reply(200, {kind: 'Service'}); + + const createResult = client.services.create(service).then((service) => { + t.equal(service.kind, 'Service', 'returns an object with Service'); + t.end(); }); + + t.equal(createResult instanceof Promise, true, 'should return a Promise'); }); }); test('update - service', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.services.create, 'function', 'There is a create method on the services object'); - - const clientConfig = privates.get(client).config; - const service = { - kind: 'Service' - }; - const serviceName = 'cool-service-name-1'; - - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .put(`/api/v1/namespaces/${clientConfig.context.namespace}/services/${serviceName}`) - .reply(200, {kind: 'Service'}); - - const createResult = client.services.update(serviceName, service).then((service) => { - t.equal(service.kind, 'Service', 'returns an object with Service'); - t.end(); - }); - - t.equal(createResult instanceof Promise, true, 'should return a Promise'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.services.create, 'function', 'There is a create method on the services object'); + + const clientConfig = privates.get(client).config; + const service = { + kind: 'Service' + }; + const serviceName = 'cool-service-name-1'; + + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .put(`/api/v1/namespaces/${clientConfig.context.namespace}/services/${serviceName}`) + .reply(200, {kind: 'Service'}); + + const createResult = client.services.update(serviceName, service).then((service) => { + t.equal(service.kind, 'Service', 'returns an object with Service'); + t.end(); }); + + t.equal(createResult instanceof Promise, true, 'should return a Promise'); }); }); test('update - services - update - no service name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.services.update().catch((err) => { - t.equal(err.message, 'Service Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.services.update().catch((err) => { + t.equal(err.message, 'Service Name is required', 'error message should return'); + t.end(); }); }); }); test('remove - services - basic removeAll', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.services.removeAll, 'function', 'There is a removeAll method on the services object'); + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.services.removeAll, 'function', 'There is a removeAll method on the services object'); - const clientConfig = privates.get(client).config; + const clientConfig = privates.get(client).config; - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .delete(`/api/v1/namespaces/${clientConfig.context.namespace}/services`) - .reply(200, {kind: 'Status'}); + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .delete(`/api/v1/namespaces/${clientConfig.context.namespace}/services`) + .reply(200, {kind: 'Status'}); - const removeResult = client.services.removeAll().then((serviceList) => { - t.equal(serviceList.kind, 'Status', 'returns an object with Status'); - t.end(); - }); - - t.equal(removeResult instanceof Promise, true, 'should return a Promise'); + const removeResult = client.services.removeAll().then((serviceList) => { + t.equal(serviceList.kind, 'Status', 'returns an object with Status'); + t.end(); }); + + t.equal(removeResult instanceof Promise, true, 'should return a Promise'); }); }); test('remove - services - basic remove', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; + openshiftRestClient(settings).then((client) => { + t.equal(typeof client.services.remove, 'function', 'There is a remove method on the services object'); - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - t.equal(typeof client.services.remove, 'function', 'There is a remove method on the services object'); + const clientConfig = privates.get(client).config; + const serviceName = 'cool-service-name-1'; - const clientConfig = privates.get(client).config; - const serviceName = 'cool-service-name-1'; + nock(clientConfig.cluster) + .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config + .delete(`/api/v1/namespaces/${clientConfig.context.namespace}/services/${serviceName}`) + .reply(200, {kind: 'Status'}); - nock(clientConfig.cluster) - .matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config - .delete(`/api/v1/namespaces/${clientConfig.context.namespace}/services/${serviceName}`) - .reply(200, {kind: 'Status'}); - - const removeResult = client.services.remove(serviceName).then((status) => { - t.equal(status.kind, 'Status', 'returns an object with Status'); - t.end(); - }); - - t.equal(removeResult instanceof Promise, true, 'should return a Promise'); + const removeResult = client.services.remove(serviceName).then((status) => { + t.equal(status.kind, 'Status', 'returns an object with Status'); + t.end(); }); + + t.equal(removeResult instanceof Promise, true, 'should return a Promise'); }); }); test('remove - services - remove - no service name', (t) => { - const settings = { - configLocation: `${__dirname}/test-config` - }; - - openshiftConfigLoader(settings).then((config) => { - openshiftRestClient(config).then((client) => { - client.services.remove().catch((err) => { - t.equal(err.message, 'Service Name is required', 'error message should return'); - t.end(); - }); + openshiftRestClient(settings).then((client) => { + client.services.remove().catch((err) => { + t.equal(err.message, 'Service Name is required', 'error message should return'); + t.end(); }); }); });