#testing #request #requests #workbook #scenario #workspace #dispatch

apicize_lib

Library supporting Apicize request dispatch, testing and serialization

10 unstable releases (3 breaking)

new 0.11.3 Nov 8, 2024
0.11.2 Nov 7, 2024
0.10.1 Nov 6, 2024
0.9.3 Nov 3, 2024
0.8.4 Oct 31, 2024

#6 in #scenario

Download history 162/week @ 2024-10-25 539/week @ 2024-11-01

701 downloads per month

MIT license

195KB
4.5K SLoC

Apicize Rust Library

This is a Rust library supporting Apicize serilization, request dispatching (via Reqwest) and test running (via V8).

Serialization

Broadly speaking, Workbooks and associated structures are how Apicize testing information is persisted in JSON format.
Workspaces contain indexed views of Workbook structures like requests, scenarios, etc. which make it more efficient to traverse hierarchical and ordered information.

Opening a Workspace from a Workbook

The function Workspace::open_from_file will populate a workspace from a a workbook file, its private parameters file, and global parameters file (if specified). Entities are indexed and warnings are generated if a workbook contains any references to parameters that are not found in the private or globals file.

Saving a Workspace to a Workbook

The function Workspace::save persists workspace information to workbook, private parameters and global parameters files. Private parameters are saved to a file with the same name as the workbook but with an .apicize-priv extension. Global parameters are saved to the user's OS configuration directory under apicize/globals.json.

Executing Tests in a Workspace

Tests are executed via the test_runner::run function, which accepts an Arc to the workspace being tested, an optional list of request IDs to execute (defaults to all), an optional cancellation token, and an Arc to instant that testing was started.

JavaScript Testing

This library leverages V8 to execute tests to validate requests. This sandboxed envioronment does not include NodeJS or Browser functionality, primarily to prevent arbitrary test code in a Workbook from doing anything harmful.

The following variables and functions are available in the testing sandbox:

  • request: A variable containing the submitted HTTP request
  • response: A variable containing the HTTP response
  • variables: A variable containing key-value pairs originally sourced from the assigned Scenario parameter, but can be updated to pass values to subsequent and child requests in a group
  • assert: An exported function of Chai's Node assertion style
  • expect / should: Exported functions of Chai's BDD assertion style
  • jsonpath: An exported function of JSONPath Plus
  • xpath: An exported function of XPath
  • dom: An exported function of xmldom

Buliding JavaScript Dependencies

The build.rs file triggers a Webpack build of the JavaScript dependencies defined in ./test-framework. Adding new functionality involves adding depdencies to ./test-framework/package.json and then exposing variables/functions in ./test-framework/index.js. Note that when creating variables that are exposed to the test runner you should not use const, var or let to define them. Also, you should add tests to test_runner.rs to ensure any additions are working properly upon rebuild.

Dependencies

~96MB
~2M SLoC