-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new cmd to get runtime env images (#823)
- Loading branch information
1 parent
c03b4fa
commit fa87afe
Showing
5 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
lib/interface/cli/commands/RuntimeEnvironmentBaseImages/get.cmd.js
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,37 @@ | ||
const _ = require('lodash'); | ||
const Command = require('../../Command'); | ||
const RuntimeEnvironmentsImages = require('../../../../logic/entities/RuntimeEnvironmentBaseImages'); | ||
const Output = require('../../../../output/Output'); | ||
require('../../defaults'); | ||
const CFError = require('cf-errors'); // eslint-disable-line | ||
const getRoot = require('../root/get.cmd'); | ||
const { sdk } = require('../../../../logic'); | ||
require('../../../../logic/entities/Environment'); | ||
|
||
const command = new Command({ | ||
command: 'runtime-environment-base-images [name]', | ||
aliases: ['re-base-images'], | ||
parent: getRoot, | ||
description: 'Get a runtime environment base images list that required by this runtime', | ||
webDocs: { | ||
category: 'Runtime-Environments-Base-Images', | ||
title: 'Get Runtime-Environment-Base-Images', | ||
}, | ||
builder: (yargs) => yargs | ||
.positional('name', { | ||
describe: 'Runtime environment name', | ||
}), | ||
handler: async (argv) => { | ||
const { name } = argv; | ||
if (!name) { | ||
throw new CFError('Runtime Name must be provided'); | ||
} | ||
const runtimeEnvImages = await sdk.runtimeEnvs.getBaseImages({ | ||
name, | ||
}); | ||
Output.print(_.map(runtimeEnvImages, RuntimeEnvironmentsImages.fromResponse)); | ||
}, | ||
}); | ||
|
||
|
||
module.exports = command; |
32 changes: 32 additions & 0 deletions
32
...rface/cli/commands/RuntimeEnvironmentBaseImages/runtimeEnvironmentsBaseImages.sdk.spec.js
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,32 @@ | ||
const getCmd = require('./get.cmd').toCommand(); | ||
|
||
jest.mock('../../../../logic/entities/RuntimeEnvironments'); | ||
|
||
const request = require('requestretry'); | ||
|
||
const DEFAULT_RESPONSE = request.__defaultResponse(); | ||
|
||
describe('runtime environment commands', () => { | ||
beforeEach(async () => { | ||
request.__reset(); | ||
request.mockClear(); | ||
await configureSdk(); // eslint-disable-line | ||
}); | ||
|
||
describe('get', () => { | ||
it('should handle getting base images', async () => { | ||
const argv = { name: 'some name' }; | ||
await getCmd.handler(argv); | ||
await verifyResponsesReturned([DEFAULT_RESPONSE]); // eslint-disable-line | ||
}); | ||
|
||
it('should throw an error for missing name', async () => { | ||
try { | ||
const argv = {}; | ||
await getCmd.handler(argv); | ||
} catch (err) { | ||
expect(err.message).toEqual('Runtime Name must be provided'); | ||
} | ||
}); | ||
}); | ||
}); |
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,18 @@ | ||
const Entity = require('./Entity'); | ||
|
||
class RuntimeEnvironmentBaseImages extends Entity { | ||
constructor(data) { | ||
super(); | ||
this.entityType = 'RuntimeEnvironmentBaseImages'; | ||
this.component = data.component; | ||
this.image = data.image; | ||
this.defaultColumns = ['component', 'image']; | ||
this.wideColumns = this.defaultColumns.concat([]); | ||
} | ||
|
||
static fromResponse(response) { | ||
return new RuntimeEnvironmentBaseImages(response); | ||
} | ||
} | ||
module.exports = RuntimeEnvironmentBaseImages; | ||
|
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
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