ronarwithsonar / rust_api_testing

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rust API Testing

An exercise in using Cucumber, Rust, and Docker to test APIs.

Prerequisites

  • Docker installed.
  • Generated API keys (public and private).
  • Host URL without trailing forward slashes ( e.g. https://api.example.com).
  • GBP funds (Steps to use this not implemented yet).
  • A stop-loss trigger for buying BTC with GBP, which will not execute in the current market condition (defaulted to 60000) (Steps to use this not implemented yet).

Important Notes

  • There are unimplemented steps that will cause test failures. This ensures tests do not appear to be passing when they are not actually running.
  • Any changes in the project locally will require rebuilding the docker image

Building the Docker Image

Navigate to the project directory and build the Docker image:

cd path/to/project
docker build -t rust_api_tests .

Running the Tests

Run the Docker container with the necessary environment variables:

docker run -e PUBLIC_KEY=<PUBLIC_KEY> -e PRIVATE_KEY=<PRIVATE_KEY> -e TRIGGER=<REASONABLE_STOP_LOSS_TRIGGER> -e API_HOST=<API_HOST> rust_api_tests

Improvements

Code and Architecture

  • Builder Pattern: Use a builder pattern to better manage the hand-built structs used in the tests.
  • OpenAPI Integration: Investigate implementing the output of openapi-generator in the test framework after processing the OpenAPI specification. This would reduce code maintenance with API changes.
  • Cucumber Integration: Integrate Cucumber test results into Rust's standard test report.
  • Validation Checks: Add more validity checks, particularly around the various World objects.
  • Error Handling: Improve error handling throughout the project.
  • Docker Optimization: Explore using the slim-buster variation of Rust Docker to reduce build times.

Learning and Best Practices

  • Rust Paradigms: Move away from an OOP mindset and adopt Rust idioms e.g. ownership/borrowing, functional programming, etc.
  • Project Structure: Learn more about structuring Rust projects, particularly around module and library organization.

Follow Up Tasks

  • Implement the step to create a stop-loss order that is unlikely to execute in a real-world environment (potentially using traits to process various requests)
  • Add a cleanup call to cancel the created order after test execution.
  • Perform a thorough cleanup of dead code in the project.

About


Languages

Language:Rust 94.8%Language:Gherkin 4.5%Language:Dockerfile 0.7%