This repository has been archived by the owner on Jul 17, 2024. It is now read-only.
- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add initial files. * Add shim tests. * Add download tests. * Update deps. * Update readme. * Fix format. * Fix lib. * Fix test. * Fix paths. * Skip windows.
Showing
15 changed files
with
495 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
[plugins] | ||
schema-test = "source:target/wasm32-wasi/debug/schema_plugin.wasm" | ||
moon-test = "source:https://raw.githubusercontent.com/moonrepo/moon/master/proto-plugin.toml" |
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 |
---|---|---|
@@ -1,6 +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
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,19 @@ | ||
bin = "moon-test" | ||
name = "moon-test" | ||
type = "cli" | ||
|
||
[platform.linux] | ||
download-file = "moon-{arch}-unknown-linux-{libc}" | ||
|
||
[platform.macos] | ||
download-file = "moon-{arch}-apple-darwin" | ||
|
||
[platform.windows] | ||
download-file = "moon-{arch}-pc-windows-msvc.exe" | ||
|
||
[install] | ||
download-url = "https://github.com/moonrepo/moon/releases/download/v{version}/{download_file}" | ||
unpack = false | ||
|
||
[resolve] | ||
git-url = "https://github.com/moonrepo/moon" |
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,23 @@ | ||
bin = "moon-test" | ||
name = "moon-test" | ||
type = "cli" | ||
|
||
[platform.linux] | ||
archive-prefix = "moon-linux" | ||
bin-path = "lin/moon" | ||
download-file = "moon-{arch}-unknown-linux-gnu" | ||
|
||
[platform.macos] | ||
bin-path = "mac/moon" | ||
checksum-file = "SHASUM256.txt" | ||
download-file = "moon-{arch}-apple-darwin" | ||
|
||
[platform.windows] | ||
bin-path = "win/moon.exe" | ||
download-file = "moon-{arch}-pc-windows-msvc.exe" | ||
|
||
[install] | ||
download-url = "https://github.com/moonrepo/moon/releases/download/v{version}/{download_file}" | ||
|
||
[resolve] | ||
git-url = "https://github.com/moonrepo/moon" |
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,16 @@ | ||
bin = "moon-test" | ||
name = "moon-test" | ||
type = "cli" | ||
|
||
[platform.linux] | ||
download-file = "moon-{arch}-unknown-linux-{libc}" | ||
|
||
[platform.macos] | ||
download-file = "moon-{arch}-apple-darwin" | ||
|
||
[platform.windows] | ||
download-file = "moon-{arch}-pc-windows-msvc.exe" | ||
|
||
[shim] | ||
local = true | ||
parent_bin = "prnt" |
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,15 @@ | ||
bin = "moon-test" | ||
name = "moon-test" | ||
type = "cli" | ||
|
||
[platform.linux] | ||
download-file = "moon-{arch}-unknown-linux-{libc}" | ||
|
||
[platform.macos] | ||
download-file = "moon-{arch}-apple-darwin" | ||
|
||
[platform.windows] | ||
download-file = "moon-{arch}-pc-windows-msvc.exe" | ||
|
||
[shim] | ||
global = false |
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,255 @@ | ||
use proto_pdk_test_utils::*; | ||
use starbase_sandbox::{create_empty_sandbox, locate_fixture}; | ||
use std::path::PathBuf; | ||
|
||
generate_download_install_tests!( | ||
"schema-test", | ||
"1.10.0", | ||
Some(locate_fixture("schemas").join("base.toml")) | ||
); | ||
|
||
#[test] | ||
fn supports_linux_arm64() { | ||
let sandbox = create_empty_sandbox(); | ||
let plugin = create_schema_plugin( | ||
"schema-test", | ||
sandbox.path(), | ||
locate_fixture("schemas").join("bins.toml"), | ||
); | ||
|
||
assert_eq!( | ||
plugin.download_prebuilt(DownloadPrebuiltInput { | ||
env: Environment { | ||
arch: HostArch::Arm64, | ||
os: HostOS::Linux, | ||
version: "20.0.0".into(), | ||
..Default::default() | ||
} | ||
}), | ||
DownloadPrebuiltOutput { | ||
archive_prefix: Some("moon-linux".into()), | ||
checksum_name: Some("CHECKSUM.txt".into()), | ||
checksum_url: None, | ||
download_name: Some("moon-aarch64-unknown-linux-gnu".into()), | ||
download_url: "https://github.com/moonrepo/moon/releases/download/v20.0.0/moon-aarch64-unknown-linux-gnu".into() | ||
} | ||
); | ||
} | ||
|
||
#[test] | ||
fn supports_linux_x64() { | ||
let sandbox = create_empty_sandbox(); | ||
let plugin = create_schema_plugin( | ||
"schema-test", | ||
sandbox.path(), | ||
locate_fixture("schemas").join("bins.toml"), | ||
); | ||
|
||
assert_eq!( | ||
plugin.download_prebuilt(DownloadPrebuiltInput { | ||
env: Environment { | ||
arch: HostArch::X64, | ||
os: HostOS::Linux, | ||
version: "20.0.0".into(), | ||
..Default::default() | ||
} | ||
}), | ||
DownloadPrebuiltOutput { | ||
archive_prefix: Some("moon-linux".into()), | ||
checksum_name: Some("CHECKSUM.txt".into()), | ||
checksum_url: None, | ||
download_name: Some("moon-x86_64-unknown-linux-gnu".into()), | ||
download_url: "https://github.com/moonrepo/moon/releases/download/v20.0.0/moon-x86_64-unknown-linux-gnu".into() | ||
} | ||
); | ||
} | ||
|
||
#[test] | ||
fn supports_macos_arm64() { | ||
let sandbox = create_empty_sandbox(); | ||
let plugin = create_schema_plugin( | ||
"schema-test", | ||
sandbox.path(), | ||
locate_fixture("schemas").join("bins.toml"), | ||
); | ||
|
||
assert_eq!( | ||
plugin.download_prebuilt(DownloadPrebuiltInput { | ||
env: Environment { | ||
arch: HostArch::Arm64, | ||
os: HostOS::MacOS, | ||
version: "20.0.0".into(), | ||
..Default::default() | ||
} | ||
}), | ||
DownloadPrebuiltOutput { | ||
archive_prefix: None, | ||
checksum_name: Some("SHASUM256.txt".into()), | ||
checksum_url: None, | ||
download_name: Some("moon-aarch64-apple-darwin".into()), | ||
download_url: "https://github.com/moonrepo/moon/releases/download/v20.0.0/moon-aarch64-apple-darwin".into() | ||
} | ||
); | ||
} | ||
|
||
#[test] | ||
fn supports_macos_x64() { | ||
let sandbox = create_empty_sandbox(); | ||
let plugin = create_schema_plugin( | ||
"schema-test", | ||
sandbox.path(), | ||
locate_fixture("schemas").join("bins.toml"), | ||
); | ||
|
||
assert_eq!( | ||
plugin.download_prebuilt(DownloadPrebuiltInput { | ||
env: Environment { | ||
arch: HostArch::X64, | ||
os: HostOS::MacOS, | ||
version: "20.0.0".into(), | ||
..Default::default() | ||
} | ||
}), | ||
DownloadPrebuiltOutput { | ||
archive_prefix: None, | ||
checksum_name: Some("SHASUM256.txt".into()), | ||
checksum_url: None, | ||
download_name: Some("moon-x86_64-apple-darwin".into()), | ||
download_url: "https://github.com/moonrepo/moon/releases/download/v20.0.0/moon-x86_64-apple-darwin".into() | ||
} | ||
); | ||
} | ||
|
||
#[test] | ||
fn supports_windows_arm64() { | ||
let sandbox = create_empty_sandbox(); | ||
let plugin = create_schema_plugin( | ||
"schema-test", | ||
sandbox.path(), | ||
locate_fixture("schemas").join("bins.toml"), | ||
); | ||
|
||
assert_eq!( | ||
plugin.download_prebuilt(DownloadPrebuiltInput { | ||
env: Environment { | ||
arch: HostArch::Arm64, | ||
os: HostOS::Windows, | ||
version: "20.0.0".into(), | ||
..Default::default() | ||
} | ||
}), | ||
DownloadPrebuiltOutput { | ||
archive_prefix: None, | ||
checksum_name: Some("CHECKSUM.txt".into()), | ||
checksum_url: None, | ||
download_name: Some("moon-aarch64-pc-windows-msvc.exe".into()), | ||
download_url: "https://github.com/moonrepo/moon/releases/download/v20.0.0/moon-aarch64-pc-windows-msvc.exe".into() | ||
} | ||
); | ||
} | ||
|
||
#[test] | ||
fn supports_windows_x86() { | ||
let sandbox = create_empty_sandbox(); | ||
let plugin = create_schema_plugin( | ||
"schema-test", | ||
sandbox.path(), | ||
locate_fixture("schemas").join("bins.toml"), | ||
); | ||
|
||
assert_eq!( | ||
plugin.download_prebuilt(DownloadPrebuiltInput { | ||
env: Environment { | ||
arch: HostArch::X86, | ||
os: HostOS::Windows, | ||
version: "20.0.0".into(), | ||
..Default::default() | ||
} | ||
}), | ||
DownloadPrebuiltOutput { | ||
archive_prefix: None, | ||
checksum_name: Some("CHECKSUM.txt".into()), | ||
checksum_url: None, | ||
download_name: Some("moon-x86-pc-windows-msvc.exe".into()), | ||
download_url: "https://github.com/moonrepo/moon/releases/download/v20.0.0/moon-x86-pc-windows-msvc.exe".into() | ||
} | ||
); | ||
} | ||
|
||
#[test] | ||
fn locates_linux_bin() { | ||
let sandbox = create_empty_sandbox(); | ||
let plugin = create_schema_plugin( | ||
"schema-test", | ||
sandbox.path(), | ||
locate_fixture("schemas").join("bins.toml"), | ||
); | ||
|
||
assert_eq!( | ||
plugin | ||
.locate_bins(LocateBinsInput { | ||
env: Environment { | ||
arch: HostArch::Arm64, | ||
os: HostOS::Linux, | ||
version: "20.0.0".into(), | ||
..Default::default() | ||
}, | ||
home_dir: PathBuf::new(), | ||
tool_dir: PathBuf::new(), | ||
}) | ||
.bin_path, | ||
Some("lin/moon".into()) | ||
); | ||
} | ||
|
||
#[test] | ||
fn locates_macos_bin() { | ||
let sandbox = create_empty_sandbox(); | ||
let plugin = create_schema_plugin( | ||
"schema-test", | ||
sandbox.path(), | ||
locate_fixture("schemas").join("bins.toml"), | ||
); | ||
|
||
assert_eq!( | ||
plugin | ||
.locate_bins(LocateBinsInput { | ||
env: Environment { | ||
arch: HostArch::X64, | ||
os: HostOS::MacOS, | ||
version: "20.0.0".into(), | ||
..Default::default() | ||
}, | ||
home_dir: PathBuf::new(), | ||
tool_dir: PathBuf::new(), | ||
}) | ||
.bin_path, | ||
Some("mac/moon".into()) | ||
); | ||
} | ||
|
||
#[test] | ||
fn locates_windows_bin() { | ||
let sandbox = create_empty_sandbox(); | ||
let plugin = create_schema_plugin( | ||
"schema-test", | ||
sandbox.path(), | ||
locate_fixture("schemas").join("bins.toml"), | ||
); | ||
|
||
assert_eq!( | ||
plugin | ||
.locate_bins(LocateBinsInput { | ||
env: Environment { | ||
arch: HostArch::X64, | ||
os: HostOS::Windows, | ||
version: "20.0.0".into(), | ||
..Default::default() | ||
}, | ||
home_dir: PathBuf::new(), | ||
tool_dir: PathBuf::new(), | ||
}) | ||
.bin_path, | ||
Some("win/moon.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,21 @@ | ||
use proto_pdk_test_utils::*; | ||
use starbase_sandbox::{create_empty_sandbox, locate_fixture}; | ||
|
||
#[test] | ||
fn registers_metadata() { | ||
let sandbox = create_empty_sandbox(); | ||
let plugin = create_schema_plugin( | ||
"schema-test", | ||
sandbox.path(), | ||
locate_fixture("schemas").join("base.toml"), | ||
); | ||
|
||
assert_eq!( | ||
plugin.register_tool(ToolMetadataInput::default()), | ||
ToolMetadataOutput { | ||
name: "moon-test".into(), | ||
type_of: PluginType::CLI, | ||
..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,44 @@ | ||
use proto_pdk_test_utils::*; | ||
use starbase_sandbox::{assert_snapshot, create_empty_sandbox, locate_fixture}; | ||
|
||
#[cfg(not(windows))] | ||
generate_global_shims_test!( | ||
"schema-test", | ||
[], | ||
Some(locate_fixture("schemas").join("base.toml")) | ||
); | ||
|
||
#[tokio::test] | ||
async fn doesnt_create_global_shim() { | ||
let sandbox = create_empty_sandbox(); | ||
let plugin = create_schema_plugin( | ||
"schema-test", | ||
sandbox.path(), | ||
locate_fixture("schemas/shim-no-global.toml"), | ||
); | ||
|
||
plugin.tool.create_shims(false).await.unwrap(); | ||
|
||
assert!(!sandbox.path().join(".proto/bin/schema-test").exists()); | ||
} | ||
|
||
#[cfg(not(windows))] | ||
#[tokio::test] | ||
async fn can_create_local_shim() { | ||
let sandbox = create_empty_sandbox(); | ||
let plugin = create_schema_plugin( | ||
"schema-test", | ||
sandbox.path(), | ||
locate_fixture("schemas/shim-local.toml"), | ||
); | ||
|
||
plugin.tool.create_shims(false).await.unwrap(); | ||
|
||
assert_snapshot!(std::fs::read_to_string( | ||
sandbox | ||
.path() | ||
.join(".proto/tools/schema-test/latest/shims/schema-test") | ||
) | ||
.unwrap() | ||
.replace(sandbox.path().to_str().unwrap(), "/workspace")); | ||
} |
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,20 @@ | ||
--- | ||
source: tests/shims_test.rs | ||
expression: "std::fs::read_to_string(sandbox.path().join(\".proto/tools/schema-test/latest/shims/schema-test\")).unwrap().replace(sandbox.path().to_str().unwrap(),\n \"/workspace\")" | ||
--- | ||
#!/usr/bin/env bash | ||
set -e | ||
[ -n "$PROTO_DEBUG" ] && set -x | ||
|
||
|
||
|
||
export PROTO_SCHEMA_TEST_DIR="/workspace/.proto/tools/schema-test/latest" | ||
|
||
|
||
|
||
|
||
|
||
|
||
exec "/workspace/.proto/tools/schema-test/latest/schema-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,13 @@ | ||
--- | ||
source: tests/shims_test.rs | ||
expression: "std::fs::read_to_string(sandbox.path().join(\".proto/bin\").join(if cfg!(windows)\n {\n format!(\"{}.cmd\", \"schema-test\")\n } else { \"schema-test\".to_string() })).unwrap()" | ||
--- | ||
#!/usr/bin/env bash | ||
set -e | ||
[ -n "$PROTO_DEBUG" ] && set -x | ||
|
||
|
||
|
||
exec proto run schema-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,43 @@ | ||
use proto_pdk_test_utils::*; | ||
use starbase_sandbox::{create_empty_sandbox, locate_fixture}; | ||
|
||
generate_resolve_versions_tests!( | ||
"schema-test", | ||
{ | ||
"1.0" => "1.0.3", | ||
"1.4" => "1.4.0", | ||
"1.5" => "1.5.1", | ||
"1" => "1.11.1", | ||
}, | ||
Some(locate_fixture("schemas").join("base.toml")) | ||
); | ||
|
||
#[test] | ||
fn loads_versions_from_git_tags() { | ||
let sandbox = create_empty_sandbox(); | ||
let plugin = create_schema_plugin( | ||
"schema-test", | ||
sandbox.path(), | ||
locate_fixture("schemas").join("base.toml"), | ||
); | ||
|
||
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_schema_plugin( | ||
"schema-test", | ||
sandbox.path(), | ||
locate_fixture("schemas").join("base.toml"), | ||
); | ||
|
||
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()); | ||
} |