1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
use super::*;
#[derive(Debug)]
pub struct ArbitraryRequest(pub http::request::Request<()>);
#[derive(Debug, Clone, Copy)]
pub struct RequestStrategy;
#[derive(Debug, Clone)]
pub struct RequestValueTree(
TupleValueTree<(
super::uri::UriValueTree,
MethodValueTree,
super::header::HeaderMapValueTree,
)>,
);
impl Arbitrary for ArbitraryRequest {
type Strategy = RequestStrategy;
type Parameters = ();
fn arbitrary_with((): Self::Parameters) -> Self::Strategy {
RequestStrategy
}
}
impl Strategy for RequestStrategy {
type Tree = RequestValueTree;
type Value = ArbitraryRequest;
fn new_tree(&self, runner: &mut TestRunner) -> NewTree<Self> {
Ok(RequestValueTree(
<(ArbitraryUri, ArbitraryMethod, ArbitraryHeaderMap)>::arbitrary().new_tree(runner)?,
))
}
}
impl ValueTree for RequestValueTree {
type Value = ArbitraryRequest;
fn current(&self) -> Self::Value {
let mut b = http::request::Builder::default();
let (ArbitraryUri(u), ArbitraryMethod(m), ArbitraryHeaderMap(h)) = self.0.current();
b.uri(u);
b.method(m);
*b.headers_mut().unwrap() = h;
ArbitraryRequest(b.body(()).unwrap())
}
fn simplify(&mut self) -> bool {
self.0.simplify()
}
fn complicate(&mut self) -> bool {
self.0.complicate()
}
}
#[derive(Debug, Eq, PartialEq)]
pub struct ArbitraryMethod(pub http::method::Method);
#[derive(Debug, Clone, Copy)]
pub struct MethodStrategy;
#[derive(Debug, Clone)]
pub struct MethodValueTree(IndexValueTree);
const METHODS: [http::Method; 5] = [
http::method::Method::GET,
http::method::Method::POST,
http::method::Method::PUT,
http::method::Method::DELETE,
http::method::Method::TRACE,
];
impl Arbitrary for ArbitraryMethod {
type Strategy = MethodStrategy;
type Parameters = ();
fn arbitrary_with((): Self::Parameters) -> Self::Strategy {
MethodStrategy
}
}
impl Strategy for MethodStrategy {
type Tree = MethodValueTree;
type Value = ArbitraryMethod;
fn new_tree(&self, runner: &mut TestRunner) -> NewTree<Self> {
Ok(MethodValueTree(Index::arbitrary().new_tree(runner)?))
}
}
impl ValueTree for MethodValueTree {
type Value = ArbitraryMethod;
fn current(&self) -> Self::Value {
ArbitraryMethod(self.0.current().get(&METHODS).clone())
}
fn simplify(&mut self) -> bool {
self.0.simplify()
}
fn complicate(&mut self) -> bool {
self.0.complicate()
}
}