Skip to content

Commit

Permalink
Added infrastructure to do integration testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
apognu committed May 3, 2024
1 parent 71cf19e commit c5fa133
Show file tree
Hide file tree
Showing 15 changed files with 1,091 additions and 54 deletions.
128 changes: 93 additions & 35 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,8 @@ tracing = "0.1.40"

[profile.release]
lto = true

[dev-dependencies]
greetd-stub = "0.3.0"
tempfile = "3.10.1"
unicode-width = "0.1.12"
12 changes: 11 additions & 1 deletion src/event.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use std::time::Duration;

use crossterm::event::{Event as TermEvent, EventStream, KeyEvent};
use crossterm::event::{Event as TermEvent, KeyEvent};
use futures::{future::FutureExt, StreamExt};
use tokio::{
process::Command,
sync::mpsc::{self, Sender},
};

#[cfg(not(test))]
use crossterm::event::EventStream;

use crate::AuthStatus;

const FRAME_RATE: f64 = 2.0;
Expand All @@ -31,7 +34,14 @@ impl Events {
let tx = tx.clone();

async move {
#[cfg(not(test))]
let mut stream = EventStream::new();

// In tests, we are not capturing events from the terminal, so we need
// to replace the crossterm::EventStream with a dummy pending stream.
#[cfg(test)]
let mut stream = futures::stream::pending::<Result<TermEvent, ()>>();

let mut render_interval = tokio::time::interval(Duration::from_secs_f64(1.0 / FRAME_RATE));

loop {
Expand Down
9 changes: 9 additions & 0 deletions src/greeter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ pub struct Greeter {

// Style object for the terminal UI
pub theme: Theme,
// Display the current time
pub time: bool,
// Time format
pub time_format: Option<String>,
// Greeting message (MOTD) to use to welcome the user.
pub greeting: Option<String>,
// Transaction message to show to the user.
Expand Down Expand Up @@ -193,6 +197,7 @@ impl Greeter {
selected: 0,
};

#[cfg(not(test))]
greeter.parse_options().await;

greeter.sessions = Menu {
Expand Down Expand Up @@ -464,11 +469,15 @@ impl Greeter {
self.secret_display = SecretDisplay::Character(asterisk);
}

self.time = self.config().opt_present("time");

if let Some(format) = self.config().opt_str("time-format") {
if StrftimeItems::new(&format).any(|item| item == Item::Error) {
eprintln!("Invalid strftime format provided in --time-format");
process::exit(1);
}

self.time_format = Some(format);
}

if self.config().opt_present("user-menu") {
Expand Down
Loading

0 comments on commit c5fa133

Please sign in to comment.