Skip to content

Commit

Permalink
chore: add ambiguous paths invalid tests and sanitize output (#4404)
Browse files Browse the repository at this point in the history
leftover from this task: #4352

## Checklist

- [x] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted)
- [x] Description explains motivation and solution
- [ ] Tests added (always)
- [ ] Docs updated (only required for features)
- [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing

*By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
  • Loading branch information
tsuf239 authored Oct 4, 2023
1 parent 4d4420c commit 53e042a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
13 changes: 13 additions & 0 deletions examples/tests/invalid/ambiguous_api_paths.test.w
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
bring cloud;

let api = new cloud.Api();
let handler = inflight (req: cloud.ApiRequest): cloud.ApiResponse => {
return cloud.ApiResponse {
body: "ok",
status: 200
};
};

api.get("/test/path", handler);
api.get("/test/{variable}", handler);
// ^ Endpoint for path '/test/{variable}' and method 'GET' is ambiguous - it conflicts with existing endpoint for path '/test/path'
17 changes: 17 additions & 0 deletions tools/hangar/__snapshots__/invalid.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,23 @@ error: Unknown symbol \\"this\\"
Tests 1 failed (1)
Test Files 1 failed (1)
Duration <DURATION>"
`;
exports[`ambiguous_api_paths.test.w 1`] = `
"ERROR: Endpoint for path '/test/{variable}' and method 'GET' is ambiguous - it conflicts with existing endpoint for path '/test/path'
../../../examples/tests/invalid/target/test/ambiguous_api_paths.test.wsim.[REDACTED].tmp/.wing/preflight.js:38
const handler = new $Closure1(this,\\"$Closure1\\");
(api.get(\\"/test/path\\",handler));
>> (api.get(\\"/test/{variable}\\",handler));
}
}
Tests 1 failed (1)
Test Files 1 failed (1)
Duration <DURATION>"
Expand Down
4 changes: 3 additions & 1 deletion tools/hangar/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ export async function runWingCommand(options: RunWingCommandOptions) {
}

function sanitizeOutput(output: string) {
return output.replace(/\d+m[\d.]+s/g, "<DURATION>");
return output
.replace(/\d+m[\d.]+s/g, "<DURATION>")
.replace(/(?<=wsim.)\d+(?=.tmp)/g, "[REDACTED]");
}

export function sanitize_json_paths(path: string) {
Expand Down

0 comments on commit 53e042a

Please sign in to comment.