localrest ~mlang_fixup
A library to allow integration testing of vibe.web.rest based code
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
LocalRest
A library to allow integration testing of vibe.web.rest
based code as unittests.
Example
The main source file is extensively documented, and includes many unittests.
The straightforward approach is to do:
static interface API
{
@safe: // Vibe.d requirement, but LocalRest works with `@system`
public @property ulong pubkey ();
public string getValue (ulong idx);
public ubyte[32] getQuorumSet ();
public string recv (string data);
}
static class MockAPI : API
{
@safe:
public override @property ulong pubkey ()
{ return 42; }
public override string getValue (ulong idx)
{ assert(0); }
public override ubyte[32] getQuorumSet ()
{ assert(0); }
public override string recv (string data)
{ assert(0); }
}
// This will start a new thread, create a `MockAPI` object in it,
// and return a handle that allows communicating with it.
scope API test = RemoteAPI!API.spawn!MockAPI();
// Note that the handle will be of type `RemoteAPI!API`, which implements `API`
// This is so one can have an array of `API`, but different underlying implementations.
// This will send a message to the remote thread, which will ultimately call `MockAPI.pubkey`
// Any parameter and return value is serialized to a type that is safe to pass accross thread.
// By default, Vibe.d's JSON serializer is used, but it can be replaced (see `geod24.Serialization`).
assert(test.pubkey() == 42);
// Remote nodes can be controlled, to extend testing parameters:
// For example, they can be made to be unresponsive for a set duration,
// or to ignore calls to certain methods.
test.ctrl.shutdown();
For this to work, one need to have Vibe.d already fetched. For a simple test, dub fetch vibe-d
will suffice.
For project depending on this, make sure your dub.json
includes the following in dependencies
:
{
"vibe-d:data": "~>0.8"
}
- Registered by Mathias Lang
- ~mlang_fixup released 7 months ago
- Geod24/localrest
- MIT
- Copyright © 2019-2020, Mathias 'Geod24' Lang
- Authors:
- Dependencies:
- vibe-d:data
- Versions:
-
0.4.0 2021-Mar-22 0.3.0 2019-Aug-08 0.2.0 2019-Jun-30 0.1.0 2019-Jun-23 0.0.1 2019-Jan-15 - Download Stats:
-
-
0 downloads today
-
0 downloads this week
-
0 downloads this month
-
370 downloads total
-
- Score:
- 0.9
- Short URL:
- localrest.dub.pm