stubr 0.6.2

Wiremock implemented in Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::wiremock::{Match, Request};

use crate::model::request::body::{binary_eq::BinaryExactMatcher, BodyMatcherStub};
use protobuf::reflect::MessageDescriptor;

pub struct GrpcBinaryExactBodyMatcher(BinaryExactMatcher, MessageDescriptor);

impl GrpcBinaryExactBodyMatcher {
    pub fn try_new(matcher: &BodyMatcherStub, md: MessageDescriptor) -> Option<Self> {
        BinaryExactMatcher::try_from(matcher).ok().map(|m| Self(m, md))
    }
}

impl Match for GrpcBinaryExactBodyMatcher {
    fn matches(&self, request: &Request) -> bool {
        self.0.matching_binary(&request.body[5..])
    }
}