Skip to content

TRT-2836: Add integration tests for payload query functions - #3859

Open
mstaeble wants to merge 1 commit into
openshift:mainfrom
mstaeble:worktree-trt-2836
Open

TRT-2836: Add integration tests for payload query functions#3859
mstaeble wants to merge 1 commit into
openshift:mainfrom
mstaeble:worktree-trt-2836

Conversation

@mstaeble

@mstaeble mstaeble commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds 53 integration tests covering all 11 functions in pkg/db/query/payload_queries.go
  • Includes 8 new tests for the previously untested GetTestFailuresForPayloadStream function (6-table join, array aggregation, 14-day window, stream/arch isolation)
  • Covers boundary conditions (exact reportEnd semantics for < vs <=), release/stream/architecture isolation, empty-result edge cases, and full column coverage for GetPayloadDiff
  • Adds shared test fixture helpers in test/integration/util/fixtures.go

Test plan

  • gofmt passes
  • go vet ./test/integration/... passes
  • make integration passes (190 tests, 0 failures)
  • make lint passes

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Added comprehensive integration coverage for payload queries, including filtering, ordering, aggregation, error handling, time boundaries, and empty results.
    • Added validation for payload diffs, accepted payloads, failures, OS upgrades, recent payloads, phase metrics, acceptance statistics, tags, predecessors, and pull-request details.
    • Added configurable test fixtures for release tags, pull requests, job runs, and their relationships.

@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: automatic mode

@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 Aug 1, 2026
@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Aug 1, 2026
@openshift-ci-robot

openshift-ci-robot commented Aug 1, 2026

Copy link
Copy Markdown

@mstaeble: This pull request references TRT-2836 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "5.0.0" version, but no target version was set.

Details

In response to this:

Summary

  • Adds 53 integration tests covering all 11 functions in pkg/db/query/payload_queries.go
  • Includes 8 new tests for the previously untested GetTestFailuresForPayloadStream function (6-table join, array aggregation, 14-day window, stream/arch isolation)
  • Covers boundary conditions (exact reportEnd semantics for < vs <=), release/stream/architecture isolation, empty-result edge cases, and full column coverage for GetPayloadDiff
  • Adds shared test fixture helpers in test/integration/util/fixtures.go

Test plan

  • gofmt passes
  • go vet ./test/integration/... passes
  • make integration passes (190 tests, 0 failures)
  • make lint passes

@coderabbitai ignore

🤖 Generated with Claude Code

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

openshift-ci Bot commented Aug 1, 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

@openshift-ci

openshift-ci Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mstaeble

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:

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 added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 1, 2026
@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@openshift-ci-robot: Acknowledged. TRT-2836 needs the 5.0.0 target version before this pull request can satisfy the Jira lifecycle check.

You are interacting with an AI system.

@mstaeble

mstaeble commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.

@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

The change adds integration coverage for payload queries and configurable fixture helpers for release metadata. Tests cover payload diffs, acceptance metrics, failure aggregation, release-tag lookup, filtering, ordering, boundaries, isolation, and empty results.

Changes

Payload query coverage

Layer / File(s) Summary
Configurable query fixtures
test/integration/util/fixtures.go
Adds configurable Prow job runs, release tags, release pull requests, release job runs, and pull-request associations.
Payload selection and diff queries
test/integration/payload_queries_test.go
Tests accepted-payload selection, payload diffs, OS upgrades, recent payloads, pull-request fields, ordering, filtering, report boundaries, release isolation, and empty results.
Payload analytics and release lookups
test/integration/payload_queries_test.go
Tests phase sequences, acceptance streaks, phase counts, acceptance statistics, release-tag lookup, predecessor constraints, time filters, isolation, and empty results.
Payload and stream failure aggregation
test/integration/payload_queries_test.go
Tests payload-specific failures, stream-level aggregation, job status handling, excluded tests, time windows, payload isolation, and no-failure results.

Estimated code review effort: 4 (Complex) | ~45 minutes

🚥 Pre-merge checks | ✅ 18 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 21.21% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Single Responsibility And Clear Naming ⚠️ Warning The new failureFixture has 13 top-level fields, and CreateReleaseJobRun has 8 positional parameters; these exceed the check's stated focus limits. Split failureFixture into focused context/entity sub-fixtures, and replace large positional constructor signatures with focused configuration types or options.
Test Structure And Quality ⚠️ Warning The new tests contain many unannotated testify assertions, including require.NoError(t, err) and assert.Equal(...) at lines 41-45, so failures lack the required diagnostic messages. Add meaningful, behavior-specific messages to every assertion, especially all require.NoError, require.Len, and field-level assert.Equal calls.
✅ Passed checks (18 passed)
Check name Status Explanation
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.
Go Error Handling ✅ Passed All query and database errors are asserted; discarded query results are used only in not-found tests, with no panic or unchecked error paths found.
Sql Injection Prevention ✅ Passed The PR adds no production SQL changes. Existing payload queries bind dynamic values with placeholders, and new fixtures use GORM Create without SQL concatenation.
Excessive Css In React Should Use Styles ✅ Passed Not applicable: the PR changes only Go integration tests and fixtures. No React components, JSX style objects, or useStyles usage appear in the changed files.
Test Coverage For New Features ✅ Passed No application Go functionality changed; 53 integration tests directly cover all 11 payload query functions, including eight tests for GetTestFailuresForPayloadStream.
Feature Documentation ✅ Passed The commit changes only integration tests and test fixtures; no production code, models, APIs, data flow, or docs/features files changed, so no feature documentation update is needed.
Stable And Deterministic Test Names ✅ Passed The added tests use stable Go test identifiers; the only t.Run uses tc.name with four fixed literals, and no Ginkgo or runtime-derived titles contain timestamps, IDs, hosts, or namespaces.
Microshift Test Compatibility ✅ Passed The PR adds standard Go testing.Test database integration tests, not Ginkgo e2e tests; changed files use NewTestDB and no OpenShift cluster APIs.
Single Node Openshift (Sno) Test Compatibility ✅ Passed The changes add standard Go testing integration tests using a PostgreSQL test container; no Ginkgo e2e tests or multi-node/SNO assumptions are present.
Topology-Aware Scheduling Compatibility ✅ Passed The PR changes only integration tests and database fixture helpers; it adds no deployment manifests, operators, controllers, or scheduling constraints.
Ote Binary Stdout Contract ✅ Passed The PR adds only Go integration tests and fixture helpers; the added diff has no main/suite setup, klog, log, fmt.Print*, os.Stdout, or Ginkgo output writes.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed The changes add standard Go Test* integration tests, not Ginkgo e2e tests. URLs are stored fixture strings; no IP parsing, network calls, public-host resolution, or downloads are added.
No-Weak-Crypto ✅ Passed The PR changes only integration tests and database fixtures. The patch adds no weak-crypto primitives, custom cryptography, or secret/token comparisons.
Container-Privileges ✅ Passed The PR changes only Go tests and fixtures; no privileged, host namespace, SYS_ADMIN, escalation, or root container setting was added.
No-Sensitive-Data-In-Logs ✅ Passed The PR adds no direct logging calls. Test failure messages use synthetic fixture names, release tags, and placeholder/public URLs; no passwords, tokens, PII, customer data, or real internal hosts a...
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the addition of integration tests for payload query functions.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🧹 Nitpick comments (2)
test/integration/payload_queries_test.go (2)

1271-1277: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider fixture options instead of the raw UPDATE.

CreateReleasePullRequest does not expose PullRequestID or BugURL, so this test writes them with raw SQL. Adding WithPullRequestID and WithBugURL options to the fixture would keep all release-pull-request setup in one place and match the option pattern you already use for CreateReleaseTag.

The current statement is safe. It uses ? placeholders with bound arguments and does not format user input into the query.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/integration/payload_queries_test.go` around lines 1271 - 1277, Extend
CreateReleasePullRequest with WithPullRequestID and WithBugURL fixture options,
following the existing option pattern used by CreateReleaseTag. Update the test
setup to pass these options when creating the pull request and remove the raw
UPDATE statement, while preserving the existing values and subsequent
LinkReleaseTagPullRequests call.

204-207: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider a fixture option for the prow job run URL.

The pattern "create the run, then update url" repeats in about twelve places in this file. A WithURL option on CreateProwJobRun, or a CreateProwJobRunWithURL helper in test/integration/util, would remove the extra Update call and the duplicated URL literal at each call site. The URL literal currently appears twice per run: once in the Update and once in CreateReleaseJobRun.

This is optional. The current code is correct.

♻️ Example option in test/integration/util/fixtures.go
type ProwJobRunOption func(*models.ProwJobRun)

func WithProwJobRunURL(url string) ProwJobRunOption {
	return func(r *models.ProwJobRun) { r.URL = url }
}

Then the fixture setup becomes:

-	f.run = intutil.CreateProwJobRun(t, dbc, f.job.ID, f.release, f.runTime, false, "F")
-	require.NoError(t, dbc.DB.Model(&f.run).Update("url", "https://prow/run/1").Error)
-
-	intutil.CreateReleaseJobRun(t, dbc, f.tag.ID, f.run.ID, f.job.Name, "Blocking", "Failed", "https://prow/run/1")
+	const runURL = "https://prow/run/1"
+	f.run = intutil.CreateProwJobRunWithOptions(t, dbc, f.job.ID, f.release, f.runTime, false, "F",
+		intutil.WithProwJobRunURL(runURL))
+	intutil.CreateReleaseJobRun(t, dbc, f.tag.ID, f.run.ID, f.job.Name, "Blocking", "Failed", runURL)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/integration/payload_queries_test.go` around lines 204 - 207, Optionally
refactor the repeated Prow run fixture setup by extending CreateProwJobRun with
a URL option, such as WithProwJobRunURL, or adding a CreateProwJobRunWithURL
helper. Apply it to the affected test fixtures so the URL is initialized during
creation, removing the follow-up Update call and avoiding duplicated URL
literals when calling CreateReleaseJobRun.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/integration/payload_queries_test.go`:
- Around line 965-967: Guard rows[0].ReleaseTags with a length assertion before
accessing index 0 in the aggregation test, matching the existing pattern in
TestGetTestFailuresForPayloadStream_BasicAggregation; keep the current rows and
FailureCount assertions unchanged.

---

Nitpick comments:
In `@test/integration/payload_queries_test.go`:
- Around line 1271-1277: Extend CreateReleasePullRequest with WithPullRequestID
and WithBugURL fixture options, following the existing option pattern used by
CreateReleaseTag. Update the test setup to pass these options when creating the
pull request and remove the raw UPDATE statement, while preserving the existing
values and subsequent LinkReleaseTagPullRequests call.
- Around line 204-207: Optionally refactor the repeated Prow run fixture setup
by extending CreateProwJobRun with a URL option, such as WithProwJobRunURL, or
adding a CreateProwJobRunWithURL helper. Apply it to the affected test fixtures
so the URL is initialized during creation, removing the follow-up Update call
and avoiding duplicated URL literals when calling CreateReleaseJobRun.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Pro Plus

Run ID: 32d7351a-e720-41f2-9bed-ba7f9ae2e23b

📥 Commits

Reviewing files that changed from the base of the PR and between f66444a and 8619668.

📒 Files selected for processing (2)
  • test/integration/payload_queries_test.go
  • test/integration/util/fixtures.go

Comment thread test/integration/payload_queries_test.go
Add 53 integration tests covering all 11 functions in
pkg/db/query/payload_queries.go, including the previously untested
GetTestFailuresForPayloadStream. Tests validate business scenarios
such as payload diffing, acceptance tracking, failure aggregation,
phase streaks, and acceptance statistics.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mstaeble
mstaeble force-pushed the worktree-trt-2836 branch from 8619668 to a017b4d Compare August 2, 2026 03:04

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/integration/util/fixtures.go`:
- Around line 137-152: Add a locally bounded context in each affected fixture
helper, then use dbc.DB.WithContext(ctx) for the GORM Create and
Association("PullRequests").Append calls. Apply this consistently to the helpers
corresponding to CreateReleaseTag and the fixture methods in the other specified
ranges, preserving existing assertions and behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Pro Plus

Run ID: 6459f4a4-66e6-4ebe-b6bc-cfc25361072e

📥 Commits

Reviewing files that changed from the base of the PR and between 8619668 and a017b4d.

📒 Files selected for processing (2)
  • test/integration/payload_queries_test.go
  • test/integration/util/fixtures.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/integration/payload_queries_test.go

Comment thread test/integration/util/fixtures.go
@openshift-ci openshift-ci Bot added the ready-for-human-review Indicates a PR has been reviewed by automated tools and is ready for human review label Aug 2, 2026
@mstaeble
mstaeble marked this pull request as ready for review August 2, 2026 10:47
@mstaeble mstaeble changed the title [WIP] TRT-2836: Add integration tests for payload query functions TRT-2836: Add integration tests for payload query functions Aug 2, 2026
@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 Aug 2, 2026
@openshift-ci
openshift-ci Bot requested review from deads2k and dgoodwin August 2, 2026 10:47
@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Scheduling required tests:
/test e2e

@openshift-ci

openshift-ci Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

@mstaeble: 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.

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. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. ready-for-human-review Indicates a PR has been reviewed by automated tools and is ready for human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants