Add generic plugin test runner script#10963
Conversation
|
Every now and then, I need to run an ad-hoc plugin rake task (usually |
I think that's fair. Do you think we can count on the pattern always including |
I'd prefer this to also cover cases like string extraction where the plugin-name-prefix is not there (it is |
7717fdf to
00ebd76
Compare
00ebd76 to
503aec1
Compare
|
@adamruzicka updated from your feedback |
adamruzicka
left a comment
There was a problem hiding this comment.
One last comment, otherwise lgtm
adamruzicka
left a comment
There was a problem hiding this comment.
This looks good, please squash the commits
49c77b1 to
0f27d10
Compare
Plugins like Katello and foreman_puppet have their own wrapper scripts or Rakefile customizations to make it easier to run individual test files without manually switching to the Foreman directory and setting up cross-project load paths. This script generalizes that pattern for all plugins. Supports running from the Foreman checkout, a plugin checkout, or anywhere on PATH with automatic Foreman/plugin discovery. Single-file runs use direct ruby invocation for faster feedback; full-suite runs delegate to the plugin's existing rake tasks. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
0f27d10 to
8c31ed8
Compare
There was a problem hiding this comment.
Pull request overview
Adds a generic, repository-provided wrapper script to run Foreman plugin tests/rake tasks from various working directories by auto-discovering the Foreman checkout and (optionally) the plugin location.
Changes:
- Introduces
script/foreman-plugin-testbash script for running plugin test suites, single test files, or arbitrary rake tasks. - Implements Foreman/plugin discovery logic (Foreman checkout, plugin checkout, PATH usage, direct plugin paths).
- Uses direct
bundle exec rubyfor single-file runs and delegates full-suite runs tobundle exec rake test:<plugin>.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| exec bundle exec ruby \ | ||
| -I"$INCLUDE_PATHS" \ | ||
| -I"${RAKE_PATH}/lib" \ | ||
| "${TEST_FILES[@]}" \ | ||
| "${OTHER_OPTS[@]}" |
| for candidate in "$dir" "$dir/foreman" "$dir/../foreman" "$dir/../../foreman"; do | ||
| if [[ -f "$candidate/config/application.rb" ]]; then | ||
| readlink -f "$candidate" | ||
| return 0 |
| # Works from four contexts: | ||
| # 1. From the Foreman checkout: plugin-test katello test/models/foo_test.rb | ||
| # 2. From a plugin checkout: plugin-test test/models/foo_test.rb | ||
| # 3. From anywhere (on PATH): plugin-test katello test/models/foo_test.rb | ||
| # 4. With direct paths: plugin-test ../katello/test/models/foo_test.rb |
Plugins like Katello and foreman_puppet have their own wrapper scripts or Rakefile customizations to make it easier to run individual test files without manually switching to the Foreman directory and setting up cross-project load paths. This script generalizes that pattern for all plugins.
Supports running from the Foreman checkout, a plugin checkout, or anywhere on PATH with automatic Foreman/plugin discovery. Single-file runs use direct ruby invocation for faster feedback; full-suite runs delegate to the plugin's existing rake tasks.
I am submitting this as a replacement for ktest to be available for any plugin, and support different paths of usage. And instead of this living inside our development deployment tooling, to live as a script in the main repository and thus allow it's usage from more places.
In the use case of
foremanctl, the development deployer would copy the script to the users local bin directory to make it broadly available within the environment.