Skip to content

Commit

Permalink
Add tests for skootrs
Browse files Browse the repository at this point in the history
This is an initial set of tests for the core functionality of
skootrs. There is more to be done, especially in making sure these
tests can run inside of github actions that might not have go,
maven, etc.
  • Loading branch information
mlieberman85 committed Mar 2, 2024
1 parent a57692d commit b4d1a6c
Show file tree
Hide file tree
Showing 8 changed files with 581 additions and 54 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/target/
.vscode
.DS_Store
state.db
state.db
.envrc
96 changes: 80 additions & 16 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
rustup
bunyan-rs
go
maven
];
RUSTC_VERSION = pkgs.lib.readFile ./rust-toolchain;
# https://github.com/rust-lang/rust-bindgen#environment-variables
Expand Down
4 changes: 4 additions & 0 deletions skootrs-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ tracing = "0.1"
futures = "0.3.30"
skootrs-model = { path = "../skootrs-model" }
ahash = "0.8.7"

[dev-dependencies]
tempdir = "0.3.7"
tokio = { version = "1.36.0", features = ["rt", "macros"] }
64 changes: 64 additions & 0 deletions skootrs-lib/src/service/ecosystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,67 @@ impl LocalGoEcosystemHandler {
}
}
}

#[cfg(test)]
mod tests {
use super::*;
use tempdir::TempDir;

#[test]
fn test_local_maven_ecosystem_handler_initialize_success() {
let temp_dir = TempDir::new("test").unwrap();
let path = temp_dir.path().to_str().unwrap();
let params = MavenParams {
group_id: "com.example".to_string(),
artifact_id: "my-project".to_string(),
};

let result = LocalMavenEcosystemHandler::initialize(path, &params);

assert!(result.is_ok());
}

#[test]
fn test_local_maven_ecosystem_handler_initialize_failure() {
let temp_dir = TempDir::new("test").unwrap();
let path = temp_dir.path().to_str().unwrap();
let params = MavenParams {
// Invalid group ID
group_id: "".to_string(),
artifact_id: "my-project".to_string(),
};

let result = LocalMavenEcosystemHandler::initialize(path, &params);

assert!(result.is_err());
}

#[test]
fn test_local_go_ecosystem_handler_initialize_success() {
let temp_dir = TempDir::new("test").unwrap();
let path = temp_dir.path().to_str().unwrap();
let params = GoParams {
name: "my-project".to_string(),
host: "github.com".to_string(),
};

let result = LocalGoEcosystemHandler::initialize(path, &params);

assert!(result.is_ok());
}

#[test]
fn test_local_go_ecosystem_handler_initialize_failure() {
let temp_dir = TempDir::new("test").unwrap();
let path = temp_dir.path().to_str().unwrap();
let params = GoParams {
// Invalid project name
name: "".to_string(),
host: "github.com".to_string(),
};

let result = LocalGoEcosystemHandler::initialize(path, &params);

assert!(result.is_err());
}
}
Loading

0 comments on commit b4d1a6c

Please sign in to comment.