Skip to content

Commit

Permalink
Adds some E2E tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ubiratansoares committed Apr 21, 2024
1 parent 109feac commit 9069e69
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 14 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: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.11GiB"* ]]
[ "$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.12MiB"* ]]
[ "$status" -eq 0 ]
}
7 changes: 7 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,10 @@ msrv-check:
@echo "→ Checking minimum supported Rust version (MSRV)"
cargo msrv verify
@echo

# Running E2E tests
e2e:
@echo "→ Running E2E tests"
docker build . -t dotanuki-labs/gradle-wiper-tests -f e2e/Dockerfile
docker run dotanuki-labs/gradle-wiper-tests
@echo
26 changes: 16 additions & 10 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ impl Cli {

let allocated = &outcome.resources;

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

if allocated.is_empty() {
println!("No usages of {} related to Gradle builds were found", what);
println!();
return;
Expand All @@ -91,22 +91,28 @@ 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 ({what}) : {}", &outcome.total_size.to_string());
println!();
}

fn report_cleanup(&self, outcome: &WipingOutcome) {
fn report_cleanup(&self, resource: &MachineResource, outcome: &WipingOutcome) {
let what = match resource {
MachineResource::RamMemory => "RAM memory",
MachineResource::DiskSpace => "disk space",
};

println!();
println!("Reclaimed {}", outcome.reclaimed);
println!("Reclaimed {what} : {}", 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

0 comments on commit 9069e69

Please sign in to comment.