Skip to content

Commit

Permalink
feat: support sn_node_rpc_client release type
Browse files Browse the repository at this point in the history
The new binary is added to the available release types.

The addition of this binary also caused the incorrect latest version to be returned for `sn_node`
because it was doing a starts-with match. The match was changed to compare the whole crate name.
  • Loading branch information
jacderida authored and joshuef committed Nov 24, 2023
1 parent fc5c35a commit e0b7b72
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@ const GITHUB_ORG_NAME: &str = "maidsafe";
const GITHUB_REPO_NAME: &str = "safe_network";
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";
const SAFENODE_RPC_CLIENT_S3_BASE_URL: &str =
"https://sn-node-rpc-client.s3.eu-west-2.amazonaws.com";
const TESTNET_S3_BASE_URL: &str = "https://sn-testnet.s3.eu-west-2.amazonaws.com";

#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum ReleaseType {
Safe,
Safenode,
SafenodeRpcClient,
Testnet,
}

Expand All @@ -46,6 +49,7 @@ impl fmt::Display for ReleaseType {
match self {
ReleaseType::Safe => "safe",
ReleaseType::Safenode => "safenode",
ReleaseType::SafenodeRpcClient => "safenode_rpc_client",
ReleaseType::Testnet => "testnet",
}
)
Expand All @@ -57,6 +61,7 @@ lazy_static! {
let mut m = HashMap::new();
m.insert(ReleaseType::Safe, "sn_cli");
m.insert(ReleaseType::Safenode, "sn_node");
m.insert(ReleaseType::SafenodeRpcClient, "sn_node_rpc_client");
m.insert(ReleaseType::Testnet, "sn_testnet");
m
};
Expand Down Expand Up @@ -124,6 +129,7 @@ impl dyn SafeReleaseRepositoryInterface {
github_api_base_url: GITHUB_API_URL.to_string(),
safe_base_url: SAFE_S3_BASE_URL.to_string(),
safenode_base_url: SAFENODE_S3_BASE_URL.to_string(),
safenode_rpc_client_base_url: SAFENODE_RPC_CLIENT_S3_BASE_URL.to_string(),
testnet_base_url: TESTNET_S3_BASE_URL.to_string(),
})
}
Expand All @@ -133,6 +139,7 @@ pub struct SafeReleaseRepository {
pub github_api_base_url: String,
pub safe_base_url: String,
pub safenode_base_url: String,
pub safenode_rpc_client_base_url: String,
pub testnet_base_url: String,
}

Expand All @@ -141,6 +148,7 @@ impl SafeReleaseRepository {
match release_type {
ReleaseType::Safe => self.safe_base_url.clone(),
ReleaseType::Safenode => self.safenode_base_url.clone(),
ReleaseType::SafenodeRpcClient => self.safenode_rpc_client_base_url.clone(),
ReleaseType::Testnet => self.testnet_base_url.clone(),
}
}
Expand Down Expand Up @@ -226,7 +234,8 @@ impl SafeReleaseRepositoryInterface for SafeReleaseRepository {
(release.get("tag_name"), release.get("created_at"))
{
let created_at = created_at.parse::<DateTime<Utc>>()?;
if tag_name.starts_with(target_tag_name) {
let crate_name = tag_name.split('-').next().unwrap().to_string();
if crate_name == target_tag_name {
match latest_release {
Some((_, date)) if created_at > date => {
latest_release = Some((tag_name.clone(), created_at));
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 @@ -13,6 +13,7 @@ use sn_releases::{ArchiveType, Platform, ReleaseType, SafeReleaseRepositoryInter

const SAFE_VERSION: &str = "0.83.51";
const SAFENODE_VERSION: &str = "0.93.7";
const SAFENODE_RPC_CLIENT_VERSION: &str = "0.1.40";
const TESTNET_VERSION: &str = "0.2.213";

async fn download_and_extract(
Expand Down Expand Up @@ -49,6 +50,7 @@ async fn download_and_extract(
let binary_name = match release_type {
ReleaseType::Safe => "safe",
ReleaseType::Safenode => "safenode",
ReleaseType::SafenodeRpcClient => "safenode_rpc_client",
ReleaseType::Testnet => "testnet",
};
let expected_binary_name = if *platform == Platform::Windows {
Expand Down Expand Up @@ -301,3 +303,72 @@ async fn should_download_and_extract_testnet_for_windows() {
)
.await;
}

///
/// Safenode RPC client tests
///
#[tokio::test]
async fn should_download_and_extract_safenode_rpc_client_for_linux_musl() {
download_and_extract(
&ReleaseType::SafenodeRpcClient,
SAFENODE_RPC_CLIENT_VERSION,
&Platform::LinuxMusl,
&ArchiveType::TarGz,
)
.await;
}

#[tokio::test]
async fn should_download_and_extract_safenode_rpc_client_for_linux_musl_aarch64() {
download_and_extract(
&ReleaseType::SafenodeRpcClient,
SAFENODE_RPC_CLIENT_VERSION,
&Platform::LinuxMuslAarch64,
&ArchiveType::TarGz,
)
.await;
}

#[tokio::test]
async fn should_download_and_extract_safenode_rpc_client_for_linux_musl_arm() {
download_and_extract(
&ReleaseType::SafenodeRpcClient,
SAFENODE_RPC_CLIENT_VERSION,
&Platform::LinuxMuslArm,
&ArchiveType::TarGz,
)
.await;
}

#[tokio::test]
async fn should_download_and_extract_safenode_rpc_client_for_linux_musl_arm_v7() {
download_and_extract(
&ReleaseType::SafenodeRpcClient,
SAFENODE_RPC_CLIENT_VERSION,
&Platform::LinuxMuslArmV7,
&ArchiveType::TarGz,
)
.await;
}

#[tokio::test]
async fn should_download_and_extract_safenode_rpc_client_for_macos() {
download_and_extract(
&ReleaseType::SafenodeRpcClient,
SAFENODE_RPC_CLIENT_VERSION,
&Platform::MacOs,
&ArchiveType::TarGz,
)
.await;
}

#[tokio::test]
async fn should_download_and_extract_safenode_rpc_client_for_windows() {
download_and_extract(
&ReleaseType::SafenodeRpcClient,
SAFENODE_RPC_CLIENT_VERSION,
&Platform::Windows,
&ArchiveType::Zip,
)
.await;
}
11 changes: 11 additions & 0 deletions tests/test_get_latest_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ async fn should_get_latest_version_of_safenode() {
assert!(valid_semver_format(&version));
}

#[tokio::test]
async fn should_get_latest_version_of_safenode_rpc_client() {
let release_type = ReleaseType::SafenodeRpcClient;
let release_repo = <dyn SafeReleaseRepositoryInterface>::default_config();
let version = release_repo
.get_latest_version(&release_type)
.await
.unwrap();
assert!(valid_semver_format(&version));
}

#[tokio::test]
async fn should_get_latest_version_of_testnet() {
let release_type = ReleaseType::Testnet;
Expand Down

0 comments on commit e0b7b72

Please sign in to comment.