This repository has been archived by the owner on Jul 17, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add download tests. * Finish tests. * Actually run in CI. * Fix windows.
- Loading branch information
Showing
9 changed files
with
272 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,3 +46,4 @@ jobs: | |
with: | ||
bins: cargo-wasi, cargo-nextest | ||
- run: cargo wasi build -p bun_plugin | ||
- run: cargo nextest run |
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 |
---|---|---|
@@ -1,3 +1,8 @@ | ||
// WASM cannot be executed through the test runner and we need to avoid building | ||
// WASM code for non-WASM targets. We can solve both of these with a cfg flag. | ||
|
||
#[cfg(not(test))] | ||
mod proto; | ||
|
||
#[cfg(not(test))] | ||
pub use proto::*; |
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,181 @@ | ||
use proto_pdk::*; | ||
use proto_pdk_test_utils::{create_plugin, generate_download_install_tests}; | ||
use starbase_sandbox::create_empty_sandbox; | ||
use std::path::PathBuf; | ||
|
||
#[cfg(not(windows))] | ||
generate_download_install_tests!("bun-test", "0.6.0"); | ||
|
||
#[test] | ||
fn supports_linux_arm64() { | ||
let sandbox = create_empty_sandbox(); | ||
let plugin = create_plugin("bun-test", sandbox.path()); | ||
|
||
assert_eq!( | ||
plugin.download_prebuilt(DownloadPrebuiltInput { | ||
env: Environment { | ||
arch: HostArch::Arm64, | ||
os: HostOS::Linux, | ||
version: "1.2.0".into(), | ||
..Default::default() | ||
} | ||
}), | ||
DownloadPrebuiltOutput { | ||
archive_prefix: Some("bun-linux-aarch64".into()), | ||
bin_path: None, | ||
checksum_name: None, | ||
checksum_url: Some( | ||
"https://github.com/oven-sh/bun/releases/download/bun-v1.2.0/SHASUMS256.txt".into() | ||
), | ||
download_name: Some("bun-linux-aarch64.zip".into()), | ||
download_url: | ||
"https://github.com/oven-sh/bun/releases/download/bun-v1.2.0/bun-linux-aarch64.zip" | ||
.into() | ||
} | ||
); | ||
} | ||
|
||
#[test] | ||
fn supports_linux_x64() { | ||
let sandbox = create_empty_sandbox(); | ||
let plugin = create_plugin("bun-test", sandbox.path()); | ||
|
||
assert_eq!( | ||
plugin.download_prebuilt(DownloadPrebuiltInput { | ||
env: Environment { | ||
arch: HostArch::X64, | ||
os: HostOS::Linux, | ||
version: "1.2.0".into(), | ||
..Default::default() | ||
} | ||
}), | ||
DownloadPrebuiltOutput { | ||
archive_prefix: Some("bun-linux-x64".into()), | ||
bin_path: None, | ||
checksum_name: None, | ||
checksum_url: Some( | ||
"https://github.com/oven-sh/bun/releases/download/bun-v1.2.0/SHASUMS256.txt".into() | ||
), | ||
download_name: Some("bun-linux-x64.zip".into()), | ||
download_url: | ||
"https://github.com/oven-sh/bun/releases/download/bun-v1.2.0/bun-linux-x64.zip" | ||
.into() | ||
} | ||
); | ||
} | ||
|
||
#[test] | ||
fn supports_macos_arm64() { | ||
let sandbox = create_empty_sandbox(); | ||
let plugin = create_plugin("bun-test", sandbox.path()); | ||
|
||
assert_eq!( | ||
plugin.download_prebuilt(DownloadPrebuiltInput { | ||
env: Environment { | ||
arch: HostArch::Arm64, | ||
os: HostOS::MacOS, | ||
version: "1.2.0".into(), | ||
..Default::default() | ||
} | ||
}), | ||
DownloadPrebuiltOutput { | ||
archive_prefix: Some("bun-darwin-aarch64".into()), | ||
bin_path: None, | ||
checksum_name: None, | ||
checksum_url: Some( | ||
"https://github.com/oven-sh/bun/releases/download/bun-v1.2.0/SHASUMS256.txt".into() | ||
), | ||
download_name: Some("bun-darwin-aarch64.zip".into()), | ||
download_url: | ||
"https://github.com/oven-sh/bun/releases/download/bun-v1.2.0/bun-darwin-aarch64.zip" | ||
.into() | ||
} | ||
); | ||
} | ||
|
||
#[test] | ||
fn supports_macos_x64() { | ||
let sandbox = create_empty_sandbox(); | ||
let plugin = create_plugin("bun-test", sandbox.path()); | ||
|
||
assert_eq!( | ||
plugin.download_prebuilt(DownloadPrebuiltInput { | ||
env: Environment { | ||
arch: HostArch::X64, | ||
os: HostOS::MacOS, | ||
version: "1.2.0".into(), | ||
..Default::default() | ||
} | ||
}), | ||
DownloadPrebuiltOutput { | ||
archive_prefix: Some("bun-darwin-x64".into()), | ||
bin_path: None, | ||
checksum_name: None, | ||
checksum_url: Some( | ||
"https://github.com/oven-sh/bun/releases/download/bun-v1.2.0/SHASUMS256.txt".into() | ||
), | ||
download_name: Some("bun-darwin-x64.zip".into()), | ||
download_url: | ||
"https://github.com/oven-sh/bun/releases/download/bun-v1.2.0/bun-darwin-x64.zip" | ||
.into() | ||
} | ||
); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected = "Unable to install Bun, unsupported platform windows.")] | ||
fn doesnt_support_windows() { | ||
let sandbox = create_empty_sandbox(); | ||
let plugin = create_plugin("bun-test", sandbox.path()); | ||
|
||
plugin.download_prebuilt(DownloadPrebuiltInput { | ||
env: Environment { | ||
arch: HostArch::X64, | ||
os: HostOS::Windows, | ||
version: "1.2.0".into(), | ||
..Default::default() | ||
}, | ||
}); | ||
} | ||
|
||
#[test] | ||
fn locates_unix_bin() { | ||
let sandbox = create_empty_sandbox(); | ||
let plugin = create_plugin("bun-test", sandbox.path()); | ||
|
||
assert_eq!( | ||
plugin | ||
.locate_bins(LocateBinsInput { | ||
env: Environment { | ||
arch: HostArch::Arm64, | ||
os: HostOS::Linux, | ||
version: "1.2.0".into(), | ||
..Default::default() | ||
}, | ||
tool_dir: PathBuf::new() | ||
}) | ||
.bin_path, | ||
Some("bun".into()) | ||
); | ||
} | ||
|
||
#[test] | ||
fn locates_windows_bin() { | ||
let sandbox = create_empty_sandbox(); | ||
let plugin = create_plugin("bun-test", sandbox.path()); | ||
|
||
assert_eq!( | ||
plugin | ||
.locate_bins(LocateBinsInput { | ||
env: Environment { | ||
arch: HostArch::X64, | ||
os: HostOS::Windows, | ||
version: "1.2.0".into(), | ||
..Default::default() | ||
}, | ||
tool_dir: PathBuf::new() | ||
}) | ||
.bin_path, | ||
Some("bun.exe".into()) | ||
); | ||
} |
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,17 @@ | ||
use proto_pdk::*; | ||
use proto_pdk_test_utils::create_plugin; | ||
use starbase_sandbox::create_empty_sandbox; | ||
|
||
#[test] | ||
fn registers_metadata() { | ||
let sandbox = create_empty_sandbox(); | ||
let plugin = create_plugin("bun-test", sandbox.path()); | ||
|
||
assert_eq!( | ||
plugin.register_tool(ToolMetadataInput::default()), | ||
ToolMetadataOutput { | ||
name: "Bun".into(), | ||
..ToolMetadataOutput::default() | ||
} | ||
); | ||
} |
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,5 @@ | ||
use proto_pdk_test_utils::{create_plugin, generate_global_shims_test}; | ||
use starbase_sandbox::{assert_snapshot, create_empty_sandbox}; | ||
|
||
#[cfg(not(windows))] | ||
generate_global_shims_test!("bun-test", ["bunx"]); |
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,13 @@ | ||
--- | ||
source: tests/shims_test.rs | ||
expression: "std::fs::read_to_string(sandbox.path().join(\".proto/bin\").join(\"bunx\")).unwrap()" | ||
--- | ||
#!/usr/bin/env bash | ||
set -e | ||
[ -n "$PROTO_DEBUG" ] && set -x | ||
|
||
|
||
|
||
exec proto run bun-test -- x "$@" | ||
|
||
|
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,13 @@ | ||
--- | ||
source: tests/shims_test.rs | ||
expression: "std::fs::read_to_string(sandbox.path().join(\".proto/bin\").join(\"bun-test\")).unwrap()" | ||
--- | ||
#!/usr/bin/env bash | ||
set -e | ||
[ -n "$PROTO_DEBUG" ] && set -x | ||
|
||
|
||
|
||
exec proto run bun-test -- "$@" | ||
|
||
|
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,30 @@ | ||
use proto_pdk::*; | ||
use proto_pdk_test_utils::{create_plugin, generate_resolve_versions_tests}; | ||
use starbase_sandbox::create_empty_sandbox; | ||
|
||
generate_resolve_versions_tests!("bun-test", { | ||
"0.4" => "0.4.0", | ||
"0.5.1" => "0.5.1", | ||
}); | ||
|
||
#[test] | ||
fn loads_versions_from_git() { | ||
let sandbox = create_empty_sandbox(); | ||
let plugin = create_plugin("bun-test", sandbox.path()); | ||
|
||
let output = plugin.load_versions(LoadVersionsInput::default()); | ||
|
||
assert!(!output.versions.is_empty()); | ||
} | ||
|
||
#[test] | ||
fn sets_latest_alias() { | ||
let sandbox = create_empty_sandbox(); | ||
let plugin = create_plugin("bun-test", sandbox.path()); | ||
|
||
let output = plugin.load_versions(LoadVersionsInput::default()); | ||
|
||
assert!(output.latest.is_some()); | ||
assert!(output.aliases.contains_key("latest")); | ||
assert_eq!(output.aliases.get("latest"), output.latest.as_ref()); | ||
} |