Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/commands/run/inside.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ import debugFactory from 'debug'
import tsheredoc from 'tsheredoc'

import Dyno from '../../lib/run/dyno.js'
import {buildCommandWithLauncher} from '../../lib/run/helpers.js'
import {buildCommandWithLauncher, revertSortedArgs} from '../../lib/run/helpers.js'

const debug = debugFactory('heroku:run:inside')
const heredoc = tsheredoc.default

export default class RunInside extends Command {
static args = {
command: Args.string({
description: 'command to run (Heroku automatically prepends \'launcher\' to the command)',
required: true,
}),
dyno_name: Args.string({
description: 'name of the dyno to run command inside',
required: true,
}),
command: Args.string({
description: 'command to run (Heroku automatically prepends \'launcher\' to the command)',
required: true,
}),
}

static description = 'run a command inside an existing dyno (for Fir-generation apps only)'
Expand Down Expand Up @@ -57,13 +57,15 @@ export default class RunInside extends Command {

async run() {
const {args, argv, flags} = await this.parse(RunInside)
const orderedArgs = revertSortedArgs(process.argv, argv as string[])
const commandArgs = orderedArgs.slice(1)

const {dyno_name: dynoName} = args
const {app: appName, 'exit-code': exitCode, listen, 'no-launcher': noLauncher} = flags

const opts = {
app: appName,
command: await buildCommandWithLauncher(this.heroku, appName, argv.slice(1) as string[], noLauncher),
command: await buildCommandWithLauncher(this.heroku, appName, commandArgs, noLauncher),
dyno: dynoName,
'exit-code': exitCode,
heroku: this.heroku,
Expand Down
62 changes: 56 additions & 6 deletions test/unit/commands/run/inside.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,35 @@ import RunInside from '../../../../src/commands/run/inside.js'
import runCommand from '../../../helpers/runCommand.js'

describe('run:inside', function () {
const originalProcessArgv = [...process.argv]

const runWithCliArgv = async (args: string[]) => {
process.argv = [
'/usr/local/bin/node',
'/usr/local/bin/heroku',
'run:inside',
...args,
]

return runCommand(RunInside, args)
}

beforeEach(function () {
nock.cleanAll()
nock.disableNetConnect()
})

afterEach(function () {
nock.enableNetConnect()
process.argv = [...originalProcessArgv]
})

it('requires a dyno name and command', async function () {
nock('https://api.heroku.com')
.get('/apps/myapp')
.reply(200, {name: 'myapp', stack: {name: 'heroku-20'}})

await runCommand(RunInside, [
await runWithCliArgv([
'--app',
'myapp',
]).catch(error => {
Expand All @@ -32,7 +46,10 @@ describe('run:inside', function () {
nock('https://api.heroku.com')
.get('/apps/myapp')
.reply(200, {name: 'myapp', stack: {name: 'heroku-20'}})
.post('/apps/myapp/dynos/web.1')
.post('/apps/myapp/dynos/web.1', body => {
expect(body.command).to.equal('bash')
return true
})
.reply(201, {
attach_url: 'rendezvous://rendezvous.runtime.heroku.com:5000',
command: 'bash',
Expand All @@ -45,7 +62,7 @@ describe('run:inside', function () {
updated_at: '2020-01-01T00:00:00Z',
})

await runCommand(RunInside, [
await runWithCliArgv([
'web.1',
'bash',
'--app',
Expand All @@ -72,7 +89,7 @@ describe('run:inside', function () {
updated_at: '2020-01-01T00:00:00Z',
})

await runCommand(RunInside, [
await runWithCliArgv([
'web.1',
'false',
'--app',
Expand All @@ -88,7 +105,10 @@ describe('run:inside', function () {
nock('https://api.heroku.com')
.get('/apps/myapp')
.reply(200, {name: 'myapp', stack: {name: 'cnb'}})
.post('/apps/myapp/dynos/web.1')
.post('/apps/myapp/dynos/web.1', body => {
expect(body.command).to.equal('bash')
return true
})
.reply(201, {
attach_url: 'rendezvous://rendezvous.runtime.heroku.com:5000',
command: 'bash',
Expand All @@ -101,7 +121,7 @@ describe('run:inside', function () {
updated_at: '2020-01-01T00:00:00Z',
})

await runCommand(RunInside, [
await runWithCliArgv([
'web.1',
'bash',
'--app',
Expand All @@ -111,4 +131,34 @@ describe('run:inside', function () {
// Expected to fail when trying to connect
})
})

it('prepends launcher by default on cnb apps', async function () {
nock('https://api.heroku.com')
.get('/apps/myapp')
.reply(200, {name: 'myapp', stack: {name: 'cnb'}})
.post('/apps/myapp/dynos/web.1', body => {
expect(body.command).to.equal('launcher bash')
return true
})
.reply(201, {
attach_url: 'rendezvous://rendezvous.runtime.heroku.com:5000',
command: 'launcher bash',
created_at: '2020-01-01T00:00:00Z',
id: '12345678-1234-1234-1234-123456789012',
name: 'web.1',
size: 'basic',
state: 'starting',
type: 'web',
updated_at: '2020-01-01T00:00:00Z',
})

await runWithCliArgv([
'web.1',
'bash',
'--app',
'myapp',
]).catch(() => {
// Expected to fail when trying to connect
})
})
})
Loading