Skip to content

Commit

Permalink
moving test_utils to a crate
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyagara committed Jun 22, 2023
1 parent 4cb719e commit 4e42283
Show file tree
Hide file tree
Showing 17 changed files with 263 additions and 268 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ All notable changes to this project will be documented in this file.
### Added

- `profile` command, prints the provided profile, accepts a `--json`/`-j` to print the profile as prettified json.
- `save` command, saves all currently running applications to a `apps.json` file.
- `--saved` flag to `start`, will try to start all applications saved in the `apps.json` file.
- More helper functions like `get_socket_dir` and `check_app_exists`.

### Changed
Expand All @@ -15,6 +17,7 @@ All notable changes to this project will be documented in this file.
- `stop`, `status` now uses a custom socket event.
- `stop` can now send a custom stop command if provided in a profile.
- `stop` now has a `--force`/`-f` flag to bypass a user defined stop command and send a SIGTERM signal.
- Moved `test_utils` to a separate crate.

### Removed

Expand Down
23 changes: 16 additions & 7 deletions Cargo.lock

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

20 changes: 13 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,17 @@ license = "Apache-2.0"
rust-version = "1.65"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[workspace]
members = ["test_utils"]

[dependencies]
[workspace.dependencies]
anyhow = "1.0.70"
serial_test = "2.0.0"
predicates = "3.0.3"
assert_cmd = "2.0.11"

[dependencies]
anyhow.workspace = true
clap = { version = "4.3.3", features = ["derive"] }
crossbeam = "0.8.2"
crossterm = { version = "0.26.1", default-features = false }
Expand All @@ -32,13 +40,11 @@ libc = { version = "0.2.146" }
serde = { version = "1.0.164", features = ["derive"] }
serde_json = "1.0.96"

[build-dependencies]
anyhow = "1.0.70"

[dev-dependencies]
assert_cmd = "2.0.11"
predicates = "3.0.3"
serial_test = "2.0.0"
anyhow.workspace = true
serial_test.workspace = true
predicates.workspace = true
test_utils = { path = "test_utils" }

[profile.release]
strip = true
Expand Down
17 changes: 7 additions & 10 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
use anyhow::{Context, Result};
use std::{env, fs, path::PathBuf};

fn main() -> Result<()> {
let home = env::var("HOME").context("Error getting HOME env.")?;
fn main() {
let home = env::var("HOME").expect("Error getting HOME env.");

let mut crescent_dir = PathBuf::from(home);

crescent_dir.push(".crescent/profiles");

if !crescent_dir.exists() {
fs::create_dir_all(&crescent_dir)
.context("Error creating crescent and profiles directory.")?;
fs::create_dir_all(&crescent_dir).expect("Error creating crescent and profiles directory.");
}

let base_profiles_dir = PathBuf::from("./profiles");

let base_profiles = base_profiles_dir
.read_dir()
.context("Error reading base profiles directory.")?
.expect("Error reading base profiles directory.")
.flatten();

'base_loop: for base_profile in base_profiles {
let user_profiles = crescent_dir
.read_dir()
.context("Error reading user profiles directory.")?
.expect("Error reading user profiles directory.")
.flatten();

for user_profile in user_profiles {
Expand All @@ -35,8 +33,7 @@ fn main() -> Result<()> {
fs::copy(
base_profile.path(),
crescent_dir.join(base_profile.file_name()),
)?;
)
.expect("Error copying profile.");
}

Ok(())
}
2 changes: 1 addition & 1 deletion src/commands/attach.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ fn ui<B: Backend>(f: &mut Frame<B>, app: &mut AttachTerminal, stats_list: &Strin
#[cfg(test)]
mod tests {
use super::*;
use crate::test_util::test_utils;
extern crate test_utils;
use predicates::Predicate;
use std::{
env::temp_dir,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl ListArgs {
#[cfg(test)]
mod tests {
use super::*;
use crate::test_util::test_utils;
extern crate test_utils;
use anyhow::Context;
use serial_test::serial;
use std::assert_eq;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl SendArgs {
#[cfg(test)]
mod tests {
use super::*;
use crate::test_util::test_utils;
extern crate test_utils;
use std::path::PathBuf;
use std::{env, fs};

Expand Down
2 changes: 1 addition & 1 deletion src/commands/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl SignalArgs {
#[cfg(test)]
mod tests {
use super::*;
use crate::test_util::test_utils;
extern crate test_utils;
use anyhow::Context;
use std::{
env,
Expand Down
10 changes: 4 additions & 6 deletions src/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@ use crate::{
application::{self, Application},
crescent::{self, Profile},
logger, subprocess,
util::print_title_cyan,
util::{self, print_title_cyan},
};
use anyhow::{anyhow, Context, Result};
use clap::Args;
use daemonize::Daemonize;
use log::LevelFilter;
use serde::{Deserialize, Serialize};
use std::{
env,
fs::{self, File},
path::Path,
process::Command,
};

#[derive(Args, Clone, Serialize, Deserialize, Default)]
Expand Down Expand Up @@ -245,8 +243,8 @@ fn start_saved() -> Result<()> {
continue;
}

let exec_path = env::current_exe()?;
let mut cmd = Command::new(exec_path);
let exec_path = util::get_exec_path();
let mut cmd = util::get_base_command(exec_path);
let mut cmd_args = vec![];

cmd_args.push("start".to_string());
Expand Down Expand Up @@ -313,7 +311,7 @@ pub fn start(app_info: Application) -> Result<()> {
#[cfg(test)]
mod tests {
use super::*;
use crate::test_util::test_utils;
extern crate test_utils;
use predicates::prelude::predicate;

#[test]
Expand Down
3 changes: 0 additions & 3 deletions src/crescent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,10 @@ mod tests {
#[test]
fn unit_get_profile() -> Result<()> {
let profile = get_profile(&String::from("example"))?;

assert!(profile.__comment.is_some());

let err = get_profile(&String::from("does-not-exist")).unwrap_err();

assert_eq!(format!("{}", err), "Profile not found.");

Ok(())
}
}
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ mod crescent;
mod logger;
mod subprocess;
mod tail;
mod test_util;
mod util;

#[derive(Parser)]
Expand Down
3 changes: 2 additions & 1 deletion src/subprocess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ pub fn send_unix_signal(pid: Pid, signal: u8) -> Result<()> {
#[cfg(test)]
mod tests {
use super::*;
use crate::{application::app_pids_by_name, test_util::test_utils};
use crate::application::app_pids_by_name;
extern crate test_utils;

#[test]
fn unit_subprocess_terminate() -> Result<()> {
Expand Down
108 changes: 0 additions & 108 deletions src/test_util.rs

This file was deleted.

0 comments on commit 4e42283

Please sign in to comment.