-
Notifications
You must be signed in to change notification settings - Fork 0
/
mock_hdk.rs
135 lines (123 loc) · 3.46 KB
/
mock_hdk.rs
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
use hdk::prelude::*;
pub fn mock_create(
mock_hdk: &mut MockHdkT,
expected_input: CreateInput,
expected_output: ExternResult<ActionHash>,
) {
mock_hdk
.expect_create()
.with(mockall::predicate::eq(expected_input))
.times(1)
.return_const(expected_output);
}
// pub fn mock_hash(
// mock_hdk: &mut MockHdkT,
// expected_input: HashInput,
// expected_output: ExternResult<HashOutput>,
// ) {
// mock_hdk
// .expect_hash()
// .with(mockall::predicate::eq(expected_input))
// .times(1)
// .return_const(expected_output);
// }
pub fn mock_create_link(
mock_hdk: &mut MockHdkT,
expected_input: CreateLinkInput,
expected_output: ExternResult<ActionHash>,
) {
mock_hdk
.expect_create_link()
.with(mockall::predicate::eq(expected_input))
.times(1)
.return_const(expected_output);
}
pub fn mock_agent_info(mock_hdk: &mut MockHdkT, expected_output: ExternResult<AgentInfo>) {
mock_hdk
.expect_agent_info()
.times(1)
.return_const(expected_output);
}
pub fn mock_remote_signal(
mock_hdk: &mut MockHdkT,
expected_input: RemoteSignal,
expected_output: ExternResult<()>,
) {
mock_hdk
.expect_remote_signal()
.with(mockall::predicate::eq(expected_input))
.times(1)
.return_const(expected_output);
}
pub fn mock_update(
mock_hdk: &mut MockHdkT,
expected_input: UpdateInput,
expected_output: ExternResult<ActionHash>,
) {
mock_hdk
.expect_update()
.with(mockall::predicate::eq(expected_input))
.times(1)
.return_const(expected_output);
}
pub fn mock_get_links(
mock_hdk: &mut MockHdkT,
expected_input: Vec<GetLinksInput>,
expected_output: ExternResult<Vec<Vec<Link>>>,
) {
// println!("expected get_links_input {:?}", expected_input);
mock_hdk
.expect_get_links()
.with(mockall::predicate::eq(expected_input))
.times(1)
.return_const(expected_output);
// .returning(|input| {
// println!("actual get_links_input {:?}", input);
// Ok(vec![vec![]])
// });
}
pub fn mock_sys_time(mock_hdk: &mut MockHdkT, expected_output: ExternResult<Timestamp>) {
mock_hdk
.expect_sys_time()
.times(1)
.return_const(expected_output);
}
pub fn mock_must_get_action(
mock_hdk: &mut MockHdkT,
expected_input: MustGetActionInput,
expected_output: ExternResult<SignedActionHashed>,
) {
mock_hdk
.expect_must_get_action()
.with(mockall::predicate::eq(expected_input))
.times(1)
.return_const(expected_output);
}
pub fn mock_must_get_entry(
mock_hdk: &mut MockHdkT,
expected_input: MustGetEntryInput,
expected_output: ExternResult<EntryHashed>,
) {
mock_hdk
.expect_must_get_entry()
.with(mockall::predicate::eq(expected_input))
.times(1)
.return_const(expected_output);
}
pub fn mock_zome_info(mock_hdk: &mut MockHdkT, expected_output: ExternResult<ZomeInfo>) {
mock_hdk
.expect_zome_info()
.times(1)
.return_const(expected_output);
}
pub fn mock_get(
mock_hdk: &mut MockHdkT,
expected_input: Vec<GetInput>,
expected_output: ExternResult<Vec<Option<Record>>>,
) {
mock_hdk
.expect_get() // called from `Path::from(MEMBER_PATH).ensure()?;`
.with(mockall::predicate::eq(expected_input))
.times(1)
.return_const(expected_output);
}