Skip to content

Make unit tests independent of external services - #2193

Open
officialasishkumar wants to merge 1 commit into
shipwright-io:mainfrom
officialasishkumar:fix/hermetic-unit-tests
Open

Make unit tests independent of external services#2193
officialasishkumar wants to merge 1 commit into
shipwright-io:mainfrom
officialasishkumar:fix/hermetic-unit-tests

Conversation

@officialasishkumar

Copy link
Copy Markdown
Contributor

Changes

  • Replace Git command execution and TCP checks in command/unit tests with package-local fakes.
  • Stub Trivy execution in vulnerability scan unit tests and image-processing command tests.
  • Use local test registries and listeners instead of public GitHub, GHCR, and network endpoints.

Related Issue

Fixes #1865

Type of PR

/kind bug

Submitter Checklist

  • Includes tests if functionality changed/was added
  • Includes docs if changes are user-facing
  • Kind label has been set
  • Release notes block has been filled in, or marked NONE

Release Notes

None

Replace command and scanner dependencies in unit tests with package-local fakes, and use local test registries/listeners instead of public services.
@openshift-ci openshift-ci Bot added release-note-none Label for when a PR does not need a release note kind/bug Categorizes issue or PR as related to a bug. labels May 11, 2026
@pull-request-size pull-request-size Bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label May 11, 2026
@openshift-ci

openshift-ci Bot commented May 11, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign heavywombat for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@IrvingMg

Copy link
Copy Markdown
Member

Could you please sign off your commit so the DCO check passes? You can amend it with git commit --amend -s --no-edit and force-push the update.

@SaschaSchwarze0 SaschaSchwarze0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The correct approach of mocking things would be to define interfaces with an implementation and fake that we would be using in tests. We cannot move Ginkgo into the production code packages to be able to overwrite private functions.

Comment thread cmd/git/main_test.go
// SPDX-License-Identifier: Apache-2.0

package main_test
package main

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We cannot do this. The price of hermetic tests cannot be to mix test and production code into a single package. Whether it actually affects binary size with the global Describe call in Ginkgo style and the dot imports I am not entirely sure, but I assume so.

Comment thread pkg/git/git_test.go
// SPDX-License-Identifier: Apache-2.0

package git_test
package git

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same concern here.

@SaschaSchwarze0 SaschaSchwarze0 added the dco-missing Pull request with missing commit signature. label Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-missing Pull request with missing commit signature. kind/bug Categorizes issue or PR as related to a bug. release-note-none Label for when a PR does not need a release note size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[BUG] Unit Tests Require External Binaries and Resources

4 participants