Skip to content

OCPBUGS-85436: Replace deprecated rand.Seed with pattern-based test assertions#534

Open
kunalmemane wants to merge 1 commit into
openshift:release-4.15from
kunalmemane:fix-rand-seed-4.15
Open

OCPBUGS-85436: Replace deprecated rand.Seed with pattern-based test assertions#534
kunalmemane wants to merge 1 commit into
openshift:release-4.15from
kunalmemane:fix-rand-seed-4.15

Conversation

@kunalmemane
Copy link
Copy Markdown
Member

@kunalmemane kunalmemane commented May 12, 2026

Summary

  • Removed deprecated rand.Seed(0) calls from TestRandomBuildTag, TestRandomBuildTagNoDupes, and TestContainerName
  • Replaced exact string assertions with regex pattern-based assertions that validate output format, SHA1 hashing for long names, length limits, and uniqueness
  • Dropped math/rand import in favor of regexp

Why

rand.Seed() is deprecated since Go 1.20. The old tests relied on seeding the global PRNG to get deterministic output, then asserting exact hex values. This was fragile and tested PRNG internals rather than actual function behavior.

Test plan

  • Verify TestRandomBuildTag passes — checks short name prefix and format, long name SHA1 hashing and 255-char limit
  • Verify TestRandomBuildTagNoDupes passes — 100 calls produce unique tags
  • Verify TestContainerName passes — output matches expected format pattern

Summary by CodeRabbit

  • Tests
    • Enhanced test coverage for build-tag and container-name formatting validation, including prefix verification, hex-suffix format checks, and length constraint verification.

Signed-off-by: Kunal Memane <kmemane@redhat.com>
@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label May 12, 2026
@openshift-ci-robot
Copy link
Copy Markdown
Contributor

@kunalmemane: This pull request references Jira Issue OCPBUGS-85436, which is invalid:

  • expected the bug to target the "4.15.z" version, but no target version was set
  • release note text must be set and not match the template OR release note type must be set to "Release Note Not Required". For more information you can reference the OpenShift Bug Process.
  • expected Jira Issue OCPBUGS-85436 to depend on a bug targeting a version in 4.16.0, 4.16.z and in one of the following states: VERIFIED, RELEASE PENDING, CLOSED (ERRATA), CLOSED (CURRENT RELEASE), CLOSED (DONE), CLOSED (DONE-ERRATA), but no dependents were found

Comment /jira refresh to re-evaluate validity if changes to the Jira bug are made, or edit the title of this pull request to link to a different bug.

The bug has been updated to refer to the pull request using the external bug tracker.

Details

In response to this:

Summary

  • Removed deprecated rand.Seed(0) calls from TestRandomBuildTag, TestRandomBuildTagNoDupes, and TestContainerName
  • Replaced exact string assertions with regex pattern-based assertions that validate output format, SHA1 hashing for long names, length limits, and uniqueness
  • Dropped math/rand import in favor of regexp

Why

rand.Seed() is deprecated since Go 1.20. The old tests relied on seeding the global PRNG to get deterministic output, then asserting exact hex values. This was fragile and tested PRNG internals rather than actual function behavior.

Test plan

  • Verify TestRandomBuildTag passes — checks short name prefix and format, long name SHA1 hashing and 255-char limit
  • Verify TestRandomBuildTagNoDupes passes — 100 calls produce unique tags
  • Verify TestContainerName passes — output matches expected format pattern

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 openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci-robot openshift-ci-robot added the jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. label May 12, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 12, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: b8c27e18-01bc-4b4f-ba4a-ac032506183f

📥 Commits

Reviewing files that changed from the base of the PR and between 5c5fbe0 and 5905dbc.

📒 Files selected for processing (1)
  • pkg/build/builder/common_test.go

Walkthrough

Test assertions for build-tag and container-name formatting are refactored from exact string matching to regex-based pattern validation, with import adjustments to support regular expression matching.

Changes

Build-Tag and Container-Name Test Validation

Layer / File(s) Summary
Regex-based build-tag validation
pkg/build/builder/common_test.go (lines 6–9, 77–109)
Import regexp and refactor TestRandomBuildTag to validate output formats using regex patterns: short inputs produce temp.builder.openshift.io/<ns>/<name>: prefix with 8-hex suffix; long inputs use SHA1:8-hex format; length does not exceed 255 characters. Removes deterministic seed-based assertions.
Regex-based container-name validation
pkg/build/builder/common_test.go (lines 122–125)
Refactor TestContainerName to match generated output against a regex pattern instead of comparing against a hard-coded expected value.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 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 (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: replacing deprecated rand.Seed with pattern-based test assertions, which aligns with the actual code modifications in the test file.
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.

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

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

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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

@openshift-ci openshift-ci Bot requested review from divyansh42 and sayan-biswas May 12, 2026 07:25
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 12, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: kunalmemane
Once this PR has been reviewed and has the lgtm label, please assign prabhapa 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

@kunalmemane
Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 12, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 12, 2026

@kunalmemane: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/security 5905dbc link false /test security

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.

@kunalmemane
Copy link
Copy Markdown
Member Author

/hold

@openshift-ci openshift-ci Bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants