Skip to content

Commit

Permalink
fix test, improved build file
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyagara committed Jun 23, 2023
1 parent fc90958 commit b9aeb7b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 24 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ All notable changes to this project will be documented in this file.
- `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.
- Refactored some tests.
- Improved a bit error handling on `build.rs`.

### Removed

Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ serial_test.workspace = true
predicates.workspace = true
test_utils = { path = "test_utils" }

[build-dependencies]
anyhow.workspace = true

[profile.release]
strip = true
lto = true
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<div align="center">
<h1>🌙crescent</h1>
<p>A process manager for game servers and services.</p>
<p>A process manager for game servers and services.</p>
<p>
<a href="https://crates.io/crates/crescent-cli">
<img src="https://img.shields.io/crates/v/crescent-cli?style=flat-square"/>
</a>
<a href="https://github.com/Kyagara/crescent/actions?query=workflow">
<img src="https://img.shields.io/github/actions/workflow/status/Kyagara/crescent/ci.yaml?label=CI&style=flat-square"/>
</a>
<a href="https://codecov.io/gh/Kyagara/crescent">
<a href="https://codecov.io/gh/Kyagara/crescent">
<img src="https://img.shields.io/codecov/c/github/Kyagara/crescent?style=flat-square"/>
</a>
</p>
Expand Down
55 changes: 33 additions & 22 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,50 @@
use anyhow::{anyhow, Result};
use std::{env, fs, path::PathBuf};

fn main() {
let home = env::var("HOME").expect("Error getting HOME env.");

let mut crescent_dir = PathBuf::from(home);
// This build file creates the ~/.crescent/profiles directories and
// copies the default profiles in ./profiles to ~/.crescent/profiles.
fn main() -> Result<()> {
let home_dir = match env::var("HOME") {
Ok(dir) => dir,
Err(err) => return Err(anyhow!("Error retrieving HOME directory: {err}")),
};

let mut crescent_dir = PathBuf::from(home_dir);
crescent_dir.push(".crescent/profiles");

if !crescent_dir.exists() {
fs::create_dir_all(&crescent_dir).expect("Error creating crescent and profiles directory.");
if let Err(err) = fs::create_dir_all(&crescent_dir) {
return Err(anyhow!(
"Error creating crescent and profiles directory: {err}"
));
}
}

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

let base_profiles = base_profiles_dir
.read_dir()
.expect("Error reading base profiles directory.")
.flatten();
let default_profiles_dir = PathBuf::from("./profiles");
let default_profiles = match default_profiles_dir.read_dir() {
Ok(dir) => dir.flatten(),
Err(err) => return Err(anyhow!("Error reading default profiles directory: {err}")),
};

'base_loop: for base_profile in base_profiles {
let user_profiles = crescent_dir
.read_dir()
.expect("Error reading user profiles directory.")
.flatten();
'base_loop: for default_profile in default_profiles {
let user_profiles = match crescent_dir.read_dir() {
Ok(dir) => dir.flatten(),
Err(err) => return Err(anyhow!("Error reading default user directory: {err}")),
};

for user_profile in user_profiles {
if user_profile.file_name() == base_profile.file_name() {
if user_profile.file_name() == default_profile.file_name() {
continue 'base_loop;
}
}

fs::copy(
base_profile.path(),
crescent_dir.join(base_profile.file_name()),
)
.expect("Error copying profile.");
if let Err(err) = fs::copy(
default_profile.path(),
crescent_dir.join(default_profile.file_name()),
) {
return Err(anyhow!("Error copying profile: {err}"));
}
}

Ok(())
}
3 changes: 3 additions & 0 deletions tests/long_running.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ fn stop_long_running_service() -> Result<()> {
cmd.args(["start", "-n", name, "-p", "example"]);
cmd.assert().success();

// Sleeping to make sure the process started
thread::sleep(std::time::Duration::from_secs(1));

assert!(test_utils::check_app_is_running(name)?);

let mut cmd = test_utils::get_base_command();
Expand Down

0 comments on commit b9aeb7b

Please sign in to comment.