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
87 changes: 87 additions & 0 deletions packages/cli/test/unit/commands/autocomplete/index.unit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/* eslint-disable mocha/no-top-level-hooks */
import {runCommand} from '@oclif/test'
import {expect} from 'chai'
import nock from 'nock'

// autocomplete will throw error on windows
import {default as runtest} from '../../../helpers/autocomplete/runtest.js'

runtest('autocomplete:index', () => {
let api: nock.Scope

beforeEach(function () {
api = nock('https://api.heroku.com')
})
afterEach(function () {
api.done()
nock.cleanAll()
})

it('provides bash instructions', async function () {
api
.get('/apps')
.reply(200, [{name: 'foo'}, {name: 'bar'}])
.get('/pipelines')
.reply(200, [{name: 'foo'}, {name: 'bar'}])
.get('/spaces')
.reply(200, [{name: 'foo'}, {name: 'bar'}])
.get('/teams')
.reply(200, [{name: 'foo'}, {name: 'bar'}])

const {stdout} = await runCommand(['autocomplete', 'bash'])

expect(stdout).to.contain(`
Setup Instructions for HEROKU CLI Autocomplete ---

1) Add the autocomplete env var to your bash profile and source it
$ printf "$(heroku autocomplete:script bash)" >> ~/.bashrc; source ~/.bashrc

NOTE: If your terminal starts as a login shell you may need to print the init script into ~/.bash_profile or ~/.profile.

2) Test it out, e.g.:
$ heroku <TAB><TAB> # Command completion
$ heroku apps:info --<TAB><TAB> # Flag completion
$ heroku apps:info --app=<TAB><TAB> # Flag option completion

Visit the autocomplete Dev Center doc at https://devcenter.heroku.com/articles/heroku-cli-autocomplete

Enjoy!

`,
)
})

it('provides zsh instructions', async function () {
api
.get('/apps')
.reply(200, [{name: 'foo'}, {name: 'bar'}])
.get('/pipelines')
.reply(200, [{name: 'foo'}, {name: 'bar'}])
.get('/spaces')
.reply(200, [{name: 'foo'}, {name: 'bar'}])
.get('/teams')
.reply(200, [{name: 'foo'}, {name: 'bar'}])

const {stdout} = await runCommand(['autocomplete', 'zsh'])

expect(stdout).to.contain(`
Setup Instructions for HEROKU CLI Autocomplete ---

1) Add the autocomplete env var to your zsh profile and source it
$ printf "$(heroku autocomplete:script zsh)" >> ~/.zshrc; source ~/.zshrc

NOTE: After sourcing, you can run \`$ compaudit -D\` to ensure no permissions conflicts are present

2) Test it out, e.g.:
$ heroku <TAB> # Command completion
$ heroku apps:info --<TAB> # Flag completion
$ heroku apps:info --app=<TAB> # Flag option completion

Visit the autocomplete Dev Center doc at https://devcenter.heroku.com/articles/heroku-cli-autocomplete

Enjoy!

`,
)
})
})

This file was deleted.

37 changes: 37 additions & 0 deletions packages/cli/test/unit/commands/autocomplete/script.unit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {runCommand} from '@oclif/test'
import {expect} from 'chai'

import {default as runtest} from '../../../helpers/autocomplete/runtest.js'
import {getConfig} from '../../../helpers/testInstances.js'

runtest('autocomplete:script', () => {
it('outputs bash profile config', async function () {
const config = await getConfig()
const {stdout} = await runCommand(['autocomplete:script', 'bash'])

expect(stdout).to.contain(`
# heroku autocomplete setup
HEROKU_AC_BASH_SETUP_PATH=${
config.cacheDir
}/autocomplete/bash_setup && test -f $HEROKU_AC_BASH_SETUP_PATH && source $HEROKU_AC_BASH_SETUP_PATH;
`)
})

it('outputs zsh profile config', async function () {
const config = await getConfig()
const {stdout} = await runCommand(['autocomplete:script', 'zsh'])

expect(stdout).to.contain(`
# heroku autocomplete setup
HEROKU_AC_ZSH_SETUP_PATH=${
config.cacheDir
}/autocomplete/zsh_setup && test -f $HEROKU_AC_ZSH_SETUP_PATH && source $HEROKU_AC_ZSH_SETUP_PATH;
`)
})

it('errors on unsupported shell', async function () {
const {error} = await runCommand(['autocomplete:script', 'fish'])

expect(error?.message).to.contain('fish is not a supported shell for autocomplete')
})
})

This file was deleted.

27 changes: 27 additions & 0 deletions packages/cli/test/unit/commands/drains/add.unit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {runCommand} from '@oclif/test'
import {expect} from 'chai'
import nock from 'nock'

describe('drains:add', function () {
let api: nock.Scope

beforeEach(function () {
api = nock('https://api.heroku.com')
})

afterEach(function () {
api.done()
nock.cleanAll()
})

it('adds a log drain', async function () {
api
.post('/apps/myapp/log-drains', {url: 'syslog://logs.example.com'})
.reply(200, {url: 'syslog://logs.example.com'})

const {stderr, stdout} = await runCommand(['drains:add', '-a', 'myapp', 'syslog://logs.example.com'])

expect(stdout).to.equal('Successfully added drain syslog://logs.example.com\n')
expect(stderr).to.equal('')
})
})
17 changes: 0 additions & 17 deletions packages/cli/test/unit/commands/drains/add.unit.test.ts.skip

This file was deleted.

Loading
Loading