Skip to content

[quality] unit tests for pkg/api projects and server_runtime helpers#19948

Merged
clubanderson merged 1 commit into
mainfrom
quality/test-api-projects-runtime
Jun 29, 2026
Merged

[quality] unit tests for pkg/api projects and server_runtime helpers#19948
clubanderson merged 1 commit into
mainfrom
quality/test-api-projects-runtime

Conversation

@clubanderson

Copy link
Copy Markdown
Collaborator

Test Improvement

Adds 14 test cases for two previously-untested source files in pkg/api:

projects_test.go (10 tests)

  • getProjectDashboards: known project returns expected dashboards, unknown project returns nil, empty string returns nil
  • isProjectEnabled: wildcard always matches, wildcard with empty active project, exact match, mismatch, empty active with non-wildcard, both empty, case-sensitive mismatch

server_runtime_test.go (7 tests)

  • Factory functions: newServerLifecycle, newAuthRuntime, newBackgroundServices, newQuantumWorkloadCache
  • quantumWorkloadCache.isRunning: env var disabled, env var forced-running, nil k8s client, cache TTL behavior

These target the first 2 of 15 untested files in pkg/api (currently at 60.5% coverage).

Fixes #19947


Filed by quality agent (ACMM L4/L6 — full mode)

Add 14 test cases for previously-untested pure functions in pkg/api:

- projects_test.go (10 tests): getProjectDashboards known/unknown/empty,
  isProjectEnabled wildcard/exact/mismatch/case-sensitive
- server_runtime_test.go (7 tests): factory functions, quantumWorkloadCache
  env var control (disabled, forced-running, nil-client), cache TTL behavior

These target 2 of the 15 untested source files in pkg/api (60.5% coverage).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: sec-check <sec-check@hive.kubestellar.io>
Copilot AI review requested due to automatic review settings June 29, 2026 20:11
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Jun 29, 2026
@kubestellar-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

@netlify

netlify Bot commented Jun 29, 2026

Copy link
Copy Markdown

Deploy Preview for kubestellarconsole canceled.

Name Link
🔨 Latest commit 0b433a9
🔍 Latest deploy log https://app.netlify.com/projects/kubestellarconsole/deploys/6a42d17e0117dc0008f239a3

@github-actions github-actions Bot added the ai-generated Pull request generated by AI label Jun 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🐝 Hi @clubanderson! I'm kubestellar-hive[bot], an automation bot for this repo.

Trusted users — org members and contributors with write access — can mention @kubestellar-hive in a comment to trigger repo automation.
On issues, that mention queues an automated fix attempt. On pull requests, it records extra context for existing automation.
This is not an interactive Q&A bot, so mentions should be treated as requests for automation rather than a conversation.

Automation may take a moment to start, and follow-up happens through workflow activity rather than chat replies.

@github-actions

Copy link
Copy Markdown
Contributor

👋 Hey @clubanderson — thanks for opening this PR!

🤖 This project is developed exclusively using AI coding assistants.

Please do not attempt to code anything for this project manually.
All contributions should be authored using an AI coding tool such as:

This ensures consistency in code style, architecture patterns, test coverage,
and commit quality across the entire codebase.


This is an automated message.

@kubestellar-prow kubestellar-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 29, 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 new Go unit tests in pkg/api to improve coverage for project dashboard presets/helpers and server runtime/quantum workload cache helpers, supporting the repo’s coverage-ratchet goals (Fixes #19947). CI will validate test/build status on the PR.

Changes:

  • Add tests for getProjectDashboards and isProjectEnabled helper behavior (including wildcard and empty-string cases).
  • Add tests covering server runtime factory constructors and quantumWorkloadCache.isRunning env-var overrides and cache behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
pkg/api/projects_test.go New tests for project dashboard preset lookup and project matching logic.
pkg/api/server_runtime_test.go New tests for server runtime factory helpers and quantum workload cache behavior.

Comment on lines +1 to +6
package api

import (
"testing"
)

Comment thread pkg/api/projects_test.go
Comment on lines +1 to +27
package api

import "testing"

func TestGetProjectDashboards_KnownProject(t *testing.T) {
dashboards := getProjectDashboards("kubestellar")
if dashboards == nil {
t.Fatal("expected non-nil dashboard list for 'kubestellar' project")
}
if len(dashboards) == 0 {
t.Fatal("expected non-empty dashboard list for 'kubestellar' project")
}
// Verify key dashboards are present
required := []string{"dashboard", "clusters", "compliance", "security", "workloads"}
for _, r := range required {
found := false
for _, d := range dashboards {
if d == r {
found = true
break
}
}
if !found {
t.Errorf("expected dashboard %q in kubestellar presets, not found", r)
}
}
}
Comment on lines +84 to +100
func TestQuantumWorkloadCache_CacheTTL(t *testing.T) {
t.Setenv("QUANTUM_WORKLOAD_DISABLED", "")
t.Setenv("QUANTUM_WORKLOAD_RUNNING", "")
qc := newQuantumWorkloadCache()

// First call populates cache
result1 := qc.isRunning(nil)
if result1 {
t.Error("expected false with nil client")
}

// Second call should use cache (refreshedAt is recent)
result2 := qc.isRunning(nil)
if result2 != result1 {
t.Error("expected cached result to match first result")
}
}
@clubanderson clubanderson merged commit ee73541 into main Jun 29, 2026
36 of 42 checks passed
@kubestellar-prow kubestellar-prow Bot deleted the quality/test-api-projects-runtime branch June 29, 2026 21:09
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution! Your PR has been merged.

Check out what's new:

Stay connected: Slack #kubestellar-dev | Multi-Cluster Survey

@github-actions

Copy link
Copy Markdown
Contributor

Post-merge build verification passed

Both Go and frontend builds compiled successfully against merge commit ee7354102cf69cf33fba375d565a624893420a39.

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

Labels

ai-generated Pull request generated by AI dco-signoff: yes Indicates the PR's author has signed the DCO. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tier/1-lightweight

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[quality] pkg/api at 60.5% coverage — 15 source files lack dedicated tests

2 participants