Skip to content

Commit

Permalink
Merge pull request #7 from busticated/feature/fetch-all-supported-con…
Browse files Browse the repository at this point in the history
…figurations

feature/fetch-all-supported-configurations
  • Loading branch information
busticated authored Oct 22, 2023
2 parents 0cfb362 + 9fc47f0 commit 8d77010
Show file tree
Hide file tree
Showing 7 changed files with 537 additions and 94 deletions.
7 changes: 7 additions & 0 deletions crates/node-js-release-info/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,18 @@ use node_js_release_info::{NodeJSRelInfo, NodeJSRelInfoError};

#[tokio::main]
async fn main() -> Result<(), NodeJSRelInfoError> {
// get a specific configuration
let info = NodeJSRelInfo::new("20.6.1").macos().arm64().fetch().await?;
assert_eq!(info.version, "20.6.1");
assert_eq!(info.filename, "node-v20.6.1-darwin-arm64.tar.gz");
assert_eq!(info.sha256, "d8ba8018d45b294429b1a7646ccbeaeb2af3cdf45b5c91dabbd93e2a2035cb46");
assert_eq!(info.url, "https://nodejs.org/download/release/v20.6.1/node-v20.6.1-darwin-arm64.tar.gz");

// get all supported configurations
let all = info.fetch_all().await?;
assert_eq!(all.len(), 24);
assert_eq!(all[2], info);
println!("{:?}", all);
Ok(())
}
```
Expand Down
30 changes: 27 additions & 3 deletions crates/node-js-release-info/src/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ pub enum NodeJSArch {
ARM64,
#[cfg_attr(feature = "json", serde(rename = "armv7l"))]
ARMV7L,
#[cfg_attr(feature = "json", serde(rename = "ppc64"))]
PPC64,
#[cfg_attr(feature = "json", serde(rename = "ppc64le"))]
PPC64LE,
#[cfg_attr(feature = "json", serde(rename = "s390x"))]
S390X,
}

impl Default for NodeJSArch {
Expand All @@ -43,7 +47,9 @@ impl Display for NodeJSArch {
NodeJSArch::X86 => "x86",
NodeJSArch::ARM64 => "arm64",
NodeJSArch::ARMV7L => "armv7l",
NodeJSArch::PPC64 => "ppc64",
NodeJSArch::PPC64LE => "ppc64le",
NodeJSArch::S390X => "s390x",
};

write!(f, "{}", arch)
Expand All @@ -58,8 +64,10 @@ impl FromStr for NodeJSArch {
"x64" | "x86_64" => Ok(NodeJSArch::X64),
"x86" => Ok(NodeJSArch::X86),
"arm64" | "aarch64" => Ok(NodeJSArch::ARM64),
"arm" => Ok(NodeJSArch::ARMV7L),
"ppc64le" | "powerpc64" => Ok(NodeJSArch::PPC64LE),
"arm" | "armv7l" => Ok(NodeJSArch::ARMV7L),
"ppc64" | "powerpc64" => Ok(NodeJSArch::PPC64),
"ppc64le" => Ok(NodeJSArch::PPC64LE),
"s390x" => Ok(NodeJSArch::S390X),
_ => Err(NodeJSRelInfoError::UnrecognizedArch(s.to_string())),
}
}
Expand Down Expand Up @@ -107,13 +115,21 @@ mod tests {

assert_eq!(arch, NodeJSArch::ARMV7L);

let arch = NodeJSArch::from_str("ppc64").unwrap();

assert_eq!(arch, NodeJSArch::PPC64);

let arch = NodeJSArch::from_str("ppc64le").unwrap();

assert_eq!(arch, NodeJSArch::PPC64LE);

let arch = NodeJSArch::from_str("powerpc64").unwrap();

assert_eq!(arch, NodeJSArch::PPC64LE);
assert_eq!(arch, NodeJSArch::PPC64);

let arch = NodeJSArch::from_str("s390x").unwrap();

assert_eq!(arch, NodeJSArch::S390X);
}

#[test]
Expand All @@ -134,9 +150,17 @@ mod tests {

assert_eq!(text, "armv7l");

let text = format!("{}", NodeJSArch::PPC64);

assert_eq!(text, "ppc64");

let text = format!("{}", NodeJSArch::PPC64LE);

assert_eq!(text, "ppc64le");

let text = format!("{}", NodeJSArch::S390X);

assert_eq!(text, "s390x");
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions crates/node-js-release-info/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ mod tests {
}

async fn fake_http_error() -> std::result::Result<(), NodeJSRelInfoError> {
reqwest::get("not-a-url").await?;
Ok(())
let error = reqwest::get("not-a-url").await.unwrap_err();
Err(NodeJSRelInfoError::from(error))
}
}
12 changes: 12 additions & 0 deletions crates/node-js-release-info/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ pub enum NodeJSPkgExt {
Zip,
#[cfg_attr(feature = "json", serde(rename = "msi"))]
Msi,
#[cfg_attr(feature = "json", serde(rename = "7z"))]
S7z, // can't start w/ a number (X_x)
}

impl Default for NodeJSPkgExt {
Expand All @@ -35,6 +37,7 @@ impl Display for NodeJSPkgExt {
NodeJSPkgExt::Tarxz => "tar.xz",
NodeJSPkgExt::Zip => "zip",
NodeJSPkgExt::Msi => "msi",
NodeJSPkgExt::S7z => "7z",
};

write!(f, "{}", arch)
Expand All @@ -50,6 +53,7 @@ impl FromStr for NodeJSPkgExt {
"tar.xz" => Ok(NodeJSPkgExt::Tarxz),
"zip" => Ok(NodeJSPkgExt::Zip),
"msi" => Ok(NodeJSPkgExt::Msi),
"7z" => Ok(NodeJSPkgExt::S7z),
_ => Err(NodeJSRelInfoError::UnrecognizedExt(s.to_string())),
}
}
Expand Down Expand Up @@ -88,6 +92,10 @@ mod tests {
let ext = NodeJSPkgExt::from_str("msi").unwrap();

assert_eq!(ext, NodeJSPkgExt::Msi);

let ext = NodeJSPkgExt::from_str("7z").unwrap();

assert_eq!(ext, NodeJSPkgExt::S7z);
}

#[test]
Expand All @@ -107,6 +115,10 @@ mod tests {
let text = format!("{}", NodeJSPkgExt::Msi);

assert_eq!(text, "msi");

let text = format!("{}", NodeJSPkgExt::S7z);

assert_eq!(text, "7z");
}

#[test]
Expand Down
Loading

0 comments on commit 8d77010

Please sign in to comment.