Skip to content

Commit

Permalink
chore: set up actual test CI
Browse files Browse the repository at this point in the history
  • Loading branch information
crepererum committed Aug 12, 2023
1 parent 491425b commit 4fa0629
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 3 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ jobs:
toolchain: stable
override: true

- name: Install Geckodriver
uses: browser-actions/setup-geckodriver@latest
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Start Geckodriver
run: geckodriver &

- name: Cache
uses: Swatinem/rust-cache@v2

Expand All @@ -57,6 +65,9 @@ jobs:
with:
command: test
args: --all-features --workspace
env:
TUTANOTA_CLI_USERNAME: ${{ secrets.TUTANOTA_CLI_USERNAME }}
TUTANOTA_CLI_PASSWORD: ${{ secrets.TUTANOTA_CLI_PASSWORD }}

- name: cargo doc
uses: actions-rs/cargo@v1
Expand Down
105 changes: 104 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ tokio = { version = "1.30.0", features = ["macros", "rt-multi-thread"] }
tracing = "0.1.38"
tracing-log = "0.1.3"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }

[dev-dependencies]
assert_cmd = "2.0.12"
4 changes: 2 additions & 2 deletions src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ pub struct LoggingCLIConfig {
pub fn setup_logging(config: LoggingCLIConfig) -> Result<()> {
LogTracer::init()?;

let filter = match config.log_verbose_count {
let base_filter = match config.log_verbose_count {
0 => "warn",
1 => "info",
2 => "debug",
_ => "trace",
};
let filter = EnvFilter::try_new(filter)?;
let filter = EnvFilter::try_new(format!("{base_filter},hyper=info"))?;

let subscriber = FmtSubscriber::builder().with_env_filter(filter).finish();

Expand Down
25 changes: 25 additions & 0 deletions src/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ pub async fn perform_login(config: LoginCLIConfig, webdriver: &WebDriver) -> Res
.context("wait for login")??;
debug!("login done");

confirm_dialog(webdriver)
.await
.context("confirm potential dialog")?;

Ok(())
}

Expand All @@ -94,3 +98,24 @@ async fn has_new_email_button(webdriver: &WebDriver) -> Result<bool> {

Ok(false)
}

async fn confirm_dialog(webdriver: &WebDriver) -> Result<()> {
debug!("confirm potential dialogs");

let Some(dialog) = webdriver.find_at_most_one(By::ClassName("dialog")).await.context("find dialog box")? else {
debug!("no dialog found");
return Ok(());
};
debug!("found dialog, trying to click OK");

let ok_button = dialog
.find_one_with_attr(By::Tag("button"), "title", "Ok")
.await
.context("find OK button")?;
debug!("found OK button");

ok_button.click().await.context("click OK button")?;
debug!("clicked OK button");

Ok(())
}
46 changes: 46 additions & 0 deletions tests/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use std::sync::{LockResult, Mutex, MutexGuard};

use assert_cmd::Command;

/// We can only have a single webdriver session.
static WEBDRIVER_MUTEX: Mutex<()> = Mutex::new(());

#[test]
fn test_help() {
let mut cmd = cmd();
cmd.arg("--help").assert().success();
}

#[test]
fn test_list_folders() {
let _guard = webdriver_mutex();
let mut cmd = cmd();
cmd.arg("-vv")
.arg("list-folders")
.assert()
.success()
.stdout(["Inbox", "Drafts", "Sent", "Trash", "Archive", "Spam"].join("\n"));
}

#[test]
fn test_export() {
let _guard = webdriver_mutex();
let mut cmd = cmd();
cmd.arg("-vv")
.arg("export")
.arg("--folder=Archive")
.assert()
.success();
}

fn cmd() -> Command {
Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap()
}

fn webdriver_mutex() -> MutexGuard<'static, ()> {
match WEBDRIVER_MUTEX.lock() {
LockResult::Ok(guard) => guard,
// poisoned locks are OK
LockResult::Err(e) => e.into_inner(),
}
}

0 comments on commit 4fa0629

Please sign in to comment.