[−][src]Struct exonum_testkit::TestKitApi
API encapsulation for the testkit. Allows to execute and asynchronously retrieve results for REST-ful endpoints of services.
Note that TestKitApi
instantiation spawns a new HTTP server. Hence, it is advised to reuse
existing instances unless it is impossible. The latter may be the case if changes
to the testkit modify the set of its HTTP endpoints, for example, if a new service is
instantiated.
The HTTP server uses actix
under the hood, so in order to execute asynchronous methods,
the user should use this API inside the actix_rt
or tokio
runtime.
The easiest way to do that is to use #[tokio::test]
or #[actix_rt::test]
instead of
#[test]
.
Examples
use exonum_rust_runtime::{ProtoSourcesQuery, ProtoSourceFile}; #[tokio::test] async fn test_api() { let mut testkit = TestKitBuilder::validator().build(); let api = testkit.api(); // Without services / plugins, API only contains endpoints // provided by the Rust runtime. let proto_sources: Vec<ProtoSourceFile> = api .public(ApiKind::RustRuntime) .query(&ProtoSourcesQuery::Core) .get("proto-sources") .await .expect("Request to the valid endpoint failed"); }
Methods
impl TestKitApi
[src]
pub fn new(testkit: &mut TestKit) -> Self
[src]
Creates a new instance of API.
pub async fn send<'_, T>(&'_ self, transaction: T) where
T: Into<Verified<AnyTx>>,
[src]
T: Into<Verified<AnyTx>>,
Sends a transaction to the node.
pub fn public_url(&self, url: &str) -> String
[src]
Returns the resolved URL for the public API.
pub fn private_url(&self, url: &str) -> String
[src]
Returns the resolved URL for the private API.
pub fn public(&self, kind: impl Display) -> RequestBuilder
[src]
Creates a requests builder for the public API scope.
pub fn private(&self, kind: impl Display) -> RequestBuilder
[src]
Creates a requests builder for the private API scope.
pub fn client(&self) -> &TestKitApiClient
[src]
Return reference to the underlying API client.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for TestKitApi
impl !Send for TestKitApi
impl !Sync for TestKitApi
impl Unpin for TestKitApi
impl !UnwindSafe for TestKitApi
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,