|
| 1 | +use anyhow::Result; |
| 2 | +use async_trait::async_trait; |
| 3 | +use clap::{Parser, Subcommand}; |
| 4 | +use oauth2_tests::Oauth2Test; |
| 5 | +use std::sync::Arc; |
| 6 | +use support_eligibility_test::SupportEligibilityTest; |
| 7 | +use support_tickets_test::SupportTicketsTest; |
| 8 | +use wp_api::{ |
| 9 | + WpApiClientDelegate, WpAppNotifier, |
| 10 | + auth::{WpAuthentication, WpAuthenticationProvider}, |
| 11 | + middleware::WpApiMiddlewarePipeline, |
| 12 | + reqwest_request_executor::ReqwestRequestExecutor, |
| 13 | + wp_com::client::WpComApiClient, |
| 14 | +}; |
| 15 | + |
| 16 | +mod oauth2_tests; |
| 17 | +mod support_eligibility_test; |
| 18 | +mod support_tickets_test; |
| 19 | + |
| 20 | +#[derive(Parser)] |
| 21 | +#[command(author, version, about, long_about = None)] |
| 22 | +struct Cli { |
| 23 | + #[command(subcommand)] |
| 24 | + command: Commands, |
| 25 | +} |
| 26 | + |
| 27 | +#[derive(Subcommand)] |
| 28 | +enum Commands { |
| 29 | + Test { |
| 30 | + #[arg(short = 't', long = "token", env = "WP_COM_API_KEY")] |
| 31 | + token: String, |
| 32 | + }, |
| 33 | +} |
| 34 | + |
| 35 | +#[async_trait] |
| 36 | +trait Testable { |
| 37 | + async fn test(&self) -> Result<(), anyhow::Error>; |
| 38 | +} |
| 39 | + |
| 40 | +#[derive(Debug)] |
| 41 | +pub struct EmptyAppNotifier; |
| 42 | + |
| 43 | +#[async_trait] |
| 44 | +impl WpAppNotifier for EmptyAppNotifier { |
| 45 | + async fn requested_with_invalid_authentication(&self) { |
| 46 | + // no-op |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +#[tokio::main] |
| 51 | +async fn main() -> Result<(), anyhow::Error> { |
| 52 | + let cli = Cli::parse(); |
| 53 | + |
| 54 | + match cli.command { |
| 55 | + Commands::Test { token } => { |
| 56 | + let delegate = WpApiClientDelegate { |
| 57 | + auth_provider: WpAuthenticationProvider::static_with_auth( |
| 58 | + WpAuthentication::Bearer { |
| 59 | + token: token.clone(), |
| 60 | + }, |
| 61 | + ) |
| 62 | + .into(), |
| 63 | + request_executor: Arc::new(ReqwestRequestExecutor::default()), |
| 64 | + middleware_pipeline: Arc::new(WpApiMiddlewarePipeline::default()), |
| 65 | + app_notifier: Arc::new(EmptyAppNotifier), |
| 66 | + }; |
| 67 | + |
| 68 | + let client = WpComApiClient::new(delegate); |
| 69 | + |
| 70 | + Oauth2Test { |
| 71 | + client: &client, |
| 72 | + token: &token, |
| 73 | + } |
| 74 | + .test() |
| 75 | + .await?; |
| 76 | + SupportTicketsTest { client: &client }.test().await?; |
| 77 | + SupportEligibilityTest { client: &client }.test().await?; |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + Ok(()) |
| 82 | +} |
0 commit comments