Skip to content

Commit

Permalink
use a single setup_octocrab
Browse files Browse the repository at this point in the history
  • Loading branch information
joshrotenberg committed Feb 5, 2025
1 parent ce8c885 commit 26cd6e3
Show file tree
Hide file tree
Showing 66 changed files with 181 additions and 465 deletions.
9 changes: 2 additions & 7 deletions tests/actions_add_selected_repo_to_org_secret_test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
mod mock_error;
mod test_common;

use mock_error::setup_error_handler;
use octocrab::Octocrab;
use test_common::{setup_error_handler, setup_octocrab};
use wiremock::{
matchers::{method, path},
Mock, MockServer, ResponseTemplate,
Expand Down Expand Up @@ -30,10 +29,6 @@ async fn setup_put_api(template: ResponseTemplate) -> MockServer {
mock_server
}

fn setup_octocrab(uri: &str) -> Octocrab {
Octocrab::builder().base_uri(uri).unwrap().build().unwrap()
}

const ORG: &str = "org";
const SECRET_NAME: &str = "some_secret";
const REPOSITORY_ID: u64 = 456;
Expand Down
9 changes: 2 additions & 7 deletions tests/actions_delete_workflow_run_logs_test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
mod mock_error;
mod test_common;

use mock_error::setup_error_handler;
use octocrab::Octocrab;
use test_common::{setup_error_handler, setup_octocrab};
use wiremock::{
matchers::{method, path},
Mock, MockServer, ResponseTemplate,
Expand Down Expand Up @@ -30,10 +29,6 @@ async fn setup_delete_workflow_run_logs_api(template: ResponseTemplate) -> MockS
mock_server
}

fn setup_octocrab(uri: &str) -> Octocrab {
Octocrab::builder().base_uri(uri).unwrap().build().unwrap()
}

const OWNER: &str = "org";
const REPO: &str = "some-repo";
const RUN_ID: u64 = 456;
Expand Down
9 changes: 2 additions & 7 deletions tests/actions_remove_selected_repo_from_org_secret_test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
mod mock_error;
mod test_common;

use mock_error::setup_error_handler;
use octocrab::Octocrab;
use test_common::{setup_error_handler, setup_octocrab};
use wiremock::{
matchers::{method, path},
Mock, MockServer, ResponseTemplate,
Expand Down Expand Up @@ -30,10 +29,6 @@ async fn setup_delete_api(template: ResponseTemplate) -> MockServer {
mock_server
}

fn setup_octocrab(uri: &str) -> Octocrab {
Octocrab::builder().base_uri(uri).unwrap().build().unwrap()
}

const ORG: &str = "org";
const SECRET_NAME: &str = "some_secret";
const REPOSITORY_ID: u64 = 456;
Expand Down
4 changes: 2 additions & 2 deletions tests/actions_self_hosted_runners.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// Tests for calls to the actions self-hosted runners API:
// - /repos/{owner}/{repo}/actions/runners
// - /orgs/{org}/actions/runners
mod mock_error;
mod test_common;

use http::StatusCode;
use mock_error::setup_error_handler;
use octocrab::{
models::{
actions::{SelfHostedRunner, SelfHostedRunnerJitConfig, SelfHostedRunnerToken},
Expand All @@ -14,6 +13,7 @@ use octocrab::{
};
use serde::{Deserialize, Serialize};
use serde_json::json;
use test_common::setup_error_handler;
use wiremock::{
matchers::{body_json, method, path},
Mock, MockServer, ResponseTemplate,
Expand Down
9 changes: 2 additions & 7 deletions tests/actions_workflows_dispatches_test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
mod mock_error;
mod test_common;

use mock_error::setup_error_handler;
use octocrab::Octocrab;
use test_common::{setup_error_handler, setup_octocrab};
use wiremock::{
matchers::{method, path},
Mock, MockServer, ResponseTemplate,
Expand Down Expand Up @@ -30,10 +29,6 @@ async fn setup_post_api(template: ResponseTemplate) -> MockServer {
mock_server
}

fn setup_octocrab(uri: &str) -> Octocrab {
Octocrab::builder().base_uri(uri).unwrap().build().unwrap()
}

const OWNER: &str = "org";
const REPO: &str = "some-repo";
const WORKFLOW_ID: &str = "workflow.yaml";
Expand Down
9 changes: 2 additions & 7 deletions tests/check_suites.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ use wiremock::{
Mock, MockServer, ResponseTemplate,
};

use mock_error::setup_error_handler;
use octocrab::models::checks::{AutoTriggerCheck, CheckSuite, CheckSuitePreferences};
use octocrab::models::{AppId, CheckRunId, CheckSuiteId};
use octocrab::params::repos::Commitish;
use octocrab::Octocrab;
use test_common::{setup_error_handler, setup_octocrab};

/// Unit test for calls to the `/repos/OWNER/REPO/contributors` endpoint
mod mock_error;
mod test_common;

const OWNER: &str = "XAMPPRocky";
const REPO: &str = "octocrab";
Expand All @@ -31,10 +30,6 @@ async fn setup_api(template: ResponseTemplate) -> MockServer {
mock_server
}

fn setup_octocrab(uri: &str) -> Octocrab {
Octocrab::builder().base_uri(uri).unwrap().build().unwrap()
}

#[tokio::test]
async fn should_create_check_suite() {
let check_suite_response: CheckSuite =
Expand Down
9 changes: 2 additions & 7 deletions tests/code_scanning_alert_update_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ use wiremock::{
Mock, MockServer, ResponseTemplate,
};

use mock_error::setup_error_handler;
use octocrab::models::code_scannings::CodeScanningAlert;
use octocrab::params::AlertState;
use octocrab::Octocrab;
use test_common::{setup_error_handler, setup_octocrab};

mod mock_error;
mod test_common;

async fn setup_issue_check_assignee_api(template: ResponseTemplate) -> MockServer {
let owner: &str = "org";
Expand All @@ -35,10 +34,6 @@ async fn setup_issue_check_assignee_api(template: ResponseTemplate) -> MockServe
mock_server
}

fn setup_octocrab(uri: &str) -> Octocrab {
Octocrab::builder().base_uri(uri).unwrap().build().unwrap()
}

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

Expand Down
9 changes: 2 additions & 7 deletions tests/code_scanning_alerts_list_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ use wiremock::{
Mock, MockServer, ResponseTemplate,
};

use mock_error::setup_error_handler;
use octocrab::models::code_scannings::CodeScanningAlert;
use octocrab::Octocrab;
use test_common::{setup_error_handler, setup_octocrab};

mod mock_error;
mod test_common;

const OWNER: &str = "org";
const REPO: &str = "some-repo";
Expand Down Expand Up @@ -55,10 +54,6 @@ async fn setup_codescanning_list_api(template: ResponseTemplate, is_org: bool) -
mock_server
}

fn setup_octocrab(uri: &str) -> Octocrab {
Octocrab::builder().base_uri(uri).unwrap().build().unwrap()
}

#[tokio::test]
async fn check_list_200() {
let s = include_str!("resources/codescanning_alerts_multiple.json");
Expand Down
9 changes: 2 additions & 7 deletions tests/code_scanning_analysis_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ use wiremock::{
Mock, MockServer, ResponseTemplate,
};

use mock_error::setup_error_handler;
use octocrab::models::code_scannings::CodeScanningAlert;
use octocrab::Octocrab;
use test_common::{setup_error_handler, setup_octocrab};

mod mock_error;
mod test_common;

async fn setup_issue_check_assignee_api(template: ResponseTemplate) -> MockServer {
let owner: &str = "org";
Expand All @@ -35,10 +34,6 @@ async fn setup_issue_check_assignee_api(template: ResponseTemplate) -> MockServe
mock_server
}

fn setup_octocrab(uri: &str) -> Octocrab {
Octocrab::builder().base_uri(uri).unwrap().build().unwrap()
}

const OWNER: &str = "org";
const REPO: &str = "some-repo";
const ASSIGNEE: &str = "some-user";
Expand Down
10 changes: 3 additions & 7 deletions tests/commit_associated_check_runs_tests.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/// Tests API calls related to check runs of a specific commit.
mod mock_error;
mod test_common;

use mock_error::setup_error_handler;
use octocrab::models::checks::ListCheckRuns;
use octocrab::models::CheckRunId;
use octocrab::params::repos::Reference;
use octocrab::{Error, Octocrab};
use octocrab::Error;
use serde_json::{json, Value};
use test_common::{setup_error_handler, setup_octocrab};
use wiremock::{
matchers::{method, path},
Mock, MockServer, ResponseTemplate,
Expand All @@ -30,10 +30,6 @@ async fn setup_api(template: ResponseTemplate) -> MockServer {
mock_server
}

fn setup_octocrab(uri: &str) -> Octocrab {
Octocrab::builder().base_uri(uri).unwrap().build().unwrap()
}

#[tokio::test]
async fn should_return_page_with_check_runs() {
let mocked_response: ListCheckRuns =
Expand Down
10 changes: 3 additions & 7 deletions tests/current_user_orgs_test.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Tests for calls to the /user/memberships/orgs API.
mod mock_error;
mod test_common;

use mock_error::setup_error_handler;
use octocrab::{models::orgs::MembershipInvitation, Octocrab, Page};
use octocrab::{models::orgs::MembershipInvitation, Page};
use serde::{Deserialize, Serialize};
use test_common::{setup_error_handler, setup_octocrab};
use wiremock::{
matchers::{method, path},
Mock, MockServer, ResponseTemplate,
Expand All @@ -30,10 +30,6 @@ async fn setup_api(template: ResponseTemplate) -> MockServer {
mock_server
}

fn setup_octocrab(uri: &str) -> Octocrab {
Octocrab::builder().base_uri(uri).unwrap().build().unwrap()
}

#[tokio::test]
async fn should_return_page_with_invitations() {
let membership_invitations: Vec<MembershipInvitation> =
Expand Down
9 changes: 2 additions & 7 deletions tests/dependabot_alerts_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ use wiremock::{
Mock, MockServer, ResponseTemplate,
};

use mock_error::setup_error_handler;
use octocrab::models::repos::dependabot::DependabotAlert;
use octocrab::Octocrab;
use test_common::{setup_error_handler, setup_octocrab};

mod mock_error;
mod test_common;

const OWNER: &str = "org";
const REPO: &str = "some-repo";
Expand Down Expand Up @@ -37,10 +36,6 @@ async fn setup_dependabot_api(template: ResponseTemplate) -> MockServer {
mock_server
}

fn setup_octocrab(uri: &str) -> Octocrab {
Octocrab::builder().base_uri(uri).unwrap().build().unwrap()
}

#[tokio::test]
async fn check_dependabot_alerts_list_200() {
let s = include_str!("resources/check_dependabot_alerts.json");
Expand Down
9 changes: 2 additions & 7 deletions tests/events_test.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// Tests for calls to the /repos/{owner}/{repo}/events API.
mod mock_error;
mod test_common;

use mock_error::setup_error_handler;
use octocrab::{
etag::{EntityTag, Etagged},
models::events,
Octocrab,
};
use serde::{Deserialize, Serialize};
use test_common::{setup_error_handler, setup_octocrab};
use wiremock::{
matchers::{method, path},
Mock, MockServer, ResponseTemplate,
Expand All @@ -29,10 +28,6 @@ async fn setup_api(template: ResponseTemplate) -> MockServer {
mock_server
}

fn setup_octocrab(uri: &str) -> Octocrab {
Octocrab::builder().base_uri(uri).unwrap().build().unwrap()
}

#[tokio::test]
async fn should_return_page_with_events_and_etag() {
let event: events::Event =
Expand Down
10 changes: 3 additions & 7 deletions tests/follow_redirect.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Tests for calls to the /repos/{owner}/{repo}/stargazers API.
mod mock_error;
mod test_common;

use mock_error::setup_error_handler;
use octocrab::{models::StarGazer, Octocrab, Page};
use octocrab::{models::StarGazer, Page};
use serde::{Deserialize, Serialize};
use test_common::{setup_error_handler, setup_octocrab};
use wiremock::{
http::HeaderValue,
matchers::{method, path},
Expand Down Expand Up @@ -44,10 +44,6 @@ async fn setup_api(template: ResponseTemplate) -> MockServer {
mock_server
}

fn setup_octocrab(uri: &str) -> Octocrab {
Octocrab::builder().base_uri(uri).unwrap().build().unwrap()
}

const OWNER: &str = "old-owner";
const REPO: &str = "repo";

Expand Down
10 changes: 3 additions & 7 deletions tests/generate_release_notes_test.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/// Tests generating release notes:
/// /repos/{owner}/{repo}/releases/generate-notes
mod mock_error;
use mock_error::setup_error_handler;
mod test_common;

use octocrab::models::repos::ReleaseNotes;
use octocrab::Octocrab;
use test_common::{setup_error_handler, setup_octocrab};
use wiremock::{
matchers::{method, path},
Mock, MockServer, ResponseTemplate,
Expand All @@ -27,10 +27,6 @@ async fn setup_api(template: ResponseTemplate) -> MockServer {
mock_server
}

fn setup_octocrab(uri: &str) -> Octocrab {
Octocrab::builder().base_uri(uri).unwrap().build().unwrap()
}

#[tokio::test]
async fn should_return_page_with_check_runs() {
let owner = "owner";
Expand Down
9 changes: 2 additions & 7 deletions tests/gists_test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
mod mock_error;
mod test_common;

use mock_error::setup_error_handler;
use octocrab::Octocrab;
use test_common::{setup_error_handler, setup_octocrab};
use wiremock::{
matchers::{method, path},
Mock, MockServer, ResponseTemplate,
Expand Down Expand Up @@ -83,10 +82,6 @@ async fn setup_put_api(template: ResponseTemplate) -> MockServer {
mock_server
}

fn setup_octocrab(uri: &str) -> Octocrab {
Octocrab::builder().base_uri(uri).unwrap().build().unwrap()
}

const GIST_ID: &str = "12c55a94bd03166ff33ed0596263b4c6";

#[tokio::test]
Expand Down
Loading

0 comments on commit 26cd6e3

Please sign in to comment.