-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
created pg setting auto explain format
- Loading branch information
Showing
3 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
packages/cli/src/commands/pg/settings/auto-explain/log-format.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,27 @@ | ||
import {Args} from '@oclif/core' | ||
import {PGSettingsCommand} from '../../../../lib/pg/setter' | ||
import {Setting, SettingKey} from '../../../../lib/pg/types' | ||
import heredoc from 'tsheredoc' | ||
|
||
export default class LogFormat extends PGSettingsCommand { | ||
static topic = 'pg' | ||
static description = heredoc(` | ||
Selects the EXPLAIN output format to be used. | ||
The allowed values are text, xml, json, and yaml. The default is text. | ||
`) | ||
|
||
static args = { | ||
database: Args.string(), | ||
value: Args.string({options: ['text', 'json', 'yaml', 'xml']}), | ||
} | ||
|
||
protected settingKey: SettingKey = 'auto_explain.log_format' | ||
|
||
protected explain(setting: Setting<string>) { | ||
return `Auto explain log output will log in ${setting.value} format.` | ||
} | ||
|
||
protected convertValue(val: string): string { | ||
return val | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
packages/cli/test/unit/commands/pg/settings/auto-explain/log-format.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,40 @@ | ||
|
||
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/auto-explain/log-format' | ||
import * as fixtures from '../../../../../fixtures/addons/fixtures' | ||
|
||
describe('pg:settings:auto-explain:log-format', function () { | ||
const addon = fixtures.addons['dwh-db'] | ||
let api: nock.Scope | ||
|
||
beforeEach(function () { | ||
api = nock('https://api.heroku.com') | ||
.post('/actions/addons/resolve', { | ||
app: 'myapp', | ||
addon: 'test-database', | ||
}).reply(200, [addon]) | ||
}) | ||
|
||
afterEach(function () { | ||
nock.cleanAll() | ||
}) | ||
|
||
it('updates settings for auto_explain.log_format with value', async function () { | ||
const pg = nock('https://api.data.heroku.com') | ||
.patch(`/postgres/v0/databases/${addon.id}/config`).reply(200, {'auto_explain.log_format': {value: 'json'}}) | ||
|
||
await runCommand(Cmd, ['--app', 'myapp', 'test-database', 'json']) | ||
|
||
api.done() | ||
pg.done() | ||
|
||
expect(stdout.output).to.equal(heredoc(` | ||
auto-explain.log-format has been set to json for ${addon.name}. | ||
Auto explain log output will log in json format. | ||
`)) | ||
}) | ||
}) |