2025-12-05 17:28:39 -05:00
|
|
|
/**
|
|
|
|
|
* Copyright IBM Corp. 2016, 2025
|
|
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { module, test } from 'qunit';
|
|
|
|
|
import { setupTest } from 'ember-qunit';
|
2025-12-17 12:20:19 -05:00
|
|
|
import { cliTemplate } from 'core/utils/code-generators/cli';
|
2025-12-05 17:28:39 -05:00
|
|
|
|
|
|
|
|
module('Integration | Util | code-generators/cli', function (hooks) {
|
|
|
|
|
setupTest(hooks);
|
|
|
|
|
|
2025-12-17 12:20:19 -05:00
|
|
|
test('cliTemplate: it formats CLI command with content', async function (assert) {
|
2025-12-05 17:28:39 -05:00
|
|
|
const content = `- <<EOT
|
|
|
|
|
path "secret/*" {
|
|
|
|
|
capabilities = ["read"]
|
|
|
|
|
}
|
|
|
|
|
EOT`;
|
2025-12-17 12:20:19 -05:00
|
|
|
const formatted = cliTemplate({ command: 'policy write my-policy', content });
|
2025-12-05 17:28:39 -05:00
|
|
|
const expected = `vault policy write my-policy ${content}`;
|
|
|
|
|
assert.strictEqual(formatted, expected, 'it formats CLI command with content');
|
|
|
|
|
});
|
|
|
|
|
|
2025-12-17 12:20:19 -05:00
|
|
|
test('cliTemplate: it handles empty content', async function (assert) {
|
|
|
|
|
const formatted = cliTemplate({ command: 'policy list', content: '' });
|
2025-12-05 17:28:39 -05:00
|
|
|
const expected = 'vault policy list';
|
|
|
|
|
assert.strictEqual(formatted, expected, 'it formats CLI command with empty content');
|
|
|
|
|
});
|
2025-12-17 12:20:19 -05:00
|
|
|
|
|
|
|
|
test('cliTemplate: it only supplies placeholder "[args]" when there is no command', async function (assert) {
|
|
|
|
|
let formatted = cliTemplate();
|
|
|
|
|
let expected = 'vault <command> [args]';
|
|
|
|
|
assert.strictEqual(formatted, expected, 'it formats CLI command with undefined args');
|
|
|
|
|
|
|
|
|
|
formatted = cliTemplate({ command: 'read my-secret' });
|
|
|
|
|
expected = 'vault read my-secret';
|
|
|
|
|
assert.strictEqual(formatted, expected, 'it formats CLI command without "[args]" placeholder');
|
|
|
|
|
|
|
|
|
|
formatted = cliTemplate({ command: '' });
|
|
|
|
|
expected = 'vault <command> [args]';
|
|
|
|
|
assert.strictEqual(
|
|
|
|
|
formatted,
|
|
|
|
|
expected,
|
|
|
|
|
'it formats CLI command with placeholders content is an empty string'
|
|
|
|
|
);
|
|
|
|
|
});
|
2025-12-05 17:28:39 -05:00
|
|
|
});
|