Skip to content

Commit

Permalink
feat(domain): init domain reader
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Aug 28, 2023
1 parent c84d2a8 commit 3e2be16
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
File renamed without changes.
22 changes: 21 additions & 1 deletion counit-server/src/domain/domain_loader.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::path::Path;
use crate::domain::domain_record::DomainRecord;

pub struct DomainLoader {
Expand All @@ -11,7 +12,7 @@ impl DomainLoader {
}
}

pub fn load(&mut self, path: &str) {
pub fn load<P: AsRef<Path>>(&mut self, path: P) {
use walkdir::WalkDir;
for entry in WalkDir::new(path) {
let entry = entry.unwrap();
Expand Down Expand Up @@ -50,4 +51,23 @@ impl DomainLoader {
self.domain_records.push(record);
});
}
}

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

#[test]
fn load_csv() {
let model_dir = Path::new(env!("CARGO_MANIFEST_DIR")).parent()
.unwrap()
.join("_fixtures")
.join("domain");


let mut loader = DomainLoader::new();
loader.load(model_dir);
assert_eq!(loader.domain_records.len(), 29);
}
}
2 changes: 1 addition & 1 deletion counit-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async fn main() -> anyhow::Result<()> {
.nest("/agent", agent_api::router())

// knowledge init
.nest("/translate/domain-language", translate_api::router())
.nest("/translate/domain", translate_api::router())

//align to archguard api
.nest("/scanner", archguard_api::router())
Expand Down
2 changes: 1 addition & 1 deletion counit-server/src/server/agent_api.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use axum::{body::HttpBody, extract::Query, Json, Router};
use axum::{extract::Query, Json, Router};
use axum::http::StatusCode;
use serde::{Deserialize, Serialize};

Expand Down

0 comments on commit 3e2be16

Please sign in to comment.