Skip to content

Commit 5c3ec4c

Browse files
authored
Skip response body scripting (#170)
* Bug fixes 2023-10-26 (#168) * Fixed issue with agent instead of controller acceptance * Fixed the errorfile validator since it can be an object * Fixed the acceptance tests if run after the agent tests * Fixed the start scripts to match the other controller/agent scripts * Cleaned up the static environment vars * Added new npm run acceptance:all - Acceptance:all will start both the agent and controller, and run the acceptance tests for both. You must manually Ctrl -C when finished * Split the skipBody try parameter into separate request/response skip (#169) * Split the skipBody try parameter into separate request/response skip - -k/--skip-response-body will only skip the response body - -K/--skip-request-body will only skip the request body - '-k -K' will skip BOTH request and response body * Fixed cargo fmt
1 parent a813382 commit 5c3ec4c

File tree

9 files changed

+91
-57
lines changed

9 files changed

+91
-57
lines changed

controller/acceptance/errorFile.spec.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,10 @@ describe("ErrorFile API Integration", function () {
154154
} else {
155155
expect(res.status, "status").to.equal(200);
156156
expect(res.data, "body").to.not.equal(undefined);
157-
expect(typeof res.data, "typeof res.data").to.equal("string");
157+
// If it's only a single line (that is json) this will be an object like
158+
// {"type":"end","msg":"Test killed early by Ctrl-c"}
159+
// expect(typeof res.data, "typeof res.data").to.equal("string");
160+
expect(["string", "object"].includes(typeof res.data), `["string", "object"].includes("${typeof res.data}")`).to.equal(true);
158161
done();
159162
}
160163
} else {

controller/acceptance/test.spec.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1971,8 +1971,9 @@ describe("Test API Integration", () => {
19711971
expect(Array.isArray(allTests.requestedTests), "requestedTests").to.equal(true);
19721972
// Running should have at least one now
19731973
expect(allTests.runningTests.length, "tests.runningTests.length: " + allTests.runningTests.length).to.be.greaterThan(0);
1974-
expect(allTests.recentTests.length, "tests.recentTests.length: " + allTests.recentTests.length).to.equal(0);
1975-
expect(allTests.requestedTests.length, "tests.requestedTests.length: " + allTests.requestedTests.length).to.be.greaterThanOrEqual(0);
1974+
// recent should be zero. But if the agent acceptance are run before this it will be 1
1975+
// expect(allTests.recentTests.length, "tests.recentTests.length: " + allTests.recentTests.length).to.equal(0);
1976+
// expect(allTests.requestedTests.length, "tests.requestedTests.length: " + allTests.requestedTests.length).to.be.greaterThanOrEqual(0);
19761977
});
19771978

19781979
it("GET /test?testId=validInS3 should respond 200 OK", (done: Mocha.Done) => {

controller/components/Layout/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { logout as authLogout } from "../../pages/api/util/authclient";
1717
import getConfig from "next/config";
1818

1919
// Have to check for null on this since the tsc test compile it will be, but nextjs will have a publicRuntimeConfig
20-
const publicRuntimeConfig: any = getConfig() && getConfig().publicRuntimeConfig ? getConfig().publicRuntimeConfig : {};
20+
const publicRuntimeConfig: any = getConfig() && getConfig().publicRuntimeConfig ? getConfig().publicRuntimeConfig : process.env;
2121
const HIDE_ENVIRONMENT: unknown = publicRuntimeConfig.HIDE_ENVIRONMENT;
2222

2323
export type OtherControllers = Record<string, {

controller/next.config.js

+9-18
Original file line numberDiff line numberDiff line change
@@ -121,35 +121,26 @@ const nextConfig = {
121121
HIDE_ENVIRONMENT: process.env.HIDE_ENVIRONMENT,
122122
},
123123
// https://github.com/vercel/next.js/discussions/11493#discussioncomment-14606
124-
env: { // These are sent to the client and the server and are set at build time
125-
// @ts-ignore
126-
LoggingLevel: process.env.LoggingLevel,
124+
env: { // These are sent to the client and the server and are set at build time for static pages
125+
LoggingLevel: process.env.LoggingLevel || "", // Only checks if debug
127126
// @ts-ignore
128127
APPLICATION_NAME: process.env.APPLICATION_NAME,
129128
// @ts-ignore
130129
SYSTEM_NAME: process.env.SYSTEM_NAME,
131130
// @ts-ignore
132-
FS_SITE: process.env.FS_SITE,
131+
FS_SITE: process.env.FS_SITE, // Used by auth client/Layout
133132
// @ts-ignore
134-
BASE_PATH: process.env.BASE_PATH,
133+
BASE_PATH: process.env.BASE_PATH, // client utils/Layout
135134
// @ts-ignore
136-
ASSET_PREFIX: process.env.ASSET_PREFIX,
135+
ASSET_PREFIX: process.env.ASSET_PREFIX, // client utils/Layout
137136
// @ts-ignore
138-
TEST_STATUS_REFRESH_DELAY: process.env.TEST_STATUS_REFRESH_DELAY,
137+
HIDE_ENVIRONMENT: process.env.HIDE_ENVIRONMENT, // Used by Layout
139138
// @ts-ignore
140-
TEST_ERRORS_MAX_DISPLAYED: process.env.TEST_ERRORS_MAX_DISPLAYED,
139+
AUTH_MODE: process.env.AUTH_MODE, // Used by auth client/Layout
141140
// @ts-ignore
142-
TEST_ERRORS_MAX_LINE_LENGTH: process.env.TEST_ERRORS_MAX_LINE_LENGTH,
141+
AUTH_COOKIE_NAME: process.env.AUTH_COOKIE_NAME, // Used by auth client/Layout
143142
// @ts-ignore
144-
REDIRECT_TO_S3: process.env.REDIRECT_TO_S3,
145-
// @ts-ignore
146-
UNZIP_S3_FILES: process.env.UNZIP_S3_FILES,
147-
// @ts-ignore
148-
AUTH_MODE: process.env.AUTH_MODE,
149-
// @ts-ignore
150-
AUTH_COOKIE_NAME: process.env.AUTH_COOKIE_NAME,
151-
// @ts-ignore
152-
AUTH_HEADER_NAME: process.env.AUTH_HEADER_NAME,
143+
AUTH_HEADER_NAME: process.env.AUTH_HEADER_NAME, // Used by auth client/Layout
153144
}
154145
};
155146

guide/src/cli.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@ Commands:
1414
help Print this message or the help of the given subcommand(s)
1515
1616
Options:
17-
-h, --help Prints help information
18-
-V, --version Prints version information
19-
-l, --loggers Enable loggers defined in the config file
20-
-d, --results-directory Directory to store logs (if enabled with --loggers)
21-
-k, --skipBody Skips request and reponse body from output (try command)
17+
-h, --help Prints help information
18+
-V, --version Prints version information
2219
```
2320

2421
As signified in the above help output, there are two subcommands `run` and `try`.
@@ -72,7 +69,8 @@ Options:
7269
endpoint matching the filter is included in the test
7370
-l, --loggers Enable loggers defined in the config file
7471
-d, --results-directory <DIRECTORY> Directory to store logs (if enabled with --loggers)
75-
-k, --skipBody Skips request and reponse body from output (try command)
72+
-k, --skip-response-body Skips reponse body from output (try command)
73+
-K, --skip-request-body Skips request body from output (try command)
7674
-h, --help Prints help information
7775
```
7876

@@ -84,7 +82,9 @@ The `-l`, `--loggers` flag specifies that any loggers defined in the config file
8482

8583
The `-d`, `--results-directory` parameter will store any log files (if the `--loggers` flag is used) in the specified directory. If the directory does not exist it is created.
8684

87-
The `-k`, `--skipBody` parameter ensures that during a Try run, the request and response bodies aren't displayed. This can be particularly useful for debugging requests or responses when the body is not crucial for the debugging process.
85+
The `-k`, `--skip-response-body` parameter ensures that during a Try run, the response bodies aren't displayed. This can be particularly useful for debugging responses when the body is very long and not crucial for the debugging process.
86+
87+
The `-K`, `--skip-request-body` parameter ensures that during a Try run, the request bodies aren't displayed. This can be particularly useful for debugging requests when the body is very long and not crucial for the debugging process.
8888
<br/><br/>
8989

9090
In both the `run` and `try` subcommands a [config file](./config.md) is required.

package.json

+7-5
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
"./controller"
1111
],
1212
"scripts": {
13-
"start": "npm-run-all --parallel startagent startcontroller",
14-
"startcontroller": "cd controller && npm run start",
15-
"startagent": "cd agent && npm run start",
13+
"start": "npm-run-all --parallel start:agent start:controller",
14+
"start:controller": "cd controller && npm run start",
15+
"start:agent": "cd agent && npm run start",
1616
"dev": "cd controller && npm run dev",
1717
"build": "npm run lint && npm run build:common && npm run build:agent && npm run build:controller",
1818
"storybook": "cd controller && npm run storybook",
@@ -35,9 +35,11 @@
3535
"test:common": "cd common && npm run test",
3636
"test:agent": "cd agent && npm run test",
3737
"test:controller": "cd controller && npm run test",
38-
"acceptance": "npm run acceptance:agent && npm run acceptance:controller",
38+
"acceptance:all": "npm-run-all --parallel start acceptance:sleep",
39+
"acceptance:sleep": "sleep 30 && npm run acceptance",
40+
"acceptance": "npm-run-all --serial acceptance:agent acceptance:controller",
3941
"acceptance:agent": "cd agent && npm run acceptance",
40-
"acceptance:controller": "cd agent && npm run acceptance",
42+
"acceptance:controller": "cd controller && npm run acceptance",
4143
"integration": "npm-run-all --serial lint integration:common integration:agent integration:controller testmerge",
4244
"integration:common": "cd common && npm run integration",
4345
"integration:agent": "cd agent && npm run integration",

pr.sh

+7-9
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,13 @@ npm run linterror
6060
npm run build:react
6161
NODE_ENV=test npm test
6262

63-
# terminal 1
63+
# npm run testcleanup
6464
# npm run coverage
65-
# grab screenshot
66-
# cd controller/ && npm run testcleanup
67-
68-
# terminal 2
69-
# cd controller/ && npm start
70-
# terminal 3
71-
# cd controller/ && npm run acceptance
72-
# grab screenshot
65+
# echo grab screenshot
66+
67+
# npm run testcleanup
68+
# echo Hit Ctrl-C when acceptance tests finish
69+
# npm acceptance:all
70+
# echo grab screenshot
7371

7472
cargo deny check --hide-inclusion-graph license sources advisories

src/bin/pewpew.rs

+45-9
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,19 @@ mod args {
151151
/// Directory to store logs (if enabled with --loggers)
152152
#[arg(short = 'd', long = "results-directory", value_name = "DIRECTORY")]
153153
results_dir: Option<PathBuf>,
154-
/// Skips request and reponse body from output
155-
#[arg(short = 'k', long = "skipBody")]
156-
skip_body_on: bool,
154+
/// Skips reponse body from output
155+
#[arg(short = 'k', long = "skip-response-body")]
156+
skip_response_body_on: bool,
157+
/// Skips request body from output
158+
#[arg(short = 'K', long = "skip-request-body")]
159+
skip_request_body_on: bool,
157160
}
158161

159162
impl From<TryConfigTmp> for TryConfig {
160163
fn from(value: TryConfigTmp) -> Self {
161164
let loggers_on = value.loggers_on;
162-
let skip_body_on = value.skip_body_on;
165+
let skip_response_body_on = value.skip_response_body_on;
166+
let skip_request_body_on = value.skip_request_body_on;
163167
let results_dir = value.results_dir.filter(|_| loggers_on);
164168
if let Some(d) = &results_dir {
165169
create_dir_all(d).unwrap();
@@ -172,7 +176,8 @@ mod args {
172176
filters: value.filters,
173177
file: value.file,
174178
format: value.format,
175-
skip_body_on,
179+
skip_response_body_on,
180+
skip_request_body_on,
176181
}
177182
}
178183
}
@@ -420,7 +425,8 @@ mod tests {
420425
assert!(try_config.filters.is_none());
421426
assert!(matches!(try_config.format, TryRunFormat::Human));
422427
assert!(!try_config.loggers_on);
423-
assert!(!try_config.skip_body_on);
428+
assert!(!try_config.skip_response_body_on);
429+
assert!(!try_config.skip_request_body_on);
424430
assert!(try_config.results_dir.is_none());
425431
}
426432

@@ -437,6 +443,7 @@ mod tests {
437443
"_id=0",
438444
"-l",
439445
"-k",
446+
"-K",
440447
"-o",
441448
STATS_FILE,
442449
YAML_FILE,
@@ -460,7 +467,8 @@ mod tests {
460467
}
461468
assert!(matches!(try_config.format, TryRunFormat::Json));
462469
assert!(try_config.loggers_on);
463-
assert!(try_config.skip_body_on);
470+
assert!(try_config.skip_response_body_on);
471+
assert!(try_config.skip_request_body_on);
464472
assert!(try_config.results_dir.is_some());
465473
assert_eq!(try_config.results_dir.unwrap().to_str().unwrap(), TEST_DIR);
466474
}
@@ -477,7 +485,8 @@ mod tests {
477485
"--include",
478486
"_id=0",
479487
"--loggers",
480-
"--skipBody",
488+
"--skip-response-body",
489+
"--skip-request-body",
481490
"--file",
482491
STATS_FILE,
483492
YAML_FILE,
@@ -501,11 +510,38 @@ mod tests {
501510
}
502511
assert!(matches!(try_config.format, TryRunFormat::Json));
503512
assert!(try_config.loggers_on);
504-
assert!(try_config.skip_body_on);
513+
assert!(try_config.skip_response_body_on);
514+
assert!(try_config.skip_request_body_on);
505515
assert!(try_config.results_dir.is_some());
506516
assert_eq!(try_config.results_dir.unwrap().to_str().unwrap(), TEST_DIR);
507517
}
508518

519+
#[test]
520+
fn cli_try_skip_response_body() {
521+
let cli_config =
522+
args::try_parse_from(["myprog", TRY_COMMAND, "--skip-response-body", YAML_FILE])
523+
.unwrap();
524+
let ExecConfig::Try(try_config) = cli_config else {
525+
panic!()
526+
};
527+
assert_eq!(try_config.config_file.to_str().unwrap(), YAML_FILE);
528+
assert!(try_config.skip_response_body_on);
529+
assert!(!try_config.skip_request_body_on);
530+
}
531+
532+
#[test]
533+
fn cli_try_request_body() {
534+
let cli_config =
535+
args::try_parse_from(["myprog", TRY_COMMAND, "--skip-request-body", YAML_FILE])
536+
.unwrap();
537+
let ExecConfig::Try(try_config) = cli_config else {
538+
panic!()
539+
};
540+
assert_eq!(try_config.config_file.to_str().unwrap(), YAML_FILE);
541+
assert!(!try_config.skip_response_body_on);
542+
assert!(try_config.skip_request_body_on);
543+
}
544+
509545
#[test]
510546
fn cli_try_include() {
511547
let cli_config = args::try_parse_from([

src/lib.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,12 @@ pub struct TryConfig {
337337
/// Directory to store logs (if enabled with --loggers)
338338
#[arg(short = 'd', long = "results-directory", value_name = "DIRECTORY")]
339339
pub results_dir: Option<PathBuf>,
340-
/// Skips request and reponse body from output (try command)
341-
#[arg(short = 's', long = "skipBody")]
342-
pub skip_body_on: bool,
340+
/// Skips reponse body from output
341+
#[arg(short = 'k', long = "skip-response-body")]
342+
pub skip_response_body_on: bool,
343+
/// Skips request body from output
344+
#[arg(short = 'K', long = "skip-request-body")]
345+
pub skip_request_body_on: bool,
343346
}
344347

345348
impl fmt::Display for TryConfig {
@@ -881,14 +884,14 @@ fn create_try_run_future(
881884
debug!("create_try_run_future start");
882885
// create a logger for the try run
883886
// request.headers only logs single Accept Headers due to JSON requirements. Use headers_all instead
884-
let request_body_template = if try_config.skip_body_on {
887+
let request_body_template = if try_config.skip_request_body_on {
885888
""
886889
} else if matches!(try_config.format, TryRunFormat::Human) {
887890
"${request.body != '' ? request.body : ''}\n"
888891
} else {
889892
r#","body": "request.body""#
890893
};
891-
let response_body_template = if try_config.skip_body_on {
894+
let response_body_template = if try_config.skip_response_body_on {
892895
""
893896
} else if matches!(try_config.format, TryRunFormat::Human) {
894897
"${response.body != '' ? JSON.stringify(response.body) : ''}\n"

0 commit comments

Comments
 (0)