Skip to content

Commit

Permalink
test: Add unit test for control loop
Browse files Browse the repository at this point in the history
  • Loading branch information
morgsmccauley committed Dec 18, 2023
1 parent 5e9334c commit 25b85c7
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions coordinator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,57 @@ async fn map_registry_to_system(

Ok(())
}

#[cfg(test)]
mod tests {
use super::*;

use std::collections::HashMap;

use registry_types::{IndexerRule, IndexerRuleKind, MatchingRule, Status};

use crate::registry::IndexerConfig;

#[tokio::test]
async fn something() {
let mut registry = Registry::default();
registry.expect_fetch().returning(|| {
Ok(HashMap::from([(
"morgs.near".parse().unwrap(),
HashMap::from([(
"test".to_string(),
IndexerConfig {
account_id: "morgs.near".parse().unwrap(),
function_name: "test".to_string(),
code: String::new(),
schema: Some(String::new()),
filter: IndexerRule {
id: None,
name: None,
indexer_rule_kind: IndexerRuleKind::Action,
matching_rule: MatchingRule::ActionAny {
affected_account_id: "queryapi.dataplatform.near".to_string(),
status: Status::Any,
},
},
created_at_block_height: 1,
updated_at_block_height: None,
start_block_height: None,
},
)]),
)]))
});

let mut redis_client = RedisClient::default();
redis_client
.expect_get::<String, u64>()
.returning(|_| Ok(1));

let mut block_stream_handler = BlockStreamHandler::default();
block_stream_handler
.expect_start()
.returning(|_, _, _, _| Ok(()));

let _ = map_registry_to_system(&registry, &redis_client, &mut block_stream_handler).await;
}
}

0 comments on commit 25b85c7

Please sign in to comment.