-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: function for downloading custom url
In the node manager we want to support downloading a 'custom' binary, which is really a binary of `safenode` from someone's fork. These get uploaded and used during testnet deployments. This new function downloads the URL not on the basis of a convention, but instead just allowing any URL to be specified. We make the assertion that the URL has to point to a zip or gzipped tar file.
- Loading branch information
Showing
3 changed files
with
120 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright (C) 2023 MaidSafe.net limited. | ||
// | ||
// This SAFE Network Software is licensed to you under The General Public License (GPL), version 3. | ||
// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed | ||
// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. Please review the Licences for the specific language governing | ||
// permissions and limitations relating to use of the SAFE Network Software. | ||
|
||
use assert_fs::prelude::*; | ||
use sn_releases::error::Error; | ||
use sn_releases::SafeReleaseRepositoryInterface; | ||
|
||
#[tokio::test] | ||
async fn should_download_a_custom_binary() { | ||
let dest_dir = assert_fs::TempDir::new().unwrap(); | ||
let download_dir = dest_dir.child("download_to"); | ||
download_dir.create_dir_all().unwrap(); | ||
let downloaded_archive = | ||
download_dir.child("safenode-charlie-x86_64-unknown-linux-musl.tar.gz"); | ||
|
||
let url = "https://sn-node.s3.eu-west-2.amazonaws.com/jacderida/file-upload-address/safenode-charlie-x86_64-unknown-linux-musl.tar.gz"; | ||
let progress_callback = |_downloaded: u64, _total: u64| {}; | ||
let release_repo = <dyn SafeReleaseRepositoryInterface>::default_config(); | ||
release_repo | ||
.download_release(url, &download_dir, &progress_callback) | ||
.await | ||
.unwrap(); | ||
|
||
downloaded_archive.assert(predicates::path::is_file()); | ||
} | ||
|
||
#[tokio::test] | ||
async fn should_fail_to_download_non_archive() { | ||
let dest_dir = assert_fs::TempDir::new().unwrap(); | ||
let download_dir = dest_dir.child("download_to"); | ||
download_dir.create_dir_all().unwrap(); | ||
|
||
let url = "https://sn-node.s3.eu-west-2.amazonaws.com/jacderida/file-upload-address/safenode-charlie-x86_64-unknown-linux-musl.txt"; | ||
let progress_callback = |_downloaded: u64, _total: u64| {}; | ||
let release_repo = <dyn SafeReleaseRepositoryInterface>::default_config(); | ||
let result = release_repo | ||
.download_release(url, &download_dir, &progress_callback) | ||
.await; | ||
|
||
match result { | ||
Ok(_) => panic!("This test should result in a failure"), | ||
Err(e) => match e { | ||
Error::UrlIsNotArchive => { | ||
assert_eq!( | ||
e.to_string(), | ||
"The URL must point to a zip or gzipped tar archive" | ||
); | ||
} | ||
_ => panic!("The error type should be ReleaseBinaryNotFound"), | ||
}, | ||
} | ||
} |