Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
Error when trying to attach a credential that does not exist (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
camillebaldock committed May 19, 2017
1 parent cc7776f commit d2570f9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions commands/addons/attach.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ function * run (context, heroku) {
)
}

if (context.flags.credential) {
let credentialConfig = yield heroku.get(`/addons/${addon.name}/config/credential:${context.flags.credential}`)
if (credentialConfig.length === 0) {
throw new Error(`Could not find credential ${context.flags.credential} for database ${addon.name}`)
}
}

let attachment = yield util.trapConfirmationRequired(context.app, context.flags.confirm, (confirm) => createAttachment(app, context.flags.as, confirm, context.flags.credential))

yield cli.action(
Expand Down
16 changes: 16 additions & 0 deletions test/commands/addons/attach.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ Setting foo config vars and restarting myapp... done, v10
let api = nock('https://api.heroku.com:443')
.get('/addons/postgres-123')
.reply(200, {name: 'postgres-123'})
.get('/addons/postgres-123/config/credential:hello')
.reply(200, [{some: 'config'}])
.post('/addon-attachments', {app: {name: 'myapp'}, addon: {name: 'postgres-123'}, namespace: 'credential:hello'})
.reply(201, {name: 'POSTGRES_HELLO'})
.get('/apps/myapp/releases')
Expand All @@ -83,4 +85,18 @@ Setting POSTGRES_HELLO config vars and restarting myapp... done, v10
`))
.then(() => api.done())
})

it('errors if the credential flag is specified but that credential does not exist for that addon', function () {
nock('https://api.heroku.com:443')
.get('/addons/postgres-123')
.reply(200, {name: 'postgres-123'})
.get('/addons/postgres-123/config/credential:hello')
.reply(200, [])

return expect(cmd.run({
app: 'myapp',
args: {addon_name: 'postgres-123'},
flags: {credential: 'hello'}
}), 'to be rejected with error satisfying', new Error('Could not find credential hello for database postgres-123'))
})
})

0 comments on commit d2570f9

Please sign in to comment.