Skip to content

Commit

Permalink
refactor(cli): consolidate common run flags in same file (#2390)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardobridge authored Jan 2, 2024
1 parent fc9b91a commit aec0b89
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 151 deletions.
65 changes: 65 additions & 0 deletions packages/artillery/lib/cli/common-flags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const { Flags } = require('@oclif/core');

const CommonRunFlags = {
target: Flags.string({
char: 't',
description:
'Set target endpoint. Overrides the target already set in the test script'
}),
config: Flags.string({
char: 'c',
description: 'Read configuration for the test from the specified file'
}),
// TODO: Replace with --profile
environment: Flags.string({
char: 'e',
description: 'Use one of the environments specified in config.environments'
}),
'scenario-name': Flags.string({
description: 'Name of the specific scenario to run'
}),
output: Flags.string({
char: 'o',
description: 'Write a JSON report to file'
}),
dotenv: Flags.string({
description: 'Path to a dotenv file to load environment variables from'
}),
overrides: Flags.string({
description: 'Dynamically override values in the test script; a JSON object'
}),
insecure: Flags.boolean({
char: 'k',
description: 'Allow insecure TLS connections; do not use in production'
}),
// multiple allows multiple arguments for the -i flag, which means that e.g.:
// artillery -i one.yml -i two.yml main.yml
// does not work as expected. Instead of being considered an argument, "main.yml"
// is considered to be input for "-i" and oclif then complains about missing
// argument
input: Flags.string({
char: 'i',
description: 'Input script file',
multiple: true,
hidden: true
}),

//Artillery Cloud commands
tags: Flags.string({
description:
'Comma-separated list of tags in key:value format to tag the test run, for example: --tags team:sqa,service:foo'
}),
note: Flags.string({
description: 'Add a note/annotation to the test run'
}),
record: Flags.boolean({
description: 'Record test run to Artillery Cloud'
}),
key: Flags.string({
description: 'API key for Artillery Cloud'
})
};

module.exports = {
CommonRunFlags
};
45 changes: 2 additions & 43 deletions packages/artillery/lib/cmds/run-fargate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

const { Command, Flags, Args } = require('@oclif/core');
const { CommonRunFlags } = require('../cli/common-flags');
const telemetry = require('../telemetry').init();
const { Plugin: CloudPlugin } = require('../platform/cloud/cloud');

Expand Down Expand Up @@ -66,6 +67,7 @@ Examples:
`;

RunCommand.flags = {
...CommonRunFlags,
count: Flags.integer({
description: runTestDescriptions.count
}),
Expand All @@ -85,11 +87,6 @@ RunCommand.flags = {
'subnet-ids': Flags.string({}),
'security-group-ids': Flags.string({}),
'task-role-name': Flags.string({}),
target: Flags.string({
char: 't',
description:
'Set target endpoint. Overrides the target already set in the test script'
}),
cpu: Flags.string({
description:
'Set task vCPU on Fargate. Value may be set as a number of vCPUs between 1-16 (e.g. 4), or as number of vCPU units (e.g. 4096)',
Expand All @@ -100,38 +97,6 @@ RunCommand.flags = {
'Set task memory on Fargate. Value may be set as number of GB between 1-120 (e.g. 8), or as MiB (e.g. 8192)',
default: '8'
}),
output: Flags.string({
char: 'o',
description: 'Write a JSON report to file'
}),
insecure: Flags.boolean({
char: 'k',
description: 'Allow insecure TLS connections; do not use in production'
}),
environment: Flags.string({
char: 'e',
description: 'Use one of the environments specified in config.environments'
}),
config: Flags.string({
description: 'Read configuration for the test from the specified file'
}),
'scenario-name': Flags.string({
description: 'Name of the specific scenario to run'
}),
overrides: Flags.string({
description: 'Dynamically override values in the test script; a JSON object'
}),
input: Flags.string({
char: 'i',
description: 'Input script file',
multiple: true,
hidden: true
}),
tags: Flags.string({
description:
'Comma-separated list of tags in key:value format to tag the test run, for example: --tags team:sre,service:foo'
}),
note: Flags.string({}), // TODO: description
packages: Flags.string({
description: runTestDescriptions.packages
}),
Expand All @@ -140,12 +105,6 @@ RunCommand.flags = {
}),
dotenv: Flags.string({
description: runTestDescriptions.dotenv
}),
record: Flags.boolean({
description: 'Record test run to Artillery Cloud'
}),
key: Flags.string({
description: 'API key for Artillery Cloud'
})
};

Expand Down
54 changes: 2 additions & 52 deletions packages/artillery/lib/cmds/run-lambda.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { Command, Flags, Args } = require('@oclif/core');
const { CommonRunFlags } = require('../cli/common-flags');

const RunCommand = require('./run');

Expand Down Expand Up @@ -50,74 +51,23 @@ Examples:
$ artillery run:lambda --region us-east-1 --count 10 my-test.yml
`;
RunLambdaCommand.flags = {
target: Flags.string({
char: 't',
description:
'Set target endpoint. Overrides the target already set in the test script'
}),
output: Flags.string({
char: 'o',
description: 'Write a JSON report to file'
}),
insecure: Flags.boolean({
char: 'k',
description: 'Allow insecure TLS connections; do not use in production'
}),
overrides: Flags.string({
description: 'Dynamically override values in the test script; a JSON object'
}),
...CommonRunFlags,
variables: Flags.string({
char: 'v',
description:
'Set variables available to vusers during the test; a JSON object'
}),
// TODO: Replace with --profile
environment: Flags.string({
char: 'e',
description: 'Use one of the environments specified in config.environments'
}),
config: Flags.string({
char: 'c',
description: 'Read configuration for the test from the specified file'
}),
payload: Flags.string({
char: 'p',
description: 'Specify a CSV file for dynamic data'
}),
// multiple allows multiple arguments for the -i flag, which means that e.g.:
// artillery -i one.yml -i two.yml main.yml
// does not work as expected. Instead of being considered an argument, "main.yml"
// is considered to be input for "-i" and oclif then complains about missing
// argument
input: Flags.string({
char: 'i',
description: 'Input script file',
multiple: true,
hidden: true
}),
dotenv: Flags.string({
description: 'Path to a dotenv file to load environment variables from'
}),
count: Flags.string({
// locally defaults to number of CPUs with mode = distribute
default: '1'
}),
tags: Flags.string({
description:
'Comma-separated list of tags in key:value format to tag the test run, for example: --tags team:sqa,service:foo'
}),
note: Flags.string({
description: 'Add a note/annotation to the test run'
}),
record: Flags.boolean({
description: 'Record test run to Artillery Cloud'
}),
key: Flags.string({
description: 'API key for Artillery Cloud'
}),
'scenario-name': Flags.string({
description: 'Name of the specific scenario to run'
}),
architecture: Flags.string({
description: 'Architecture of the Lambda function',
default: 'arm64'
Expand Down
58 changes: 2 additions & 56 deletions packages/artillery/lib/cmds/run.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { Command, Flags, Args } = require('@oclif/core');
const { CommonRunFlags } = require('../cli/common-flags');

const {
readScript,
Expand Down Expand Up @@ -74,64 +75,25 @@ Examples:
// TODO: Link to an Examples section in the docs

RunCommand.flags = {
target: Flags.string({
char: 't',
description:
'Set target endpoint. Overrides the target already set in the test script'
}),
output: Flags.string({
char: 'o',
description: 'Write a JSON report to file'
}),
insecure: Flags.boolean({
char: 'k',
description: 'Allow insecure TLS connections; do not use in production'
}),
...CommonRunFlags,
quiet: Flags.boolean({
char: 'q',
description: 'Quiet mode'
}),
overrides: Flags.string({
description: 'Dynamically override values in the test script; a JSON object'
}),
variables: Flags.string({
char: 'v',
description:
'Set variables available to vusers during the test; a JSON object'
}),
// TODO: Deprecation notices for commands below:

// TODO: Replace with --profile
environment: Flags.string({
char: 'e',
description: 'Use one of the environments specified in config.environments'
}),
config: Flags.string({
char: 'c',
description: 'Read configuration for the test from the specified file'
}),
payload: Flags.string({
char: 'p',
description: 'Specify a CSV file for dynamic data'
}),
// multiple allows multiple arguments for the -i flag, which means that e.g.:
// artillery -i one.yml -i two.yml main.yml
// does not work as expected. Instead of being considered an argument, "main.yml"
// is considered to be input for "-i" and oclif then complains about missing
// argument
input: Flags.string({
char: 'i',
description: 'Input script file',
multiple: true,
hidden: true
}),
solo: Flags.boolean({
char: 's',
description: 'Create only one virtual user'
}),
dotenv: Flags.string({
description: 'Path to a dotenv file to load environment variables from'
}),
platform: Flags.string({
description: 'Runtime platform',
default: 'local'
Expand All @@ -144,22 +106,6 @@ RunCommand.flags = {
count: Flags.string({
// locally defaults to number of CPUs with mode = distribute
default: '1'
}),
tags: Flags.string({
description:
'Comma-separated list of tags in key:value format to tag the test run, for example: --tags team:sqa,service:foo'
}),
note: Flags.string({
description: 'Add a note/annotation to the test run'
}),
record: Flags.boolean({
description: 'Record test run to Artillery Cloud'
}),
key: Flags.string({
description: 'API key for Artillery Cloud'
}),
'scenario-name': Flags.string({
description: 'Name of the specific scenario to run'
})
};

Expand Down

0 comments on commit aec0b89

Please sign in to comment.