Skip to content

Commit

Permalink
feat: add nat detection binary to release type
Browse files Browse the repository at this point in the history
  • Loading branch information
RolandSherwin authored and jacderida committed May 23, 2024
1 parent 493ca2d commit eb0dc67
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use zip::ZipArchive;

const GITHUB_API_URL: &str = "https://api.github.com";
const FAUCET_S3_BASE_URL: &str = "https://sn-faucet.s3.eu-west-2.amazonaws.com";
const NAT_DETECTION_S3_BASE_URL: &str = "https://nat-detection.s3.eu-west-2.amazonaws.com";
const NODE_LAUNCHPAD_S3_BASE_URL: &str = "https://node-launchpad.s3.eu-west-2.amazonaws.com";
const SAFE_S3_BASE_URL: &str = "https://sn-cli.s3.eu-west-2.amazonaws.com";
const SAFENODE_S3_BASE_URL: &str = "https://sn-node.s3.eu-west-2.amazonaws.com";
Expand All @@ -37,6 +38,7 @@ const SN_AUDITOR_S3_BASE_URL: &str = "https://sn-auditor.s3.eu-west-2.amazonaws.
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum ReleaseType {
Faucet,
NatDetection,
NodeLaunchpad,
Safe,
Safenode,
Expand All @@ -53,6 +55,7 @@ impl fmt::Display for ReleaseType {
"{}",
match self {
ReleaseType::Faucet => "faucet",
ReleaseType::NatDetection => "nat-detection",
ReleaseType::NodeLaunchpad => "node-launchpad",
ReleaseType::Safe => "safe",
ReleaseType::Safenode => "safenode",
Expand All @@ -69,6 +72,7 @@ lazy_static! {
static ref RELEASE_TYPE_CRATE_NAME_MAP: HashMap<ReleaseType, &'static str> = {
let mut m = HashMap::new();
m.insert(ReleaseType::Faucet, "sn_faucet");
m.insert(ReleaseType::NatDetection, "sn_nat_detection");
m.insert(ReleaseType::NodeLaunchpad, "node-launchpad");
m.insert(ReleaseType::Safe, "sn_cli");
m.insert(ReleaseType::Safenode, "sn_node");
Expand Down Expand Up @@ -147,6 +151,7 @@ impl dyn SafeReleaseRepoActions {
pub fn default_config() -> Box<dyn SafeReleaseRepoActions> {
Box::new(SafeReleaseRepository {
github_api_base_url: GITHUB_API_URL.to_string(),
nat_detection_base_url: NAT_DETECTION_S3_BASE_URL.to_string(),
faucet_base_url: FAUCET_S3_BASE_URL.to_string(),
node_launchpad_base_url: NODE_LAUNCHPAD_S3_BASE_URL.to_string(),
safe_base_url: SAFE_S3_BASE_URL.to_string(),
Expand All @@ -161,6 +166,7 @@ impl dyn SafeReleaseRepoActions {
pub struct SafeReleaseRepository {
pub github_api_base_url: String,
pub faucet_base_url: String,
pub nat_detection_base_url: String,
pub node_launchpad_base_url: String,
pub safe_base_url: String,
pub safenode_base_url: String,
Expand All @@ -173,6 +179,7 @@ impl SafeReleaseRepository {
fn get_base_url(&self, release_type: &ReleaseType) -> String {
match release_type {
ReleaseType::Faucet => self.faucet_base_url.clone(),
ReleaseType::NatDetection => self.nat_detection_base_url.clone(),
ReleaseType::NodeLaunchpad => self.node_launchpad_base_url.clone(),
ReleaseType::Safe => self.safe_base_url.clone(),
ReleaseType::Safenode => self.safenode_base_url.clone(),
Expand Down
71 changes: 71 additions & 0 deletions tests/test_download_from_s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use semver::Version;
use sn_releases::{ArchiveType, Platform, ReleaseType, SafeReleaseRepoActions};

const FAUCET_VERSION: &str = "0.1.98";
const NAT_DETECTION_VERSION: &str = "0.1.0";
const NODE_LAUNCHPAD_VERSION: &str = "0.1.0";
const SAFE_VERSION: &str = "0.83.51";
const SAFENODE_VERSION: &str = "0.93.7";
Expand Down Expand Up @@ -53,6 +54,7 @@ async fn download_and_extract(

let binary_name = match release_type {
ReleaseType::Faucet => "faucet",
ReleaseType::NatDetection => "nat-detection",
ReleaseType::NodeLaunchpad => "node-launchpad",
ReleaseType::Safe => "safe",
ReleaseType::Safenode => "safenode",
Expand Down Expand Up @@ -623,3 +625,72 @@ async fn should_download_and_extract_sn_auditor_for_windows() {
)
.await;
}

///
/// NAT Detection Test
///
#[tokio::test]
async fn should_download_and_extract_nat_detection_for_linux_musl() {
download_and_extract(
&ReleaseType::NatDetection,
NAT_DETECTION_VERSION,
&Platform::LinuxMusl,
&ArchiveType::TarGz,
)
.await;
}

#[tokio::test]
async fn should_download_and_extract_nat_detection_for_linux_musl_aarch64() {
download_and_extract(
&ReleaseType::NatDetection,
NAT_DETECTION_VERSION,
&Platform::LinuxMuslAarch64,
&ArchiveType::TarGz,
)
.await;
}

#[tokio::test]
async fn should_download_and_extract_nat_detection_for_linux_musl_arm() {
download_and_extract(
&ReleaseType::NatDetection,
NAT_DETECTION_VERSION,
&Platform::LinuxMuslArm,
&ArchiveType::TarGz,
)
.await;
}

#[tokio::test]
async fn should_download_and_extract_nat_detection_for_linux_musl_arm_v7() {
download_and_extract(
&ReleaseType::NatDetection,
NAT_DETECTION_VERSION,
&Platform::LinuxMuslArmV7,
&ArchiveType::TarGz,
)
.await;
}

#[tokio::test]
async fn should_download_and_extract_nat_detection_for_macos() {
download_and_extract(
&ReleaseType::NatDetection,
NAT_DETECTION_VERSION,
&Platform::MacOs,
&ArchiveType::TarGz,
)
.await;
}

#[tokio::test]
async fn should_download_and_extract_nat_detection_for_windows() {
download_and_extract(
&ReleaseType::NatDetection,
NAT_DETECTION_VERSION,
&Platform::Windows,
&ArchiveType::Zip,
)
.await;
}

0 comments on commit eb0dc67

Please sign in to comment.