Skip to content

Commit

Permalink
refactor(container-registry-v5): move container:rm to CLI & upgrade t…
Browse files Browse the repository at this point in the history
…o oclif (#2656)

* Convert container:rm to oclif

* Convert rm test to test oclif version

* Remove rm from container-v5

* Update test output check

* Include docker variant header and expect it in test
  • Loading branch information
eablack authored Feb 27, 2024
1 parent aa8060d commit ee9fec1
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 85 deletions.
38 changes: 38 additions & 0 deletions packages/cli/src/commands/container/rm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {Command, flags} from '@heroku-cli/command'
import {ux} from '@oclif/core'
import color from '@heroku-cli/color'

export default class Rm extends Command {
static topic = 'container'
static description = 'remove the process type from your app'
static usage = '$ heroku container:rm -a APP [-v] PROCESS_TYPE...'
static example = `
${color.cmd('heroku container:rm web')} # Destroys the web container
${color.cmd('heroku container:rm web worker')} # Destroys the web and worker containers`

static strict = false

static flags = {
app: flags.app({required: true}),
}

async run() {
const {argv, flags} = await this.parse(Rm)
const {app} = flags

if (argv.length === 0) {
this.error(`Error: Requires one or more process types\n${Rm.example}`)
}

for (const process of argv as string[]) {
ux.action.start(`Removing container ${process} for ${color.app(app)}`)
await this.heroku.patch(`/apps/${app}/formation/${process}`, {
headers: {
Accept: 'application/vnd.heroku+json; version=3.docker-releases',
},
body: {docker_image: null},
})
ux.action.stop()
}
}
}
54 changes: 54 additions & 0 deletions packages/cli/test/unit/commands/rm.unit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import {stdout, stderr} from 'stdout-stderr'
import Cmd from '../../../src/commands/container/rm'
import runCommand from '../../helpers/runCommand'
import expectOutput from '../../helpers/utils/expectOutput'
import * as nock from 'nock'
import {expect} from 'chai'

describe('container removal', () => {
it('removes one container', async () => {
nock('https://api.heroku.com', {reqheaders: {Accept: 'application/vnd.heroku+json; version=3.docker-releases'}})
.patch('/apps/testapp/formation/web')
.reply(200, {})
await runCommand(Cmd, [
'--app',
'testapp',
'web',
])
expectOutput(stdout.output, '')
expectOutput(stderr.output, `
Removing container web for ⬢ testapp...
Removing container web for ⬢ testapp... done
`)
})
it('removes two containers', async () => {
nock('https://api.heroku.com', {reqheaders: {Accept: 'application/vnd.heroku+json; version=3.docker-releases'}})
.patch('/apps/testapp/formation/web')
.reply(200, {})
.patch('/apps/testapp/formation/worker')
.reply(200, {})
await runCommand(Cmd, [
'--app',
'testapp',
'web',
'worker',
])
expectOutput(stdout.output, '')
expectOutput(stderr.output, `
Removing container web for ⬢ testapp...
Removing container web for ⬢ testapp... done
Removing container worker for ⬢ testapp...
Removing container worker for ⬢ testapp... done
`)
})

it('requires a container to be specified', async () => {
await runCommand(Cmd, [
'--app',
'testapp',
]).catch((error: any) => {
expect(error.message).to.contain('Requires one or more process types')
})
expectOutput(stdout.output, '')
})
})
36 changes: 0 additions & 36 deletions packages/container-registry-v5/commands/rm.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/container-registry-v5/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ module.exports = {
help: pkg.description,
},
commands: [
require('./commands/rm')(pkg.topic),
require('./commands/push')(pkg.topic),
require('./commands/release')(pkg.topic),
require('./commands/run')(pkg.topic),
Expand Down
48 changes: 0 additions & 48 deletions packages/container-registry-v5/test/unit/commands/rm.unit.test.js

This file was deleted.

0 comments on commit ee9fec1

Please sign in to comment.