#mocking #server #suite #web-services #setting #instance #up

bin+lib wwsvc-mock

A mock server for testing SoftENGINE's ERP Suite without setting up an instance!

5 stable releases

1.0.4 Mar 21, 2024

#127 in Authentication

Download history 190/week @ 2024-03-15 115/week @ 2024-03-22 42/week @ 2024-03-29 1/week @ 2024-04-05

348 downloads per month

LGPL-3.0

40KB
798 lines

wwsvc-mock

crate-badge docs-badge codecov-badge

This crate aims to provide a mock server for the SoftENGINE ERP Suite webservices.

It is a dual purpose crate, providing both a library and a binary. The library exposes the router, which can be used to integrate it into an axum-test server or a custom axum server. The binary is a standalone server.

Both the library and the binary can be extensively configured using environment variables or a configuration file.

Installation

As a library

cargo add wwsvc-mock

As a binary

cargo install wwsvc-mock

Usage

Using environment variables

Configuring the server using environment variables is very cumbersome, but possible.

Here is an example .env file:

APP__SERVER__BIND_ADDRESS=0.0.0.0:3000
APP__MOCK_RESOURCES=[{data_source={type=Empty},function=ARTIKEL,method=INSERT,revision=1,parameters={ARTNR=MeinArtikel}}]

Using a configuration file

The same configuration can be expressed in a configuration file:

[server]
bind_address = "0.0.0.0:3000"

[[mock_resources]]
data_source.type = "Empty"
function = "ARTIKEL"
method = "INSERT"
revision = 1
parameters.ARTNR = "MeinArtikel"

Both ways of configuring the server can be combined. The environment variables will take precedence over the configuration file. In this case, the mock server would allow you to register and deregister your service pass and additionally call the ARTIKEL.INSERT function with the given parameters. Using any other function, method or parameters will result in a 404 response in style of the original SoftENGINE ERP Suite webservice response.

You will also notice that we didn't specify any credentials, such as the vendor or app hash. This will cause the server to generate a random set of credentials for you. If you run the server using the binary, you will see the generated credentials in the logs. If you use the library, generating a config struct will also return the generated credentials.

Mocking data sources

The mock server as a whole doesn't mock any data sources. Instead, you will need to provide which combinations of function, method and parameters you want to mock, along with the data the endpoint should return. Ideally, you return the "best case" scenario, but you can also return error responses.

Currently it is not possible to jitter response times or return random errors. This is a planned feature.

Running the server

You can run the server using the built binary:

cargo build --release
target/release/wwsvc-mock

or from this repository:

cargo run --release

or using Docker:

docker run --rm -p 3000:3000 -e APP__SERVER__BIND_ADDRESS=0.0.0.0:3000 -e RUST_LOG=info ghcr.io/cozygalvinism/wwsvc-mock

Limitations

At this time, some limitations apply:

  • As stated above, it is not possible to jitter response times or return random errors.
  • The server does not support file uploads of any kind.
    • This is a planned feature.
  • The server currently does not validate which HTTP verb you use, although it shouldn't need to.

Dependencies

~15–28MB
~474K SLoC