Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Add request decomposition with directories #31

Merged
merged 29 commits into from
Jul 24, 2019

Conversation

bookmoons
Copy link
Contributor

Adds command line option --separate/-s which generates a separate file per request.

Generated files define the request through the shim. The main logic then invokes requests by name.

Files are generated into a directory structure matching the tree defined in the Postman collection. File and folder name collisions are suffixed alphabetically, A B etc.

Closes #24.

@bookmoons
Copy link
Contributor Author

bookmoons commented May 6, 2019

The box example puts this to good use.

node bin/postman-to-k6.js example/v2/box.json -s
export default function() {
  group("Collaborations", function() {
    postman[Request]("Get Pending Collaborations");
    postman[Request]("Retrieve a Collaboration");
    postman[Request]("Retrieve all Collaborations");
    postman[Request]("Add a Collaboration");
    postman[Request]("Edit a Collaboration");
    postman[Request]("Remove a Collaboration");
  });
  group("Comments", function() {
    postman[Request]("Get Information About a Comment");
    postman[Request]("Add a Comment to a File");
    postman[Request]("Add an '@' Comment to a File");
    postman[Request]("Add an Reply Comment to a File");
    postman[Request]("Change a Comment's Message");
    postman[Request]("Delete a Comment");
  });
  group("Events", function() {
    postman[Request]("Get Events for a User");
    postman[Request]("Get a Specific Event in an Enterprise");
    postman[Request]("Get Events in an Enterprise");
  });
  group("Files", function() {
    postman[Request]("Download a File");
    postman[Request]("Get Information about a File");
    postman[Request]("View the Comments on a File");
    postman[Request]("Get a Thumbnail for a File");
..

@robingustafsson
Copy link
Member

Apologies for the delay. Looking at this now. Running the box example from above I get:

Could not create request file Collaborations
{ Error: EISDIR: illegal operation on a directory, open './requests/Collaborations'
    at Object.openSync (fs.js:436:3)
    at Object.writeFileSync (fs.js:1168:35)
    at outputRequests (/<path>/postman-to-k6/bin/requests.js:11:10)
    at Command.run (/<path>/postman-to-k6/bin/postman-to-k6.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
    at startup (internal/bootstrap/node.js:279:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:752:3)
  errno: -21,
  syscall: 'open',
  code: 'EISDIR',
  path: './requests/Collaborations' }

Also, I think the filenames should be filtered a bit. The box example produces filenames like Get the Current User's Information.js and Get Access & Refresh Token.js. I propose we at least filter out characters not matching Unicode's "Letters" and "Numbers" category, or at least replace those other characters with a hyphen.

@bookmoons
Copy link
Contributor Author

Strange. I'll put it on my list to look into this. Thanks for looking it over.

@bookmoons bookmoons force-pushed the bookmoons/request-decomp-dir branch from 9272bdf to dad7273 Compare July 12, 2019 05:30
@bookmoons
Copy link
Contributor Author

Think I've got this error fixed, and implemented that filename encoding.

Did the encoding like this:

  • Strip everything except A-Za-z0-9 .-
  • Replace consecutive space sequences with a single -

@robingustafsson
Copy link
Member

@bookmoons Thanks, works and LGTM, merging.

@robingustafsson robingustafsson merged commit e693aa8 into grafana:master Jul 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Request decomposition [bounty: $200]
2 participants