Skip to content

ROSAENG-60112 | test: add focused coverage for untested pkg packages#3277

Merged
openshift-merge-bot[bot] merged 2 commits into
openshift:masterfrom
olucasfreitas:ROSAENG-60112-1C
Jun 29, 2026
Merged

ROSAENG-60112 | test: add focused coverage for untested pkg packages#3277
openshift-merge-bot[bot] merged 2 commits into
openshift:masterfrom
olucasfreitas:ROSAENG-60112-1C

Conversation

@olucasfreitas

@olucasfreitas olucasfreitas commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

PR Summary

Add focused, meaningful unit tests for previously untested package-level behavior in the early-priority Phase 1C scope. This aligns the change with the plan's first implementation step instead of the earlier pkg/aws Phase 1A direction.

Detailed Description of the Issue

The coverage plan prioritizes untested pkg/ packages first because they are fast, reviewable wins that raise confidence without over-investing in low-value command wiring. Several package-level utilities and integration helpers had no automated coverage at all, including FedRAMP config behavior, input file parsing, logging helpers, color/profile/region/debug flag behavior, and the small HTTP client wrapper.

This PR adds focused tests for the real behavior in those packages while intentionally skipping constants-only packages and avoiding coverage-for-coverage-sake assertions.

Related Issues and PRs

  • Jira: ROSAENG-60112
  • Fixes: #
  • Related PR(s): supersedes prior draft work that was started under the Phase 1A direction
  • Related design/docs: Coverage planning work for ROSAENG-60112

Type of Change

  • feat - adds a new user-facing capability.
  • fix - resolves an incorrect behavior or bug.
  • docs - updates documentation only.
  • style - formatting or naming changes with no logic impact.
  • refactor - code restructuring with no behavior change.
  • test - adds or updates tests only.
  • chore - maintenance work (tooling, housekeeping, non-product code).
  • build - changes build system, packaging, or dependencies for build output.
  • ci - changes CI pipelines, jobs, or automation workflows.
  • perf - improves performance without changing intended behavior.

Previous Behavior

The following packages had no dedicated automated coverage for their package-level behavior:

  • pkg/fedramp
  • pkg/input
  • pkg/logging
  • pkg/color
  • pkg/aws/profile
  • pkg/aws/region
  • pkg/debug
  • pkg/clients

Behavior After This Change

The repo now has focused tests for:

  • FedRAMP flag wiring, environment validation, and config-backed enable/disable behavior
  • YAML/JSON input file loading plus the Hosted Control Planes happy path guard
  • Logger builders and HTTP round-tripper request/response logging with JSON/form redaction
  • Color flag defaults, completion options, and explicit color modes
  • AWS profile and region flag/environment precedence, including escaped-empty handling for region
  • Debug flag state behavior
  • HTTP client wrapper request behavior

Intentionally not added:

  • constants-only packages such as pkg/info, pkg/object, pkg/properties, and pkg/constants
  • brittle tests that would only duplicate stdlib or SDK behavior without validating ROSA-specific logic

How to Test (Step-by-Step)

Preconditions

  • Go toolchain installed
  • Repository cloned with hooks installed

Test Steps

  1. Run go test ./pkg/fedramp ./pkg/input ./pkg/logging ./pkg/color ./pkg/aws/profile ./pkg/aws/region ./pkg/debug ./pkg/clients -count=1
  2. Run go test ./pkg/fedramp ./pkg/input ./pkg/logging ./pkg/color ./pkg/aws/profile ./pkg/aws/region ./pkg/debug ./pkg/clients -cover
  3. Run go vet ./pkg/fedramp ./pkg/input ./pkg/logging ./pkg/color ./pkg/aws/profile ./pkg/aws/region ./pkg/debug ./pkg/clients

Expected Results

  • All targeted package tests pass
  • Coverage is reported for each targeted package
  • go vet finishes without findings

Proof of the Fix

  • Logs/CLI output:
    • go test passes for all targeted packages
    • go vet is clean
    • pre-push checks passed (format, build, lint, changed-files coverage, unit/integration tests)
  • Other artifacts:
    • 8 new test files
    • 757 lines of test code added

Breaking Changes

  • No breaking changes
  • Yes, this PR introduces a breaking change (describe impact and migration plan below)

Breaking Change Details / Migration Plan

N/A

Developer Verification Checklist

  • Commit subject/title follows [JIRA-TICKET] | [TYPE]: <MESSAGE>.
  • PR description clearly explains both what changed and why.
  • Relevant Jira/GitHub issues and related PRs are linked.
  • make install-hooks has been run in this clone.
  • Tests were added/updated where appropriate.
  • I manually tested the change.
  • make test passes.
  • make lint passes.
  • make rosa passes.
  • Documentation or repo-local agent guidance was added/updated where appropriate.
  • Any risk, limitation, or follow-up work is documented.

Summary by CodeRabbit

  • Tests
    • Added Ginkgo/Gomega suites covering AWS profile and region flag + environment variable precedence and special empty-value handling.
    • Added HTTP client tests for successful requests and error propagation.
    • Added color and debug flag tests for default behavior and state changes.
    • Added FedRAMP config tests, including enable/disable behavior, region validation, and environment validation.
    • Added input unmarshalling tests (YAML/JSON) and Hypershift safety checks.
    • Added logging tests verifying log level behavior, body preservation, and sensitive/redacted field handling (including headers and form fields).

…(Phase 1C)

Add meaningful tests for previously untested package-level behavior:

- pkg/fedramp: flag wiring, env validation, config-backed enable/disable behavior
- pkg/input: YAML/JSON file loading and hypershift happy path
- pkg/logging: logger builders, round tripper validation, JSON/form redaction
- pkg/color: flag defaults, completion, explicit color modes
- pkg/aws/profile: flag/env precedence
- pkg/aws/region: flag/env precedence and escaped-empty handling
- pkg/debug: debug flag state
- pkg/clients: HTTP client wrapper behavior

Skip constants-only packages and avoid low-value coverage-for-coverage-sake tests.

Validation:
- go test ./pkg/fedramp ./pkg/input ./pkg/logging ./pkg/color ./pkg/aws/profile ./pkg/aws/region ./pkg/debug ./pkg/clients -count=1
- go test ./pkg/fedramp ./pkg/input ./pkg/logging ./pkg/color ./pkg/aws/profile ./pkg/aws/region ./pkg/debug ./pkg/clients -cover
- go vet ./pkg/fedramp ./pkg/input ./pkg/logging ./pkg/color ./pkg/aws/profile ./pkg/aws/region ./pkg/debug ./pkg/clients
@openshift-ci openshift-ci Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 23, 2026
@openshift-ci

openshift-ci Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 4a1e1238-a4de-435d-b911-8be4d755a160

📥 Commits

Reviewing files that changed from the base of the PR and between 6402b4e and 1d9dadb.

📒 Files selected for processing (4)
  • pkg/aws/region/flag_test.go
  • pkg/color/flag_test.go
  • pkg/fedramp/fedramp_test.go
  • pkg/logging/logging_test.go
💤 Files with no reviewable changes (1)
  • pkg/color/flag_test.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • pkg/aws/region/flag_test.go
  • pkg/fedramp/fedramp_test.go
  • pkg/logging/logging_test.go

📝 Walkthrough

Walkthrough

Eight new Ginkgo/Gomega test files were added across pkg/aws/profile, pkg/aws/region, pkg/clients, pkg/color, pkg/debug, pkg/fedramp, pkg/input, and pkg/logging. The tests cover flag registration and default values, environment-variable precedence, color and debug state changes, FedRAMP config loading and disable behavior, HTTP client request handling, input unmarshalling, Hypershift cluster detection, and logging redaction for JSON, headers, and form data.

🚥 Pre-merge checks | ✅ 14 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (14 passed)
Check name Status Explanation
Title check ✅ Passed Matches the required commit format and clearly describes the main change: focused tests for untested pkg packages.
Description check ✅ Passed It follows the required template and includes the needed summary, issue context, scope, testing, proof, and checklist sections.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Stable And Deterministic Test Names ✅ Passed All Ginkgo titles in the added tests are static descriptive strings; none embed timestamps, IDs, hostnames, IPs, or generated values.
Test Structure And Quality ✅ Passed New Ginkgo tests are isolated, clean up global/env state, use no indefinite waits, and follow existing repository patterns without resource leaks.
Microshift Test Compatibility ✅ Passed PASS: The added Ginkgo tests are package unit tests and do not reference MicroShift-unsupported OpenShift APIs, namespaces, or features; no skip/tag guard is needed.
Single Node Openshift (Sno) Test Compatibility ✅ Passed PASS: The added Ginkgo tests are package-level unit specs; I found no node/topology/HA assumptions and no missing SNO guards.
Topology-Aware Scheduling Compatibility ✅ Passed Only test files changed; no deployment manifests, controllers, or scheduling logic were added or modified.
Ote Binary Stdout Contract ✅ Passed The new test files only add standard Ginkgo Test* entrypoints and specs; no main/init/TestMain/BeforeSuite stdout writes or stdout logger setup appear.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed No new test hardcodes IPv4 or needs public connectivity; httptest.NewServer falls back to ::1, and other HTTP uses are mocked/local.
No-Weak-Crypto ✅ Passed No modified file uses MD5/SHA1/DES/RC4/3DES/Blowfish/ECB, custom crypto, or secret comparisons; searches over the added tests were clean.
Container-Privileges ✅ Passed PR is test-only; scanned touched files and manifests found no new privileged:true, hostPID, hostNetwork, hostIPC, allowPrivilegeEscalation:true, or root/SYS_ADMIN settings.
No-Sensitive-Data-In-Logs ✅ Passed Only tests were added; no new prod logging was introduced, and the logging code/tests explicitly omit Authorization and redact configured secrets.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 23, 2026
@olucasfreitas olucasfreitas changed the title ROSAENG-60112 | test: add focused coverage for untested pkg packages (Phase 1C) ROSAENG-60112 | test: add focused coverage for untested pkg packages Jun 23, 2026
@olucasfreitas olucasfreitas marked this pull request as ready for review June 23, 2026 16:14
@openshift-ci openshift-ci Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 23, 2026
@openshift-ci openshift-ci Bot requested review from davidleerh and marcolan018 June 23, 2026 16:17
@codecov

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 27.02%. Comparing base (9abd301) to head (1d9dadb).
⚠️ Report is 19 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3277      +/-   ##
==========================================
+ Coverage   25.00%   27.02%   +2.02%     
==========================================
  Files         330      334       +4     
  Lines       36162    36704     +542     
==========================================
+ Hits         9042     9920     +878     
+ Misses      26458    26029     -429     
- Partials      662      755      +93     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread pkg/input/input_test.go
Describe("CheckIfHypershiftClusterOrExit", func() {
It("returns without exiting for a hypershift cluster", func() {
cluster, err := cmv1.NewCluster().
Hypershift(cmv1.NewHypershift().Enabled(true)).

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.

What is the expected behavior if is not enabled?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The non-HCP path calls os.Exit(1) directly, so testing it at unit level would need subprocess tricks or a refactor of the function signature, both out of scope here. The happy path test documents the intended behavior for HCP clusters; the exit behavior is better validated at the command integration level.

Describe("IsValidEnv", func() {
It("recognizes known environments", func() {
Expect(IsValidEnv("production")).To(BeTrue())
Expect(IsValidEnv("staging")).To(BeTrue())

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.

Is staging01 a valid env too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, it is! Adding it to the assertion.


Expect(Region()).To(Equal(""))
})
})

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.

Would make sense having one "returns an empty string when neither flag nor environment is set" like the profile has?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good call, adding it for parity with the profile tests.

Comment thread pkg/logging/logging_test.go Outdated
})

Describe("RoundTripper", func() {
It("preserves request and response bodies and redacts JSON fields in logs", func() {

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.

If this test fails how do we know the cause? bodies not preserved or json fields not redacted?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agree, splitting it into three focused tests so a failure tells you exactly what broke.


Describe("Disable", func() {
It("clears the in-memory flag and persists FedRAMP=false for a valid config", func() {
tempDir := GinkgoT().TempDir()

@amandahla amandahla Jun 23, 2026

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.

minor: What is the difference between this and the os.MkdirTemp?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No real difference in outcome, GinkgoT().TempDir() is just Ginkgo's managed version that auto-cleans after the test. I was mixing the two approaches, standardizing all of them to GinkgoT().TempDir() now.

Comment thread pkg/color/flag_test.go Outdated
stdout, err := os.Stdout.Stat()
expected := true
if err == nil {
expected = (stdout.Mode()&os.ModeDevice != 0) && (stdout.Mode()&os.ModeNamedPipe == 0)

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.

The expected value is computed with the same stdout logic as UseColor(), right?
If this test failed, what would tell?
I would suggest dropping it and relying on never/always + the unknown→default case (and reporter tests) for color coverage. wdyt?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're right, it's basically testing the function against itself. Dropping it. The never, always, and unknown-falls-to-default cases already cover the meaningful paths.

Expect(HasFlag(cmd)).To(BeFalse())
Expect(HasAdminFlag(cmd)).To(BeFalse())

Expect(cmd.Flags().Set("govcloud", "true")).To(Succeed())

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.

  1. With this test I noticed that we have 2 flags (--admin and --govcloud) that enables fedramp. Is this expected? (out of scope of this PR but nice to review since we are here ;-) )

  2. If this is expected then should we have a test to validate behavior if just one of them are enabled?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

  1. Yeah, both flags bind to the same enabled var, that's existing behavior. Worth reviewing separately but out of scope here. 2) Good idea, adding a test that setting one flag doesn't make the other one report as changed.

Expect(Enabled()).To(BeFalse())
})

It("returns false when the config file does not exist", func() {

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.

Would make sense covering the cases below? (if they are real cases)

  • Enabled() with valid config + FedRAMP: false
  • Disable() when config is missing
  • Disable() when config is invalid

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good suggestions, they are real cases. Adding all three.

- Add staging01 to IsValidEnv assertion
- Add region empty-string test for parity with profile tests
- Split round-tripper test into three focused tests (body preservation,
  JSON redaction, auth header omission)
- Drop tautological auto-color test
- Add flag-independence tests for govcloud vs admin
- Add edge cases: Enabled with FedRAMP:false, Disable with missing and
  invalid config
@amandahla

Copy link
Copy Markdown
Contributor

/approve
/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Jun 29, 2026
@openshift-ci

openshift-ci Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: amandahla, olucasfreitas

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

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [amandahla,olucasfreitas]

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

@openshift-ci

openshift-ci Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

@olucasfreitas: all tests passed!

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@openshift-merge-bot openshift-merge-bot Bot merged commit 9c2b995 into openshift:master Jun 29, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants