-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding luis:version:delete cmd #355
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7ece99c
Adding luis:version:delete cmd
8aef155
Make error mssg check more specific
c0b7695
Merge branch 'master' into 304-luis-version-delete
8d6f49e
Removing unused function in utils, boot test coverage
a8d6d2d
Merge branch '304-luis-version-delete' of https://github.com/microsof…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,49 @@ | ||
/*! | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
import {CLIError, Command, flags} from '@microsoft/bf-cli-command' | ||
|
||
const utils = require('../../../utils/index') | ||
|
||
export default class LuisVersionDelete extends Command { | ||
static description = 'Deletes a version of a LUIS application' | ||
|
||
static examples = [` | ||
$ bf luis:version:delete --appId {APP_ID} --versionId {VERSION_ID} --endpoint {ENDPOINT} --subscriptionKey {SUBSCRIPTION_KEY} | ||
`] | ||
|
||
static flags = { | ||
help: flags.help({char: 'h'}), | ||
appId: flags.string({description: 'LUIS application Id'}), | ||
versionId: flags.string({description: 'LUIS application version Id'}), | ||
endpoint: flags.string({description: 'LUIS endpoint hostname'}), | ||
subscriptionKey: flags.string({description: 'LUIS cognitive services subscription key (aka Ocp-Apim-Subscription-Key)'}), | ||
} | ||
|
||
async run() { | ||
const {flags} = this.parse(LuisVersionDelete) | ||
const flagLabels = Object.keys(LuisVersionDelete.flags) | ||
const configDir = this.config.configDir | ||
|
||
const { | ||
appId, | ||
versionId, | ||
endpoint, | ||
subscriptionKey, | ||
} = await utils.processInputs(flags, flagLabels, configDir) | ||
|
||
const requiredProps = {appId, versionId, endpoint, subscriptionKey} | ||
utils.validateRequiredProps(requiredProps) | ||
|
||
const client = utils.getLUISClient(subscriptionKey, endpoint) | ||
|
||
try { | ||
await client.versions.deleteMethod(appId, versionId) | ||
this.log(`Successfully deleted version ${versionId}`) | ||
} catch (err) { | ||
throw new CLIError(`Failed to delete app version: ${err}`) | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import {expect, test} from '@oclif/test' | ||
const sinon = require('sinon') | ||
const uuidv1 = require('uuid/v1') | ||
const utils = require('../../../../src/utils/index') | ||
|
||
describe('luis:version:delete', () => { | ||
|
||
beforeEach(() => { | ||
sinon.stub(utils, 'processInputs').returnsArg(0) | ||
}) | ||
|
||
afterEach(() => { | ||
sinon.restore(); | ||
}); | ||
|
||
test | ||
.stdout() | ||
.command(['luis:version:delete', '--help']) | ||
.it('should print the help contents when --help is passed as an argument', ctx => { | ||
expect(ctx.stdout).to.contain('Deletes a version of a LUIS application') | ||
}) | ||
|
||
test | ||
.stdout() | ||
.stderr() | ||
.command(['luis:version:delete', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--subscriptionKey', uuidv1()]) | ||
.it('displays an error if any required input parameters are missing', ctx => { | ||
expect(ctx.stderr).to.contain(`Required input property 'appId' missing.`) | ||
}) | ||
|
||
test | ||
.stdout() | ||
.stderr() | ||
.command(['luis:version:delete', '--appId', uuidv1(), '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--subscriptionKey', uuidv1()]) | ||
.it('displays an error if any required input parameters are missing', ctx => { | ||
expect(ctx.stderr).to.contain(`Required input property 'versionId' missing.`) | ||
}) | ||
|
||
test | ||
.nock('https://westus.api.cognitive.microsoft.com', api => api | ||
.delete(uri => uri.includes('version')) | ||
.reply(200) | ||
) | ||
.stdout() | ||
.command(['luis:version:delete', '--appId', uuidv1(), '--versionId', '0.2', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--subscriptionKey', uuidv1()]) | ||
.it('deletes a luis app and displays a success message', ctx => { | ||
expect(ctx.stdout).to.contain('Successfully deleted version') | ||
}) | ||
|
||
test | ||
.stdout() | ||
.stderr() | ||
.command(['luis:version:delete', '--appId', uuidv1(), '--versionId', '0.2', '--endpoint', 'undefined', '--subscriptionKey', uuidv1()]) | ||
.it('fails to delete an app and displays an error message if the endpoint is undefined', ctx => { | ||
expect(ctx.stderr).to.contain('Failed to delete app version') | ||
}) | ||
|
||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the azure client 'deleteMethod' returns null, so I just await it and output a success message if there's no error. their api is a little inconsistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@christopheranderson should we open a bug against the sdk on details like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, definitely should.