Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support local buildpacks and meta-buildpacks in libcnb-test #666

Merged
merged 9 commits into from
Sep 20, 2023

Conversation

colincasey
Copy link
Contributor

The test runner has been modified to support a BuildpackReference::LibCnbRs(BuildpackId) variant which represents a buildpack (and any of it's dependencies) within the workspace that needs to be compiled for testing. This is similar to BuildpackReference::Crate but also supports meta-buildpacks.

This PR replaces #590 and should be easier to review now that similar refactorings from that PR have been incorporated into the codebase.

The test runner has been modified to support a `BuildpackReference::LibCnbRs(BuildpackId)` variant which represents a buildpack (and any of it's dependencies) within the workspace that needs to be compiled for testing. This is similar to `BuildpackReference::Crate` but also supports meta-buildpacks.
libcnb-test/src/test_runner.rs Outdated Show resolved Hide resolved
libcnb-test/src/build_config.rs Outdated Show resolved Hide resolved
.gitignore Show resolved Hide resolved
libcnb-test/src/build_config.rs Show resolved Hide resolved
* Renamed `LibCnbRs` to `WorkspaceBuildpack`
* Renamed `Crate` to `CurrentCrate`
* Updated CHANGELOG.md and doc example
Copy link
Member

@edmorley edmorley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for making those changes. I'll defer to Manuel for the main part of the review, since he's more familiar with the libcnb-package APIs than I am.

@edmorley edmorley requested a review from Malax September 11, 2023 09:34
@Malax
Copy link
Member

Malax commented Sep 12, 2023

Update: This is on my short list for this week for a review. I should get to this tomorrow.

libcnb-test/src/build.rs Outdated Show resolved Hide resolved
Copy link
Member

@Malax Malax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall good to go I think - some minor changes requested but nothing crazy I think.

libcnb-test/src/build.rs Outdated Show resolved Hide resolved
libcnb-test/src/build.rs Outdated Show resolved Hide resolved
libcnb-test/src/build.rs Outdated Show resolved Hide resolved
libcnb-test/src/build.rs Outdated Show resolved Hide resolved
libcnb-test/src/build.rs Outdated Show resolved Hide resolved
libcnb-test/tests/integration_test.rs Show resolved Hide resolved
* updated error enum names
* removed need for wrapper struct for packaged buildpacks
libcnb-test/README.md Outdated Show resolved Hide resolved
libcnb-test/tests/integration_test.rs Outdated Show resolved Hide resolved
libcnb-test/tests/integration_test.rs Outdated Show resolved Hide resolved
colincasey and others added 4 commits September 19, 2023 09:36
Co-authored-by: Ed Morley <501702+edmorley@users.noreply.github.com>
Co-authored-by: Ed Morley <501702+edmorley@users.noreply.github.com>
Co-authored-by: Ed Morley <501702+edmorley@users.noreply.github.com>
* main:
  Ignore file support when finding buildpacks (#673)
  Apply rustfmt to README example (#676)
  Update example `cargo libcnb package` log output in READMEs (#675)
  Add CLI usage help output to libcnb-cargo README (#674)
  Fix lint errors with Rust 1.73 (#672)
  Include README.md in lib.rs (#667)

# Conflicts:
#	CHANGELOG.md
Copy link
Member

@Malax Malax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve to stop blocking, feel free to merge after fixing the two comments I made. :) 👍🏻

libcnb-test/Cargo.toml Outdated Show resolved Hide resolved
libcnb-test/src/build.rs Outdated Show resolved Hide resolved
libcnb-test/tests/integration_test.rs Show resolved Hide resolved
* updated error enum from `PackageTestBuildpackError` to `PackageBuildpackError`
* added newline to Cargo.toml
@colincasey colincasey merged commit b59a9ce into main Sep 20, 2023
4 checks passed
@colincasey colincasey deleted the libcnb_test_meta_buildpack_support branch September 20, 2023 17:30
edmorley added a commit that referenced this pull request Nov 2, 2023
…sts (#715)

The `#[should_panic]` annotation allows marking tests that are
expected to panic. It accepts an `expected` field which allows for
substring matching against the panic message.

`panic::catch_unwind` allows doing something similar, but requires
a lot more boilerplate. However, it can be used in cases where the
panic message contains dynamic values and substring matching isn't
adequate for the purpose of what the tests intends to test.

In general I believe we should prefer `#[should_panic]` and only use
`panic::catch_unwind` when it benefits the test.

I've added this recommendation to the top of the integration tests file,
and updated several of the tests to follow it.

Notably:
- For the tests `address_for_port_when_container_crashed` and
  `app_dir_invalid_path`, the tests now uses `panic::catch_unwind`
  allowing the assertions to match against the whole dynamic message,
  improving coverage.
- For `expected_pack_failure_still_panics_for_non_pack_failure`, the
  test has been switched back to using `#[should_panic]` (as it was before
  #666), since the purpose of the test is not to check the full error message
  of that specific failure mode, but instead to confirm that a non-pack failure
  isn't marked as a success when using `.expected_pack_result()`.

See:
https://doc.rust-lang.org/book/ch11-01-writing-tests.html#checking-for-panics-with-should_panic
https://doc.rust-lang.org/std/panic/fn.catch_unwind.html
https://doc.rust-lang.org/std/panic/struct.AssertUnwindSafe.html
edmorley added a commit that referenced this pull request Nov 2, 2023
Improves the integration test coverage in preparation for fixing #666,
so as to (a) reduce the size of that PR, (b) make it easier to see the
before/after of the error output.

GUS-W-14416222.
edmorley added a commit that referenced this pull request Nov 7, 2023
After #666, incorrect error messages were shown for failures that
occurred during buildpack compilation packaging, since the
handling in `TestRunner::build_internal` used the wrong message
text, plus didn't include the error struct in the `panic!` string.

These have been fixed, plus display representations added to
all of the new error variants.

In addition, the usages of `assert!` and `.unwrap()` in functions that
return `Result` have been replaced with new error enum variants.

The change in output can be seen in the new tests added by #717.

There is one last scenario that doesn't yet have a test - the testing
of the cross-compilation output itself. However, I'll add that separately,
since it's going to be more complex to test / there are a few different
options that we'll need to choose between.

Fixes #704.
Fixes #709.
Fixes #710.
GUS-W-14395170.
edmorley added a commit that referenced this pull request Nov 16, 2023
Since `pack::BuildpackReference` is an internal-only type (not to be
confused with the public `build_config::BuildpackReference`), and the
`From<&TempDir>` implementation is unused since #666.

GUS-W-14502304.
@edmorley edmorley removed their request for review March 1, 2024 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants