Skip to content

Commit

Permalink
ci: Lint test utils macros. (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Sep 10, 2023
1 parent 975d935 commit b726e42
Show file tree
Hide file tree
Showing 7 changed files with 3,985 additions and 233 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
with:
components: clippy
- run: cargo clippy --workspace --all-targets
- run: cd plugins && cargo clippy --workspace --all-targets
test:
name: Test
runs-on: ${{ matrix.os }}
Expand All @@ -49,16 +50,16 @@ jobs:
with:
bins: cargo-wasi, cargo-nextest
cache: false
- run: cd plugins && cargo wasi build -p proto_wasm_test
if: ${{ runner.os != 'Windows' }}
- if: ${{ runner.os != 'Windows' }}
run: cd plugins && cargo wasi build -p proto_wasm_test
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Windows runs out of disk space
- run: |
- if: ${{ runner.os == 'Windows' }}
run: |
cd plugins;
cargo wasi build -p proto_wasm_test;
node ../.github/actions/delete-target-files.js;
if: ${{ runner.os == 'Windows' }}
- run: cargo nextest run --workspace --exclude proto_pdk --profile ci --config-file ./.cargo/nextest.toml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
39 changes: 18 additions & 21 deletions crates/pdk-test-utils/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ macro_rules! generate_download_install_tests {
($id:literal, $version:literal, $schema:expr) => {
#[tokio::test]
async fn downloads_verifies_installs_tool() {
let sandbox = create_empty_sandbox();
let sandbox = starbase_sandbox::create_empty_sandbox();
let mut plugin = if let Some(schema) = $schema {
create_schema_plugin($id, sandbox.path(), schema)
} else {
Expand Down Expand Up @@ -43,7 +43,7 @@ macro_rules! generate_download_install_tests {

#[tokio::test]
async fn downloads_prebuilt_and_checksum_to_temp() {
let sandbox = create_empty_sandbox();
let sandbox = starbase_sandbox::create_empty_sandbox();
let mut plugin = if let Some(schema) = $schema {
create_schema_plugin($id, sandbox.path(), schema)
} else {
Expand All @@ -63,20 +63,17 @@ macro_rules! generate_download_install_tests {

#[tokio::test]
async fn doesnt_install_if_already_installed() {
let sandbox = create_empty_sandbox();
let sandbox = starbase_sandbox::create_empty_sandbox();
let plugin = if let Some(schema) = $schema {
create_schema_plugin($id, sandbox.path(), schema)
} else {
create_plugin($id, sandbox.path())
};
let mut tool = plugin.tool;
let version_inst = proto_pdk_test_utils::Version::parse($version).unwrap();
let spec = proto_pdk_test_utils::VersionSpec::parse($version).unwrap();

tool.version = Some(proto_pdk_test_utils::VersionSpec::Version(
version_inst.clone(),
));

tool.manifest.installed_versions.insert(version_inst);
tool.version = Some(spec.clone());
tool.manifest.installed_versions.insert(spec);

std::fs::create_dir_all(&tool.get_tool_dir()).unwrap();

Expand All @@ -93,7 +90,7 @@ macro_rules! generate_resolve_versions_tests {
($id:literal, { $( $k:literal => $v:literal, )* }, $schema:expr) => {
#[tokio::test]
async fn resolves_latest_alias() {
let sandbox = create_empty_sandbox();
let sandbox = starbase_sandbox::create_empty_sandbox();
let mut plugin = if let Some(schema) = $schema {
create_schema_plugin($id, sandbox.path(), schema)
} else {
Expand All @@ -109,7 +106,7 @@ macro_rules! generate_resolve_versions_tests {

#[tokio::test]
async fn resolve_version_or_alias() {
let sandbox = create_empty_sandbox();
let sandbox = starbase_sandbox::create_empty_sandbox();
let mut plugin = if let Some(schema) = $schema {
create_schema_plugin($id, sandbox.path(), schema)
} else {
Expand All @@ -132,7 +129,7 @@ macro_rules! generate_resolve_versions_tests {
// #[tokio::test]
// async fn resolve_custom_alias() {
//
// let sandbox = create_empty_sandbox();
// let sandbox = starbase_sandbox::create_empty_sandbox();

// sandbox.create_file(
// format!(".proto/tools/{}/manifest.json", $id),
Expand All @@ -150,7 +147,7 @@ macro_rules! generate_resolve_versions_tests {
#[tokio::test]
#[should_panic(expected = "Failed to resolve a semantic version for unknown")]
async fn errors_invalid_alias() {
let sandbox = create_empty_sandbox();
let sandbox = starbase_sandbox::create_empty_sandbox();
let mut plugin = if let Some(schema) = $schema {
create_schema_plugin($id, sandbox.path(), schema)
} else {
Expand All @@ -165,7 +162,7 @@ macro_rules! generate_resolve_versions_tests {
#[tokio::test]
#[should_panic(expected = "Failed to resolve a semantic version for 99.99.99")]
async fn errors_invalid_version() {
let sandbox = create_empty_sandbox();
let sandbox = starbase_sandbox::create_empty_sandbox();
let mut plugin = if let Some(schema) = $schema {
create_schema_plugin($id, sandbox.path(), schema)
} else {
Expand All @@ -190,7 +187,7 @@ macro_rules! generate_global_shims_test {
($id:literal, [ $($bin:literal),* ], $schema:expr) => {
#[tokio::test]
async fn creates_global_shims() {
let sandbox = create_empty_sandbox();
let sandbox = starbase_sandbox::create_empty_sandbox();
let mut plugin = if let Some(schema) = $schema {
create_schema_plugin($id, sandbox.path(), schema)
} else {
Expand All @@ -199,7 +196,7 @@ macro_rules! generate_global_shims_test {

plugin.tool.create_shims(false).await.unwrap();

assert_snapshot!(std::fs::read_to_string(
starbase_sandbox::assert_snapshot!(std::fs::read_to_string(
sandbox.path().join(".proto/bin").join(if cfg!(windows) {
format!("{}.cmd", $id)
} else {
Expand All @@ -208,7 +205,7 @@ macro_rules! generate_global_shims_test {
).unwrap());

$(
assert_snapshot!(std::fs::read_to_string(
starbase_sandbox::assert_snapshot!(std::fs::read_to_string(
sandbox.path().join(".proto/bin").join(if cfg!(windows) {
format!("{}.cmd", $bin)
} else {
Expand All @@ -227,8 +224,8 @@ macro_rules! generate_local_shims_test {
};
($id:literal, [ $($bin:literal),* ], $schema:expr) => {
#[tokio::test]
async fn creates_global_shims() {
let sandbox = create_empty_sandbox();
async fn creates_local_shims() {
let sandbox = starbase_sandbox::create_empty_sandbox();
let mut plugin = if let Some(schema) = $schema {
create_schema_plugin($id, sandbox.path(), schema)
} else {
Expand All @@ -238,7 +235,7 @@ macro_rules! generate_local_shims_test {
plugin.tool.create_shims(false).await.unwrap();

$(
assert_snapshot!(std::fs::read_to_string(
starbase_sandbox::assert_snapshot!(std::fs::read_to_string(
sandbox.path().join(".proto/tools").join($id).join("latest/shims").join(if cfg!(windows) {
format!("{}.ps1", $bin)
} else {
Expand All @@ -261,7 +258,7 @@ macro_rules! generate_globals_test {
($id:literal, $dep:literal, $env:expr, $schema:expr) => {
#[tokio::test]
async fn installs_and_uninstalls_globals() {
let sandbox = create_empty_sandbox();
let sandbox = starbase_sandbox::create_empty_sandbox();
let mut plugin = if let Some(schema) = $schema {
create_schema_plugin($id, sandbox.path(), schema)
} else {
Expand Down
Loading

0 comments on commit b726e42

Please sign in to comment.