grass/dev/strategy/alias/
mock.rs1use super::{Alias, AliasStrategy, AliasStrategyError};
2
3#[derive(Debug, Default)]
11pub struct MockAliasStrategy;
12
13impl AliasStrategy for MockAliasStrategy {
14 fn list_all_aliases<T>(&self) -> super::Result<T>
15 where
16 T: FromIterator<super::Alias>,
17 {
18 Ok([
19 ("allg", "all_good"),
20 ("change", "with_changes"),
21 ("err", "with_error"),
22 ]
23 .into_iter()
24 .map(Into::<Alias>::into)
25 .collect())
26 }
27
28 fn list_aliases_for_category<T, U>(&self, category: T) -> super::Result<U>
29 where
30 T: AsRef<str>,
31 U: FromIterator<super::Alias>,
32 {
33 let result = match category.as_ref() {
34 "all_good" => [("allg", "all_good")],
35 "with_changes" => [("change", "with_changes")],
36 "with_error" => [("err", "with_error")],
37 _ => {
38 return Err(AliasStrategyError::CategoryNotFound {
39 context: "When mocking the API".into(),
40 reason: "Category isn't defined".into(),
41 })
42 }
43 };
44
45 Ok(result.into_iter().map(Into::<Alias>::into).collect())
46 }
47
48 fn resolve_alias<T: super::ResolvesAlias>(&self, input: T) -> super::Result<T::Resolved> {
49 input.resolve_alias(|input| {
50 Ok(Box::from(match input {
51 "allg" => "all_good",
52 "with_changes" => "with_changes",
53 "with_error" => "with_error",
54 value => value,
55 }))
56 })
57 }
58}