Skip to content

Commit

Permalink
bootstrap ci tests (#56)
Browse files Browse the repository at this point in the history
* Handle errors for download_file

* bootstrap a test

* Add tempfile dev dependency

* Add cargo test job

* Revert "Handle errors for download_file"

This reverts commit 6a3ae36.

* newline
  • Loading branch information
bing authored Jun 6, 2022
1 parent 5f6ed4e commit bfde98a
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ jobs:
command: fmt
args: --all -- --check

cargo-test:
needs: cancel-previous-runs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- name: Run tests
uses: actions-rs/cargo@v1
with:
command: test
args: --locked

lint-toml-files:
needs: cancel-previous-runs
runs-on: ubuntu-latest
Expand Down
42 changes: 42 additions & 0 deletions 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 @@ -28,3 +28,6 @@ tar = "0.4"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["ansi", "env-filter", "json"] }
ureq = "2.4"

[dev-dependencies]
tempfile = "3"
31 changes: 31 additions & 0 deletions src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,34 @@ pub fn unpack_extracted_bins(dir: &std::path::PathBuf) -> Result<()> {

Ok(())
}

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

#[test]
fn test_unpack_extracted_bins() {
let fuelup_bin_dir = tempfile::Builder::new()
.prefix("mock-fuelup-bin")
.tempdir()
.unwrap();
let mock_bin_dir = fuelup_bin_dir.path().join("forc-mock");
let mock_bin_file_1 = mock_bin_dir.join("forc-mock-exec-1");
let mock_bin_file_2 = mock_bin_dir.join("forc-mock-exec-2");

fs::create_dir(&mock_bin_dir).unwrap();
fs::File::create(mock_bin_file_1).unwrap();
fs::File::create(mock_bin_file_2).unwrap();

assert!(mock_bin_dir.exists());
assert!(!fuelup_bin_dir.path().join("forc-mock-exec-1").exists());
assert!(!fuelup_bin_dir.path().join("forc-mock-exec-2").exists());

unpack_extracted_bins(&fuelup_bin_dir.path().to_path_buf()).unwrap();

assert!(!mock_bin_dir.exists());
assert!(fuelup_bin_dir.path().join("forc-mock-exec-1").exists());
assert!(fuelup_bin_dir.path().join("forc-mock-exec-2").exists());
}
}

0 comments on commit bfde98a

Please sign in to comment.