-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(imagestreamtags): add resource (#90)
- Loading branch information
1 parent
85e5a95
commit fbbf390
Showing
4 changed files
with
312 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
'use strict'; | ||
|
||
/* | ||
* | ||
* Copyright 2016-2017 Red Hat, Inc, and individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
const request = require('./common-request'); | ||
const privates = require('./private-map'); | ||
|
||
function findAll (client) { | ||
return function findAll (options = {}) { | ||
const clientConfig = privates.get(client).config; | ||
|
||
const req = { | ||
method: 'GET', | ||
url: `${client.apiUrl}/namespaces/${clientConfig.context.namespace}/imagestreamtags`, | ||
qs: options.qs | ||
}; | ||
|
||
return request(client, req); | ||
}; | ||
} | ||
|
||
function find (client) { | ||
return function find (imageStreamTagName, options = {}) { | ||
const clientConfig = privates.get(client).config; | ||
|
||
if (!imageStreamTagName) { | ||
return Promise.reject(new Error('Image Stream Tag Name is required')); | ||
} | ||
|
||
const req = { | ||
method: 'GET', | ||
url: `${client.apiUrl}/namespaces/${clientConfig.context.namespace}/imagestreamtags/${imageStreamTagName}` | ||
}; | ||
|
||
return request(client, req); | ||
}; | ||
} | ||
|
||
function create (client) { | ||
return function create (imageStreamTag, options = {}) { | ||
const clientConfig = privates.get(client).config; | ||
|
||
const req = { | ||
method: 'POST', | ||
url: `${client.apiUrl}/namespaces/${clientConfig.context.namespace}/imagestreamtags`, | ||
json: false, | ||
body: JSON.stringify(imageStreamTag) | ||
}; | ||
|
||
return request(client, req).then((body) => { | ||
return JSON.parse(body); | ||
}); | ||
}; | ||
} | ||
|
||
function update (client) { | ||
return function create (imageStreamTagName, imageStreamTag, options = {}) { | ||
const clientConfig = privates.get(client).config; | ||
|
||
if (!imageStreamTagName) { | ||
return Promise.reject(new Error('Image Stream Tag Name is required')); | ||
} | ||
|
||
const req = { | ||
method: 'PUT', | ||
json: false, | ||
url: `${client.apiUrl}/namespaces/${clientConfig.context.namespace}/imagestreamtags/${imageStreamTagName}`, | ||
body: JSON.stringify(imageStreamTag) | ||
}; | ||
|
||
return request(client, req).then((body) => { | ||
return JSON.parse(body); | ||
}); | ||
}; | ||
} | ||
|
||
function remove (client) { | ||
return function remove (imageStreamTagName, options = {}) { | ||
const clientConfig = privates.get(client).config; | ||
|
||
if (!imageStreamTagName) { | ||
return Promise.reject(new Error('Image Stream Tag Name is required')); | ||
} | ||
|
||
const req = { | ||
method: 'DELETE', | ||
url: `${client.apiUrl}/namespaces/${clientConfig.context.namespace}/imagestreamtags/${imageStreamTagName}`, | ||
body: options.body, | ||
qs: options.qs | ||
}; | ||
|
||
return request(client, req); | ||
}; | ||
} | ||
|
||
function removeAll (client) { | ||
return function removeAll (options = {}) { | ||
const clientConfig = privates.get(client).config; | ||
|
||
const req = { | ||
method: 'DELETE', | ||
url: `${client.apiUrl}/namespaces/${clientConfig.context.namespace}/imagestreamtags`, | ||
qs: options.qs | ||
}; | ||
|
||
return request(client, req); | ||
}; | ||
} | ||
|
||
module.exports = { | ||
findAll: findAll, | ||
find: find, | ||
create: create, | ||
update: update, | ||
remove: remove, | ||
removeAll: removeAll | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
'use strict'; | ||
|
||
const test = require('tape'); | ||
const nock = require('nock'); | ||
|
||
const openshiftRestClient = require('../'); | ||
const privates = require('../lib/private-map'); | ||
|
||
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' } | ||
}; | ||
|
||
test('find - imagestreamtags - basic findAll', (t) => { | ||
openshiftRestClient(settings).then((client) => { | ||
t.equal(typeof client.imagestreamtags.findAll, 'function', 'There is a findAll method on the imagestreamtags object'); | ||
|
||
const clientConfig = privates.get(client).config; | ||
|
||
nock(clientConfig.cluster) | ||
.matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config | ||
.get(`/oapi/v1/namespaces/${clientConfig.context.namespace}/imagestreamtags`) | ||
.reply(200, {kind: 'ImageStreamTagList'}); | ||
|
||
const findResult = client.imagestreamtags.findAll().then((imageStreamTagList) => { | ||
t.equal(imageStreamTagList.kind, 'ImageStreamTagList', 'returns an object with ImageStreamTagList'); | ||
t.end(); | ||
}); | ||
|
||
t.equal(findResult instanceof Promise, true, 'should return a Promise'); | ||
}); | ||
}); | ||
|
||
test('find - imagestreamtags - basic find', (t) => { | ||
openshiftRestClient(settings).then((client) => { | ||
t.equal(typeof client.imagestreamtags.find, 'function', 'There is a find method on the imagestreamtags object'); | ||
|
||
const clientConfig = privates.get(client).config; | ||
const imageStreamTagName = 'cool-imagestreamtag-name-1'; | ||
|
||
nock(clientConfig.cluster) | ||
.matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config | ||
.get(`/oapi/v1/namespaces/${clientConfig.context.namespace}/imagestreamtags/${imageStreamTagName}`) | ||
.reply(200, {kind: 'ImageStreamTag'}); | ||
|
||
const findResult = client.imagestreamtags.find(imageStreamTagName).then((imagestreamtag) => { | ||
t.equal(imagestreamtag.kind, 'ImageStreamTag', 'returns an object with ImageStreamTag'); | ||
t.end(); | ||
}); | ||
|
||
t.equal(findResult instanceof Promise, true, 'should return a Promise'); | ||
}); | ||
}); | ||
|
||
test('find - imagestreamtags - find - no imagestreamtag name', (t) => { | ||
openshiftRestClient(settings).then((client) => { | ||
client.imagestreamtags.find().catch((err) => { | ||
t.equal(err.message, 'Image Stream Tag Name is required', 'error message should return'); | ||
t.end(); | ||
}); | ||
}); | ||
}); | ||
|
||
test('create - imagestreamtag', (t) => { | ||
openshiftRestClient(settings).then((client) => { | ||
t.equal(typeof client.imagestreamtags.create, 'function', 'There is a create method on the imagestreamtags object'); | ||
|
||
const clientConfig = privates.get(client).config; | ||
const imagestreamtag = { | ||
kind: 'ImageStreamTag' | ||
}; | ||
|
||
nock(clientConfig.cluster) | ||
.matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config | ||
.post(`/oapi/v1/namespaces/${clientConfig.context.namespace}/imagestreamtags`) | ||
.reply(200, {kind: 'ImageStreamTag'}); | ||
|
||
const createResult = client.imagestreamtags.create(imagestreamtag).then((imagestreamtag) => { | ||
t.equal(imagestreamtag.kind, 'ImageStreamTag', 'returns an object with ImageStreamTag'); | ||
t.end(); | ||
}); | ||
|
||
t.equal(createResult instanceof Promise, true, 'should return a Promise'); | ||
}); | ||
}); | ||
|
||
test('update - imagestreamtag', (t) => { | ||
openshiftRestClient(settings).then((client) => { | ||
t.equal(typeof client.imagestreamtags.create, 'function', 'There is a create method on the imagestreamtags object'); | ||
|
||
const clientConfig = privates.get(client).config; | ||
const imagestreamtag = { | ||
kind: 'ImageStreamTag' | ||
}; | ||
const imageStreamTagName = 'cool-imagestreamtag-name-1'; | ||
|
||
nock(clientConfig.cluster) | ||
.matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config | ||
.put(`/oapi/v1/namespaces/${clientConfig.context.namespace}/imagestreamtags/${imageStreamTagName}`) | ||
.reply(200, {kind: 'ImageStreamTag'}); | ||
|
||
const createResult = client.imagestreamtags.update(imageStreamTagName, imagestreamtag).then((imagestreamtag) => { | ||
t.equal(imagestreamtag.kind, 'ImageStreamTag', 'returns an object with ImageStreamTag'); | ||
t.end(); | ||
}); | ||
|
||
t.equal(createResult instanceof Promise, true, 'should return a Promise'); | ||
}); | ||
}); | ||
|
||
test('update - imagestreamtags - update - no imagestreamtag name', (t) => { | ||
openshiftRestClient(settings).then((client) => { | ||
client.imagestreamtags.update().catch((err) => { | ||
t.equal(err.message, 'Image Stream Tag Name is required', 'error message should return'); | ||
t.end(); | ||
}); | ||
}); | ||
}); | ||
|
||
test('remove - imagestreamtags - basic removeAll', (t) => { | ||
openshiftRestClient(settings).then((client) => { | ||
t.equal(typeof client.imagestreamtags.removeAll, 'function', 'There is a removeAll method on the imagestreamtags object'); | ||
|
||
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}/imagestreamtags`) | ||
.reply(200, {kind: 'Status'}); | ||
|
||
const removeResult = client.imagestreamtags.removeAll().then((imageStreamTagList) => { | ||
t.equal(imageStreamTagList.kind, 'Status', 'returns an object with Status'); | ||
t.end(); | ||
}); | ||
|
||
t.equal(removeResult instanceof Promise, true, 'should return a Promise'); | ||
}); | ||
}); | ||
|
||
test('remove - imagestreamtags - basic remove', (t) => { | ||
openshiftRestClient(settings).then((client) => { | ||
t.equal(typeof client.imagestreamtags.remove, 'function', 'There is a remove method on the imagestreamtags object'); | ||
|
||
const clientConfig = privates.get(client).config; | ||
const imageStreamTagName = 'cool-imagestreamtag-name-1'; | ||
|
||
nock(clientConfig.cluster) | ||
.matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config | ||
.delete(`/oapi/v1/namespaces/${clientConfig.context.namespace}/imagestreamtags/${imageStreamTagName}`) | ||
.reply(200, {kind: 'Status'}); | ||
|
||
const removeResult = client.imagestreamtags.remove(imageStreamTagName).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 - imagestreamtags - remove - no imagestreamtag name', (t) => { | ||
openshiftRestClient(settings).then((client) => { | ||
client.imagestreamtags.remove().catch((err) => { | ||
t.equal(err.message, 'Image Stream Tag Name is required', 'error message should return'); | ||
t.end(); | ||
}); | ||
}); | ||
}); |