Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate(W-14179932): pg-v5: Upgrade pg:settings:log-connections #2784

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
36 changes: 36 additions & 0 deletions packages/cli/src/commands/pg/settings/log-connections.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {flags} from '@heroku-cli/command'
import {Args} from '@oclif/core'
import heredoc from 'tsheredoc'
import {type BooleanAsString, booleanConverter, PGSettingsCommand} from '../../../lib/pg/setter'
import type {Setting, SettingKey} from '../../../lib/pg/types'

export default class LogConnections extends PGSettingsCommand {
static topic = 'pg'
static description = heredoc(`
Controls whether a log message is produced when a login attempt is made. Default is true.
Setting log_connections to false stops emitting log messages for all attempts to login to the database.`)

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

static args = {
database: Args.string(),
value: Args.string(),
}

protected settingKey: SettingKey = 'log_connections'

protected convertValue(val: unknown): unknown {
return booleanConverter(val as BooleanAsString)
}

protected explain(setting: Setting<unknown>): string {
if (setting.value) {
return 'When login attempts are made, a log message will be emitted in your application\'s logs.'
}

return 'When login attempts are made, no log message will be emitted in your application\'s logs.'
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import {expect} from '@oclif/test'
import * as nock from 'nock'
import {stdout} from 'stdout-stderr'
import heredoc from 'tsheredoc'
import runCommand from '../../../../helpers/runCommand'
import Cmd from '../../../../../src/commands/pg/settings/log-connections'

describe('pg:settings:log-connections', () => {
let api: nock.Scope
let pg: nock.Scope

beforeEach(() => {
const addon = {
id: 1,
name: 'postgres-1',
app: {name: 'myapp'},
config_vars: ['READONLY_URL', 'DATABASE_URL', 'HEROKU_POSTGRESQL_RED_URL'],
plan: {name: 'heroku-postgresql:standard-0'},
}

api = nock('https://api.heroku.com')
api.post('/actions/addons/resolve', {
app: 'myapp',
addon: 'test-database',
}).reply(200, [addon])

pg = nock('https://api.data.heroku.com')
})

afterEach(() => {
api.done()
pg.done()
})

it('shows settings for auto_explain with value', async () => {
pg.get('/postgres/v0/databases/1/config').reply(200, {log_connections: {value: 'test_value'}})
await runCommand(Cmd, ['--app', 'myapp', 'test-database'])
expect(stdout.output).to.equal(heredoc(`
log-connections is set to test_value for postgres-1.
When login attempts are made, a log message will be emitted in your application's logs.
`))
})

it('shows settings for auto_explain with no value', async () => {
pg.get('/postgres/v0/databases/1/config').reply(200, {log_connections: {value: ''}})
await runCommand(Cmd, ['--app', 'myapp', 'test-database'])
expect(stdout.output).to.equal(heredoc(`
log-connections is set to for postgres-1.
When login attempts are made, no log message will be emitted in your application's logs.
`))
})
})
23 changes: 0 additions & 23 deletions packages/pg-v5/commands/settings/log_connections.js

This file was deleted.

Loading