Skip to content

Commit

Permalink
Add graph proxy multiple workflows name query test
Browse files Browse the repository at this point in the history
  • Loading branch information
yousefmoazzam committed Dec 13, 2024
1 parent f33e825 commit 25d4642
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
56 changes: 56 additions & 0 deletions graph-proxy/src/graphql/workflows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,4 +504,60 @@ mod tests {
let expected_data = Value::from(outer_map);
assert_eq!(resp.data, expected_data);
}

#[tokio::test]
async fn multiple_workflows_query() {
let proposal_code = "mg";
let proposal_number = 36964;
let number = 1;
let namespace = format!("{}{}-{}", proposal_code, proposal_number, number);

let server = httpmock::MockServer::start();
let mut multiple_workflows_response_file_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
multiple_workflows_response_file_path.push("test-resources");
multiple_workflows_response_file_path.push("get-workflows-in-namespace.json");

let workflows_endpoint = server.mock(|when, then| {
when.method(httpmock::Method::GET)
.path(format!("/api/v1/workflows/{}", namespace));
then.status(200)
.header("content-type", "application/json")
.body(std::fs::read_to_string(multiple_workflows_response_file_path).unwrap());
});

let token = None::<Authorization<Bearer>>;
let argo_server_url = Url::parse(&server.base_url()).unwrap();
let schema = root_schema_builder()
.data(ArgoServerUrl(argo_server_url))
.data(token)
.finish();
let query = r#"
query {
workflows(visit: {proposalCode: "mg", proposalNumber: 36964, number: 1}) {
nodes {
name
}
}
}
"#;
let resp = schema.execute(query).await.into_result().unwrap();

workflows_endpoint.assert();
let mut outer_map = IndexMap::new();
let mut nodes_map = IndexMap::new();
let mut nodes = Vec::new();

for workflow_name in ["numpy-benchmark-wdkwj", "numpy-benchmark-r9csr"] {
let mut map = IndexMap::new();
let key = Name::new("name");
let value = Value::from(workflow_name);
map.insert(key, value);
nodes.push(Value::from(map));
}

nodes_map.insert(Name::new("nodes"), Value::from(nodes));
outer_map.insert(Name::new("workflows"), Value::from(nodes_map));
let expected_data = Value::from(outer_map);
assert_eq!(resp.data, expected_data);
}
}
1 change: 1 addition & 0 deletions graph-proxy/test-resources/get-workflows-in-namespace.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"metadata":{"resourceVersion":"158534252","continue":"3"},"items":[{"metadata":{"name":"numpy-benchmark-wdkwj","namespace":"mg36964-1","uid":"bed157b2-ecf2-4423-9945-8ecfa767a151","creationTimestamp":"2024-11-19T09:45:46Z","labels":{"submit-from-ui":"true","workflows.argoproj.io/cluster-workflow-template":"numpy-benchmark","workflows.argoproj.io/completed":"true","workflows.argoproj.io/creator":"ed66f621-7b56-4157-a255-a03af5bd8f0e","workflows.argoproj.io/creator-email":"garry.o-donnell.at.diamond.ac.uk","workflows.argoproj.io/creator-preferred-username":"enu43627","workflows.argoproj.io/phase":"Succeeded","workflows.argoproj.io/workflow-archiving-status":"Persisted"},"annotations":{"workflows.argoproj.io/pod-name-format":"v2"}},"spec":{"arguments":{}},"status":{"phase":"Succeeded","startedAt":"2024-11-19T09:45:46Z","finishedAt":"2024-11-19T09:46:59Z","estimatedDuration":68,"progress":"1/1","resourcesDuration":{"cpu":6,"memory":158}}},{"metadata":{"name":"numpy-benchmark-r9csr","namespace":"mg36964-1","uid":"169bd094-ace5-43af-aaa5-d4528762e1b2","creationTimestamp":"2024-11-12T13:04:00Z","labels":{"submit-from-ui":"true","workflows.argoproj.io/cluster-workflow-template":"numpy-benchmark","workflows.argoproj.io/completed":"true","workflows.argoproj.io/creator":"d2cc5e04-14e7-453b-9622-e20bea96ccf5","workflows.argoproj.io/creator-email":"yousef.moazzam.at.diamond.ac.uk","workflows.argoproj.io/creator-preferred-username":"twi18192","workflows.argoproj.io/phase":"Succeeded","workflows.argoproj.io/workflow-archiving-status":"Persisted"},"annotations":{"workflows.argoproj.io/pod-name-format":"v2"}},"spec":{"arguments":{}},"status":{"phase":"Succeeded","startedAt":"2024-11-12T13:04:00Z","finishedAt":"2024-11-12T13:05:18Z","estimatedDuration":11,"progress":"1/1","resourcesDuration":{"cpu":6,"memory":262}}}]}

0 comments on commit 25d4642

Please sign in to comment.