Skip to content

test: add unit tests for resolveBuilder in cmd/ci#3570

Open
Ankitsinghsisodya wants to merge 2 commits intoknative:mainfrom
Ankitsinghsisodya:test/ci-config-accessors
Open

test: add unit tests for resolveBuilder in cmd/ci#3570
Ankitsinghsisodya wants to merge 2 commits intoknative:mainfrom
Ankitsinghsisodya:test/ci-config-accessors

Conversation

@Ankitsinghsisodya
Copy link
Copy Markdown
Contributor

@Ankitsinghsisodya Ankitsinghsisodya commented Apr 1, 2026

test: add unit tests for resolveBuilder in cmd/ci

Related Issue

Closes: #3568

What this PR does

Adds cmd/ci/config_test.go — a new test file for cmd/ci/config.go.

The unexported resolveBuilder function had zero test coverage. It
contains non-trivial branching logic that selects the correct build strategy
(host, pack, or s2i) for each runtime × local/remote combination.

This PR adds a focused, 15-subcase table-driven test for resolveBuilder
using struct literals — no viper setup, no mocks, no cluster, no network.

Trivial one-liner getter/accessor methods are intentionally not tested here,
as they add no meaningful coverage and only verify that Go's struct field
assignment works.

Changes

File Change
cmd/ci/config_test.go New — 1 table-driven test with 15 sub-cases

Tests added

TestResolveBuilder (15 sub-cases):
  go local         → host
  go remote        → pack
  node local/remote        → pack
  typescript local/remote  → pack
  rust local/remote        → pack
  quarkus local/remote     → pack
  springboot local/remote  → pack
  python local     → host
  python remote    → s2i
  unknown runtime  → error

How to verify

go test ./cmd/ci/... -v -run TestResolveBuilder

Expected output: all 15 sub-tests PASS, ok knative.dev/func/cmd/ci.

Checklist

  • Tests only — no production code changed
  • make test passes
  • make check passes
  • No new dependencies introduced

Copilot AI review requested due to automatic review settings April 1, 2026 19:10
@knative-prow
Copy link
Copy Markdown

knative-prow bot commented Apr 1, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

@knative-prow knative-prow bot requested review from dsimansk and jrangelramos April 1, 2026 19:10
@knative-prow knative-prow bot added size/L 🤖 PR changes 100-499 lines, ignoring generated files. needs-ok-to-test 🤖 Needs an org member to approve testing labels Apr 1, 2026
@knative-prow
Copy link
Copy Markdown

knative-prow bot commented Apr 1, 2026

Hi @Ankitsinghsisodya. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

Copy link
Copy Markdown

Copilot AI left a comment

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 for cmd/ci/config.go’s CIConfig accessors and the resolveBuilder helper to improve coverage without requiring viper setup, mocks, or external dependencies.

Changes:

  • Introduces cmd/ci/config_test.go with tests for CIConfig getter/path helpers.
  • Adds a table-driven test covering resolveBuilder runtime→builder selection and error behavior.

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

Add tests for CIConfig accessor methods and resolveBuilder helper
in cmd/ci/config.go.

Covered:
- FnGitHubWorkflowFilepath correctly joins fnRoot, workflow dir and filename
- OutputPath uses the default dir/filename constants
- Verbose, FnRuntime, FnBuilder simple getters
- resolveBuilder — all supported runtimes (go, node, typescript, rust,
  quarkus, springboot, python) both local and remote modes, plus error
  for unknown runtime
- All remaining bool accessors: RegistryLogin, SelfHostedRunner,
  RemoteBuild, WorkflowDispatch, TestStep, Force
- All string accessors: Branch, WorkflowName, KubeconfigSecret,
  RegistryLoginUrlVar, RegistryUserVar, RegistryPassSecret, RegistryUrlVar

Fixes zero-coverage on config.go:221, 226, 282, 286, 290.
@Ankitsinghsisodya Ankitsinghsisodya force-pushed the test/ci-config-accessors branch from 556ff32 to c119d3c Compare April 1, 2026 19:14
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 56.28%. Comparing base (e92b074) to head (726ed64).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3570      +/-   ##
==========================================
+ Coverage   55.52%   56.28%   +0.75%     
==========================================
  Files         180      180              
  Lines       20465    20465              
==========================================
+ Hits        11363    11518     +155     
+ Misses       7902     7749     -153     
+ Partials     1200     1198       -2     
Flag Coverage Δ
e2e 36.11% <ø> (-4.07%) ⬇️
e2e go 32.55% <ø> (ø)
e2e node 28.36% <ø> (ø)
e2e python 32.91% <ø> (ø)
e2e quarkus 28.50% <ø> (+0.02%) ⬆️
e2e rust 27.92% <ø> (ø)
e2e springboot 26.38% <ø> (+0.02%) ⬆️
e2e typescript 28.47% <ø> (ø)
e2e-config-ci 18.14% <ø> (ø)
integration 17.40% <ø> (ø)
unit macos-14 43.43% <ø> (+0.06%) ⬆️
unit macos-latest 43.43% <ø> (+0.06%) ⬆️
unit ubuntu-24.04-arm 43.63% <ø> (+0.05%) ⬆️
unit ubuntu-latest 44.31% <ø> (+0.06%) ⬆️
unit windows-latest 43.45% <ø> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Ankitsinghsisodya Ankitsinghsisodya marked this pull request as draft April 1, 2026 19:28
@knative-prow knative-prow bot added the do-not-merge/work-in-progress 🤖 PR should not merge because it is a work in progress. label Apr 1, 2026
Removed accessor tests for one-liner getters (Verbose, FnRuntime,
FnBuilder, BoolAccessors, StringAccessors, OutputPath,
FnGitHubWorkflowFilepath) — they test Go's struct assignment, not
any real logic.

Kept TestResolveBuilder (15 sub-cases) which covers the non-trivial
branching in resolveBuilder() across all runtimes × local/remote.
@knative-prow knative-prow bot added size/M 🤖 PR changes 30-99 lines, ignoring generated files. and removed size/L 🤖 PR changes 100-499 lines, ignoring generated files. labels Apr 1, 2026
@Ankitsinghsisodya Ankitsinghsisodya changed the title test: add unit coverage for ci config accessors test: add unit tests for resolveBuilder in cmd/ci Apr 1, 2026
@Ankitsinghsisodya Ankitsinghsisodya marked this pull request as ready for review April 1, 2026 22:24
@knative-prow knative-prow bot removed the do-not-merge/work-in-progress 🤖 PR should not merge because it is a work in progress. label Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ok-to-test 🤖 Needs an org member to approve testing size/M 🤖 PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add unit tests for resolveBuilder in cmd/ci/config.go

2 participants