Skip to content

Add generic plugin test runner script#10963

Open
ehelms wants to merge 1 commit into
theforeman:developfrom
ehelms:add-plugin-test-script
Open

Add generic plugin test runner script#10963
ehelms wants to merge 1 commit into
theforeman:developfrom
ehelms:add-plugin-test-script

Conversation

@ehelms

@ehelms ehelms commented Apr 27, 2026

Copy link
Copy Markdown
Member

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.

@adamruzicka

Copy link
Copy Markdown
Contributor

Every now and then, I need to run an ad-hoc plugin rake task (usually foreman_theme_satellite:validate_docs), could this be extended to be able to run arbitrary rake tasks or would that be out of scope?

@ehelms

ehelms commented Apr 27, 2026

Copy link
Copy Markdown
Member Author

Every now and then, I need to run an ad-hoc plugin rake task (usually foreman_theme_satellite:validate_docs), could this be extended to be able to run arbitrary rake tasks or would that be out of scope?

I think that's fair. Do you think we can count on the pattern always including : to differentiate rake tasks from test files? Or do you think it will need an option like --rake ?

@adamruzicka

Copy link
Copy Markdown
Contributor

Or do you think it will need an option like --rake ?

I'd prefer this to also cover cases like string extraction where the plugin-name-prefix is not there (it is plugin:gettext[$plugin])

@ehelms ehelms force-pushed the add-plugin-test-script branch from 7717fdf to 00ebd76 Compare April 27, 2026 14:23
Comment thread script/plugin-test Outdated
Comment thread script/plugin-test Outdated
Comment thread script/plugin-test Outdated
Comment thread script/plugin-test Outdated
Comment thread script/plugin-test Outdated
Comment thread script/foreman-plugin-test
@ehelms

ehelms commented Jun 2, 2026

Copy link
Copy Markdown
Member Author

@adamruzicka updated from your feedback

@adamruzicka adamruzicka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One last comment, otherwise lgtm

Comment thread script/foreman-plugin-test Outdated
adamruzicka
adamruzicka previously approved these changes Jun 4, 2026

@adamruzicka adamruzicka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks good, please squash the commits

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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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-test bash 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 ruby for single-file runs and delegates full-suite runs to bundle exec rake test:<plugin>.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +190 to +194
exec bundle exec ruby \
-I"$INCLUDE_PATHS" \
-I"${RAKE_PATH}/lib" \
"${TEST_FILES[@]}" \
"${OTHER_OPTS[@]}"
Comment on lines +50 to +53
for candidate in "$dir" "$dir/foreman" "$dir/../foreman" "$dir/../../foreman"; do
if [[ -f "$candidate/config/application.rb" ]]; then
readlink -f "$candidate"
return 0
Comment on lines +5 to +9
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants