Skip to content

Commit d9c581e

Browse files
committed
adapter - DummyAdapter - move the success get_auth call to doc-test
1 parent 6cda319 commit d9c581e

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

adapter/src/dummy.rs

+30-22
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
use std::collections::HashMap;
2+
3+
use hex::encode;
4+
15
use crate::adapter::{Adapter, AdapterError, Config};
26
use crate::sanity::SanityChecker;
3-
use hex::encode;
4-
use std::collections::HashMap;
57

68
#[derive(Debug)]
79
pub struct DummyParticipant {
@@ -67,6 +69,30 @@ impl Adapter for DummyAdapter<'_> {
6769
}
6870
}
6971

72+
/// Finds the auth. token in the HashMap of DummyParticipants if exists
73+
/// Example:
74+
///
75+
/// ```
76+
/// use std::collections::HashMap;
77+
/// use adapter::dummy::{DummyParticipant, DummyAdapter};
78+
/// use adapter::{ConfigBuilder, Adapter};
79+
///
80+
/// let mut participants = HashMap::new();
81+
/// participants.insert(
82+
/// "identity_key",
83+
/// DummyParticipant {
84+
/// identity: "identity".to_string(),
85+
/// token: "token".to_string(),
86+
/// },
87+
/// );
88+
///
89+
///let adapter = DummyAdapter {
90+
/// config: ConfigBuilder::new("identity").build(),
91+
/// participants,
92+
///};
93+
///
94+
///assert_eq!(Ok("token".to_string()), adapter.get_auth("identity"));
95+
/// ```
7096
fn get_auth(&self, validator: &str) -> Result<String, AdapterError<'_>> {
7197
match self
7298
.participants
@@ -81,9 +107,10 @@ impl Adapter for DummyAdapter<'_> {
81107

82108
#[cfg(test)]
83109
mod test {
84-
use super::*;
85110
use crate::adapter::ConfigBuilder;
86111

112+
use super::*;
113+
87114
#[test]
88115
fn dummy_adapter_sings_state_root_and_verifies_it() {
89116
let config = ConfigBuilder::new("identity").build();
@@ -130,23 +157,4 @@ mod test {
130157
adapter.get_auth("non-existing").unwrap_err()
131158
);
132159
}
133-
134-
#[test]
135-
fn get_auth_with_existing_participator() {
136-
let mut participants = HashMap::new();
137-
participants.insert(
138-
"identity_key",
139-
DummyParticipant {
140-
identity: "identity".to_string(),
141-
token: "token".to_string(),
142-
},
143-
);
144-
145-
let adapter = DummyAdapter {
146-
config: ConfigBuilder::new("identity").build(),
147-
participants,
148-
};
149-
150-
assert_eq!(Ok("token".to_string()), adapter.get_auth("identity"));
151-
}
152160
}

0 commit comments

Comments
 (0)