Skip to content

Commit

Permalink
test: improve runtime test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
brianheineman committed Jul 27, 2024
1 parent 0752816 commit 2ffda72
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ indoc = "2.0.5"
reqwest = "0.12.5"
tar = "0.4.41"
thiserror = "1.0.63"
tokio = "1.39.1"
tokio = "1.39.2"
zip = "2.1.5"

[workspace.metadata.release]
Expand Down
1 change: 1 addition & 0 deletions ristretto_classfile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ byteorder = { workspace = true }
thiserror = { workspace = true }

[dev-dependencies]
anyhow = { workspace = true }
criterion = { workspace = true }
flate2 = { workspace = true }
indoc = { workspace = true }
Expand Down
18 changes: 9 additions & 9 deletions ristretto_classfile/tests/java8_runtime_test.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
mod utilities;

use anyhow::{anyhow, Result};
use flate2::read::GzDecoder;
use reqwest::Client;
use std::error::Error;
use std::io::Read;
use tar::Archive;

#[tokio::test]
async fn verify() -> Result<(), Box<dyn Error>> {
async fn verify() -> Result<()> {
let url = "https://corretto.aws/downloads/latest/amazon-corretto-8-x64-linux-jdk.tar.gz";
let client = Client::new();
let archive = client.get(url).send().await?.bytes().await?.to_vec();
Expand All @@ -18,21 +18,21 @@ async fn verify() -> Result<(), Box<dyn Error>> {
Ok(())
}

fn get_runtime_jar(archive: Vec<u8>) -> Result<Vec<u8>, Box<dyn Error>> {
fn get_runtime_jar(archive: Vec<u8>) -> Result<Vec<u8>> {
let tar = GzDecoder::new(&*archive);
let mut archive = Archive::new(tar);
let file_name = "rt.jar";
let mut runtime_jar: Result<Vec<u8>> = Err(anyhow!("{file_name} not found in the archive"));

for file in archive.entries()? {
let mut file = file?;
if file.path()?.ends_with("rt.jar") {
if file.path()?.ends_with(file_name) {
let mut jar_bytes = Vec::new();
file.read_to_end(&mut jar_bytes)?;
return Ok(jar_bytes);
runtime_jar = Ok(jar_bytes);
break;
}
}

Err(Box::new(std::io::Error::new(
std::io::ErrorKind::NotFound,
"rt.jar not found in the archive",
)))
runtime_jar
}

0 comments on commit 2ffda72

Please sign in to comment.