-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(redis-v5): Move redis:promite command to CLI
- Loading branch information
1 parent
a4f5b31
commit 3b8a03a
Showing
6 changed files
with
127 additions
and
127 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,39 @@ | ||
import {Command, flags} from '@heroku-cli/command' | ||
import {Args, ux} from '@oclif/core' | ||
import * as Heroku from '@heroku-cli/schema' | ||
import apiFactory from '../../lib/redis/api' | ||
export default class Promote extends Command { | ||
static topic = 'redis' | ||
static description = 'sets DATABASE as your REDIS_URL' | ||
static flags = { | ||
app: flags.app({required: true}), | ||
} | ||
|
||
static args = { | ||
database: Args.string({required: false}), | ||
} | ||
|
||
public async run(): Promise<void> { | ||
const {flags, args} = await this.parse(Promote) | ||
const api = apiFactory(flags.app, args.database, false, this.heroku) | ||
const {body: addonsList} = await this.heroku.get<Required<Heroku.AddOn>[]>(`/apps/${flags.app}/addons`) | ||
const addon = await api.getRedisAddon(addonsList) | ||
const redisFilter = api.makeAddonsFilter('REDIS_URL') | ||
const redis = redisFilter(addonsList) as Required<Heroku.AddOn>[] | ||
if (redis.length === 1 && redis[0].config_vars.filter((c: string) => c.endsWith('_URL')).length === 1) { | ||
const attachment = redis[0] | ||
await this.heroku.post('/addon-attachments', { | ||
body: { | ||
app: {name: flags.app}, addon: {name: attachment.name}, confirm: flags.app, | ||
}, | ||
}) | ||
} | ||
|
||
ux.log(`Promoting ${addon.name} to REDIS_URL on ${flags.app}`) | ||
await this.heroku.post('/addon-attachments', { | ||
body: { | ||
app: {name: flags.app}, addon: {name: addon.name}, confirm: flags.app, name: 'REDIS', | ||
}, | ||
}) | ||
} | ||
} |
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
84 changes: 84 additions & 0 deletions
84
packages/cli/test/unit/commands/redis/promote.unit.test.ts
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,84 @@ | ||
import {expect} from '@oclif/test' | ||
import * as nock from 'nock' | ||
import {stderr, stdout} from 'stdout-stderr' | ||
import Cmd from '../../../../src/commands/redis/promote' | ||
import runCommand from '../../../helpers/runCommand' | ||
|
||
describe('heroku redis:promote', () => { | ||
require('../../lib/redis/shared.unit.test.ts').shouldHandleArgs(Cmd) | ||
}) | ||
|
||
describe('heroku redis:promote', async () => { | ||
beforeEach(async () => nock.cleanAll()) | ||
|
||
it('# promotes', async () => { | ||
const app = nock('https://api.heroku.com:443') | ||
.get('/apps/example/addons') | ||
.reply(200, [ | ||
{ | ||
name: 'redis-silver-haiku', | ||
addon_service: {name: 'heroku-redis'}, | ||
config_vars: ['REDIS_URL', 'HEROKU_REDIS_SILVER_URL'], | ||
}, { | ||
name: 'redis-gold-haiku', | ||
addon_service: {name: 'heroku-redis'}, | ||
config_vars: ['HEROKU_REDIS_GOLD_URL'], | ||
}, | ||
]) | ||
|
||
const attach = nock('https://api.heroku.com:443') | ||
.post('/addon-attachments', { | ||
app: {name: 'example'}, addon: {name: 'redis-gold-haiku'}, confirm: 'example', name: 'REDIS', | ||
}) | ||
.reply(200, {}) | ||
|
||
await runCommand(Cmd, [ | ||
'--app', | ||
'example', | ||
'redis-gold-haiku', | ||
]) | ||
app.done() | ||
attach.done() | ||
expect(stdout.output).to.equal('Promoting redis-gold-haiku to REDIS_URL on example\n') | ||
expect(stderr.output).to.equal('') | ||
}) | ||
|
||
it('# promotes and replaces attachment of existing REDIS_URL if necessary', async () => { | ||
const app = nock('https://api.heroku.com:443') | ||
.get('/apps/example/addons') | ||
.reply(200, [ | ||
{ | ||
name: 'redis-silver-haiku', addon_service: {name: 'heroku-redis'}, config_vars: [ | ||
'REDIS_URL', | ||
'REDIS_BASTIONS', | ||
'REDIS_BASTION_KEY', | ||
'REDIS_BASTION_REKEYS_AFTER', | ||
], | ||
}, { | ||
name: 'redis-gold-haiku', | ||
addon_service: {name: 'heroku-redis'}, | ||
config_vars: ['HEROKU_REDIS_GOLD_URL'], | ||
}, | ||
]) | ||
const attachRedisUrl = nock('https://api.heroku.com:443') | ||
.post('/addon-attachments', { | ||
app: {name: 'example'}, addon: {name: 'redis-silver-haiku'}, confirm: 'example', | ||
}) | ||
.reply(200, {}) | ||
const attach = nock('https://api.heroku.com:443') | ||
.post('/addon-attachments', { | ||
app: {name: 'example'}, addon: {name: 'redis-gold-haiku'}, confirm: 'example', name: 'REDIS', | ||
}) | ||
.reply(200, {}) | ||
await runCommand(Cmd, [ | ||
'--app', | ||
'example', | ||
'redis-gold-haiku', | ||
]) | ||
app.done() | ||
attachRedisUrl.done() | ||
attach.done() | ||
expect(stdout.output).to.equal('Promoting redis-gold-haiku to REDIS_URL on example\n') | ||
expect(stderr.output).to.equal('') | ||
}) | ||
}) |
This file was deleted.
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
This file was deleted.
Oops, something went wrong.