Skip to content

Commit

Permalink
trying out tes_status unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aaravm committed Jun 26, 2024
1 parent e447b5a commit bcce6ec
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Before running the tests, you need to install Funnel, a task execution system th
Once you have installed Funnel, you can run the tests with (it will automatically run Funnel as well):

```
bash ./run-test.sh
bash ./run-tests.sh
```

To test out the CI/CD workflow locally, install `act` and run the following command:
Expand Down
4 changes: 2 additions & 2 deletions lib/src/serviceinfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ impl ServiceInfo {
let response = self.transport.get("/service-info", None).await;
match response {
Ok(response_body) => match serde_json::from_str::<models::Service>(&response_body) {
Ok(tes_create_task_response) => Ok(tes_create_task_response),
Ok(service) => Ok(service),
Err(e) => {
log::error!("Failed to deserialize response: {}", e);
Err("Failed to deserialize response".into())
Err(e.into())
}
},
Err(e) => {
Expand Down
42 changes: 25 additions & 17 deletions lib/src/tes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ impl Task {

pub async fn status(&self) -> Result<TesState, Box<dyn std::error::Error>> {
let task_id=&self.id;
let url = format!("/ga4gh/tes/v1/tasks/{}", task_id.clone());
let config = Configuration::new(url, None, None);
let config = Configuration::default();
let tes=TES::new(&config).await;
tes?.status(&task_id.clone(), "BASIC").await
}
Expand All @@ -42,13 +41,15 @@ pub struct TES {

impl TES {
pub async fn new(config: &Configuration) -> Result<Self, Box<dyn std::error::Error>> {
let transport = &Transport::new(config);
let service_info = &ServiceInfo::new(config).unwrap();
let transport = Transport::new(config);
let service_info = ServiceInfo::new(config).unwrap();

let resp = service_info.get().await;

// println!("artifact: {}",resp.clone().unwrap().r#type.artifact);
let instance = TES {
config: config.clone(),
transport: transport.clone(),
transport,
service: resp,
};

Expand All @@ -62,18 +63,19 @@ impl TES {
fn check(&self) -> bool {
let resp = &self.service;
return resp.as_ref().unwrap().r#type.artifact == "tes";
// true
}

pub async fn create(
&self,
task: TesTask, /*, params: models::TesTask*/
) -> Result<Task, Box<dyn std::error::Error>> {
// First, check if the service is of TES class
if !self.check() {
// If check fails, log an error and return an Err immediately
log::error!("Service check failed");
return Err("Service check failed".into());
}
// if !self.check() {
// // If check fails, log an error and return an Err immediately
// log::error!("Service check failed");
// return Err("Service check failed".into());
// }
// todo: version in url based on serviceinfo or user config
let response = self
.transport
Expand Down Expand Up @@ -129,6 +131,7 @@ impl TES {
#[cfg(test)]
mod tests {
use crate::configuration::Configuration;
// use crate::tes::Task;
use crate::tes::models::TesTask;
use crate::tes::TES;
use crate::test_utils::{ensure_funnel_running, setup};
Expand Down Expand Up @@ -159,12 +162,17 @@ mod tests {
assert!(!task.is_empty(), "Task ID should not be empty"); // doube check if it's a correct assertion
}

// #[tokio::test]
// async fn test_task_status() {
// setup();
#[tokio::test]
async fn test_task_status() {
// setup();

// let task = create_task().await.expect("Failed to create task");
// // Now use task to get the task status...
// // todo: assert_eq!(task.status().await, which status?);
// }
// let taskid = &create_task().await.expect("Failed to create task");
// assert!(!taskid.clone().is_empty(), "Task ID should not be empty"); // doube check if it's a correct assertion

// let task=Task::new(taskid.clone());
// let status= task.status().await;
// println!("Task: {:?}", status);
// // Now use task to get the task status...
// // todo: assert_eq!(task.status().await, which status?);
}
}

0 comments on commit bcce6ec

Please sign in to comment.