Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
schneems committed May 28, 2024
1 parent 655530b commit 7a3647a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
Binary file added docker_tools/fixtures/ruby-source-3.3.1.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion docker_tools/src/bin/make_ruby.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn make_ruby(args: Args) -> Result<(), RubyMakeError> {
let source_dir = tempdir.path().join("source");
let compiled_dir = tempdir.path().join("compiled");

let download_tar_path = TarPath(cache.join(version.tar_filename()));
let download_tar_path = TarPath(cache.join(format!("ruby-source-{version}.tgz")));

let output_tar_file = {
let out_tar_path = output_tar_path(&output, &version, &base_image, &CpuArch::new());
Expand Down
57 changes: 41 additions & 16 deletions docker_tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,6 @@ impl RubyDownloadVersion {
format!("ruby-{}", self)
}

pub fn tar_filename(&self) -> String {
format!("ruby-{self}.tgz")
}

pub fn download_url(&self) -> String {
format!(
"https://cache.ruby-lang.org/pub/ruby/{major}.{minor}/ruby-{self}.tar.gz",
Expand Down Expand Up @@ -448,18 +444,11 @@ mod test {
}

#[test]
fn test_ruby_tar_filename() {
assert_eq!(
"ruby-3.1.2.tgz".to_string(),
RubyDownloadVersion::new("3.1.2").unwrap().tar_filename()
);

assert_eq!(
"ruby-3.1.2-preview1.tgz".to_string(),
RubyDownloadVersion::new("3.1.2-preview1")
.unwrap()
.tar_filename()
);
fn bad_ruby_version() {
assert!(RubyDownloadVersion::new("3.-1.2-preview1").is_err());
assert!(RubyDownloadVersion::new("3.1").is_err());
assert!(RubyDownloadVersion::new("3").is_err());
assert!(RubyDownloadVersion::new("3-1").is_err());
}

#[test]
Expand All @@ -481,4 +470,40 @@ mod test {
.download_url()
);
}

#[test]
fn test_untar_to_dir() {
let tempdir = tempfile::tempdir().unwrap();
let tar_path = TarPath(
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("fixtures")
.join("ruby-source-3.3.1.tar.gz"),
);
untar_to_dir(&tar_path, tempdir.path()).unwrap();

assert_eq!(
vec!["ruby-3.3.1".to_string()],
filenames_in_path(tempdir.path())
);

let filenames = filenames_in_path(&tempdir.path().join("ruby-3.3.1"));
assert_eq!(filenames.len(), 274);
assert!(filenames.iter().any(|name| name == "ruby.c"));
}

fn filenames_in_path(path: &Path) -> Vec<String> {
let mut filenames = fs_err::read_dir(path)
.unwrap()
.filter_map(|entry| {
entry.ok().and_then(|e| {
e.path()
.file_name()
.and_then(|n| n.to_str().map(String::from))
})
})
.collect::<Vec<String>>();

filenames.sort();
filenames
}
}

0 comments on commit 7a3647a

Please sign in to comment.