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

Commit

Permalink
Attaching default is like not specifying credential (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
camillebaldock authored May 25, 2017
1 parent d2570f9 commit 5cca1d7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions commands/addons/attach.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function * run (context, heroku) {
addon: {name: addon.name},
confirm
}
if (credential) {
if (credential && credential !== 'default') {
body.namespace = 'credential:' + credential
}
return cli.action(
Expand All @@ -29,7 +29,7 @@ function * run (context, heroku) {
)
}

if (context.flags.credential) {
if (context.flags.credential && context.flags.credential !== 'default') {
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}`)
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 @@ -68,6 +68,22 @@ Setting foo config vars and restarting myapp... done, v10
.then(() => api.done())
})

it('attaches an addon without a namespace if the credential flag is set to default', function () {
let api = nock('https://api.heroku.com:443')
.get('/addons/postgres-123')
.reply(200, {name: 'postgres-123'})
.post('/addon-attachments', {app: {name: 'myapp'}, addon: {name: 'postgres-123'}})
.reply(201, {name: 'POSTGRES_HELLO'})
.get('/apps/myapp/releases')
.reply(200, [{version: 10}])
return cmd.run({app: 'myapp', args: {addon_name: 'postgres-123'}, flags: {credential: 'default'}})
.then(() => expect(cli.stdout, 'to be empty'))
.then(() => expect(cli.stderr, 'to equal', `Attaching default of postgres-123 to myapp... done
Setting POSTGRES_HELLO config vars and restarting myapp... done, v10
`))
.then(() => api.done())
})

it('attaches in the credential namespace if the credential flag is specified', function () {
let api = nock('https://api.heroku.com:443')
.get('/addons/postgres-123')
Expand Down

0 comments on commit 5cca1d7

Please sign in to comment.