Skip to content

Commit

Permalink
Test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vlad1slav committed Nov 21, 2024
1 parent 7ae42c8 commit 19ba34a
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions tests/secrets_alerts_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod mock_error;

const OWNER: &str = "org";
const REPO: &str = "some-repo";
const ALERT_NUMBER: u32 = 5;

async fn setup_secrets_api(template: ResponseTemplate) -> MockServer {
let mock_server = MockServer::start().await;
Expand All @@ -38,6 +39,31 @@ async fn setup_secrets_api(template: ResponseTemplate) -> MockServer {
mock_server
}

async fn setup_secrets_locations_api(template: ResponseTemplate) -> MockServer {
let mock_server = MockServer::start().await;

Mock::given(method("GET"))
.and(path(format!(
"/repos/{owner}/{repo}/secret-scanning/alerts/5/locations",
owner = OWNER,
repo = REPO
)))
.respond_with(template.clone())
.mount(&mock_server)
.await;
setup_error_handler(
&mock_server,
&format!(
"GET on /repos/{owner}/{repo}/secret-scanning/alerts/{ALERT_NUMBER}/locations was not received",
owner = OWNER,
repo = REPO
),
)
.await;

mock_server
}

fn setup_octocrab(uri: &str) -> Octocrab {
Octocrab::builder().base_uri(uri).unwrap().build().unwrap()
}
Expand Down Expand Up @@ -83,13 +109,13 @@ async fn check_secrets_alert_locations_list_200() {
let s: &str = include_str!("resources/check_secrets_alerts_locations.json");
let alert: Vec<SecretsScanningAlertLocation> = serde_json::from_str(s).unwrap();
let template = ResponseTemplate::new(200).set_body_json(&alert);
let mock_server = setup_secrets_api(template).await;
let mock_server = setup_secrets_locations_api(template).await;
let client = setup_octocrab(&mock_server.uri());

let result = client
.repos(OWNER.to_owned(), REPO.to_owned())
.secrets_scanning()
.get_alert_locations(5)
.get_alert_locations(ALERT_NUMBER)
.await;

assert!(
Expand Down

0 comments on commit 19ba34a

Please sign in to comment.