Skip to content

test: Add Unit Test Coverage for Query Util#1027

Open
kartikangiras wants to merge 1 commit into
goharbor:mainfrom
kartikangiras:test/querytest
Open

test: Add Unit Test Coverage for Query Util#1027
kartikangiras wants to merge 1 commit into
goharbor:mainfrom
kartikangiras:test/querytest

Conversation

@kartikangiras

@kartikangiras kartikangiras commented Jun 26, 2026

Copy link
Copy Markdown

Description

Add unit test coverage for pkg/utils/query.go

Type of Change

Please select the relevant type.

  • Bug fix
  • New feature
  • Refactor
  • Documentation update
  • Chore / maintenance

Changes

  • pkg/utils/query_test.go: 15 tests for BuildQueryParam, input validation, key validation

@kartikangiras

Copy link
Copy Markdown
Author

@NucleoFusion Could you PTAL into this PR.

@qcserestipy qcserestipy added the status/in-progress Work on this issue has started or a linked pull request is actively being developed. label Jun 30, 2026

Copilot AI 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.

Pull request overview

Adds unit tests to cover the query-string builder utility used for list command filtering, improving confidence in CLI query construction and validation behavior.

Changes:

  • Introduces unit tests for utils.BuildQueryParam covering empty input, fuzzy/exact/range query generation, and combined modes.
  • Adds negative tests for invalid argument formats and invalid keys.

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

Comment thread pkg/utils/query_test.go
Comment thread pkg/utils/query_test.go
Signed-off-by: Kartik Angiras <angiraskartik@gmail.com>
@kartikangiras

Copy link
Copy Markdown
Author

Hey @qcserestipy , I have made changes and resolved the review remarks. Could you PTAL.

@qcserestipy

Copy link
Copy Markdown
Collaborator

Nice coverage of the happy paths and the format/key validation errors. A few edge cases in BuildQueryParam aren't exercised yet, and they're the interesting ones because they reveal some fuzzy parsing behavior worth pinning down:

  1. Values containing =strings.Split(v, "=") returns 3 parts for name=foo=bar, so it's rejected as an "invalid arg" even though the intent is a value with an = in it. Using strings.SplitN(v, "=", 2) would fix this. Either way, a test should document the chosen behavior.

  2. Empty valuename= passes the len(kv) != 2 check and produces name=~ (fuzzy) / name= (match). Likely unintended; currently untested.

  3. Empty range boundssize=1~ or size=~100 both pass and emit size=[1~] / size=[~100]. Worth a test to confirm whether that's acceptable or should error.

Optional: these 15 functions are nearly identical in shape — folding them into a single table-driven test with t.Run subtests (as done elsewhere in the repo) would make adding the above cases a one-line change each.

Also, since #1025 asks for both query.go and reflect.go coverage and this PR is query-only, consider dropping "Fixes #1025" here (or marking it partial) so the issue isn't auto-closed before the reflect tests land.

@qcserestipy qcserestipy added the Changes Requesed feedback that must be addressed before merging. label Jul 20, 2026
@qcserestipy
qcserestipy requested a review from Copilot July 20, 2026 12:14

@qcserestipy qcserestipy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

As mentioned

Copilot AI 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.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Changes Requesed feedback that must be addressed before merging. status/in-progress Work on this issue has started or a linked pull request is actively being developed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants