Skip to content

Commit

Permalink
Adds some E2E tests (#30)
Browse files Browse the repository at this point in the history
* Adds some E2E tests

* Fix formatting

* Implements Display for another model
  • Loading branch information
ubiratansoares authored Apr 22, 2024
1 parent 109feac commit 4d59db4
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 15 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,21 @@ jobs:
- name: Check code smells
run: just lint

- name: Run tests
run: just tests

- name: Check supply-chain issues
run: just supply-chain-checks

- name: Check MSRV
run: just msrv-check

- name: Build against supported targets
- name: Cross-compilation against some targets
run: just cross-build-pull-request

- name: Run unit tests
run: just tests

- name: Run E2E tests
run: just e2e

- name: Archive SBOM
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
Expand Down
12 changes: 12 additions & 0 deletions e2e/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM azul/zulu-openjdk:21-latest

RUN apt-get update && apt-get install -y git openssh-client bats
RUN cd $HOME && mkdir -p $HOME/.ssh
RUN ssh-keyscan -t rsa github.com >> $HOME/.ssh/known_hosts
RUN git clone https://github.com/dotanuki-labs/android-archives-watchdog.git aaw

COPY e2e/e2e.bats /usr/e2e.bats
COPY target/release/gradle-wiper /usr/bin/gradle-wiper
RUN chmod +x /usr/bin/gradle-wiper

CMD ["bats", "/usr/e2e.bats"]
21 changes: 21 additions & 0 deletions e2e/e2e.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bats

current_dir="$(cd "$(dirname "$BATS_TEST_FILENAME")" >/dev/null 2>&1 && pwd)"

@test "should detect usages of disk" {
run aaw/gradlew tasks -q -p aaw
run gradle-wiper disk evaluate

echo "$output"
[[ "$output" == *"Total resources (disk space) : 1.1GiB"* ]]
[ "$status" -eq 0 ]
}

@test "should perform disk shallow wiping" {
run aaw/gradlew shadowJar -q -p aaw
run gradle-wiper disk evaluate
run gradle-wiper disk shallow

[[ "$output" == *"Reclaimed disk space : 642.1MiB"* ]]
[ "$status" -eq 0 ]
}
11 changes: 11 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,14 @@ msrv-check:
@echo "→ Checking minimum supported Rust version (MSRV)"
cargo msrv verify
@echo

# Running E2E tests
e2e:
@echo "→ Build release target"
cargo build --release
@echo

@echo "→ Running E2E tests"
docker build . -t dotanuki-labs/gradle-wiper-tests -f e2e/Dockerfile
docker run dotanuki-labs/gradle-wiper-tests
@echo
18 changes: 7 additions & 11 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,7 @@ impl Cli {
let allocated = &outcome.resources;

if allocated.is_empty() {
let what = match resource {
MachineResource::RamMemory => "RAM memory",
MachineResource::DiskSpace => "disk space",
};

println!("No usages of {} related to Gradle builds were found", what);
println!("No usages of {} related to Gradle builds were found", resource);
println!();
return;
}
Expand All @@ -91,22 +86,23 @@ impl Cli {
.set_header(vec!["What", "Total Size"])
.add_rows(rows);

table.add_row(vec!["Total", &outcome.total_size.to_string()]);

println!("{table}");

println!();
println!("Total resources ({}) : {:.1}", resource, &outcome.total_size);
println!();
}

fn report_cleanup(&self, outcome: &WipingOutcome) {
fn report_cleanup(&self, resource: &MachineResource, outcome: &WipingOutcome) {
println!();
println!("Reclaimed {}", outcome.reclaimed);
println!("Reclaimed {} : {:.1}", resource, outcome.reclaimed);
println!();
}

pub fn show_execution_outcome(&self, resource: &MachineResource, outcome: &ExecutionOutcome) -> anyhow::Result<()> {
match outcome {
ExecutionOutcome::Evaluation(evaluation) => self.report_resources(resource, evaluation),
ExecutionOutcome::Wiping(wipping) => self.report_cleanup(wipping),
ExecutionOutcome::Wiping(wipping) => self.report_cleanup(resource, wipping),
}

Ok(())
Expand Down
11 changes: 11 additions & 0 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ pub enum MachineResource {
DiskSpace,
}

impl Display for MachineResource {
fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
let formatted = match self {
MachineResource::RamMemory => "RAM memory",
MachineResource::DiskSpace => "disk space",
};

formatter.write_str(formatted)
}
}

#[derive(Debug)]
pub enum WipeAction {
Evaluate,
Expand Down

0 comments on commit 4d59db4

Please sign in to comment.