Resolves #
- Introduced comprehensive unit tests for the KC Agent HTTP translation layer (
pkg/agent/server_http.go) by establishing a new test suite file:pkg/agent/server_http_test.go. - Enforces reliability and correctly scoped sanitization for translation of cluster payloads towards external REST interfaces.
- Added
TestMapK8sErrorToHTTPto verifymapK8sErrorToHTTPproperly intercepts native Kubernetes API errors (e.g.,StatusNotFound,StatusForbidden) and translates them into appropriate HTTP status codes (404, 403, 409). - Added
TestResourceHandlers_QueryExtractionproviding a mockk8s.MultiClusterClientutilizingfakek8s.NewSimpleClientsetto intercepthandleNodesHTTPandhandleDeploymentsHTTP, verifying that?cluster=and?namespace=parameters are predictably passed from HTTP request structs to the fake client. - Added
TestMutationLogic_CreateNamespaceHTTPto verify thecreateNamespaceHTTPhandler reliably decodes JSON POST payloads and executes the native Kubernetesk8sClient.CreateNamespaceAPI underneath. - Added
TestMutationLogic_CreateServiceAccountHTTPto verify thehandleServiceAccountsHTTPcomponent reliably translates simulated POST payloads directly into KubernetesCreateActionpayloads.
Please ensure the following before submitting your PR:
- I used a coding agent (Claude Code, Copilot, Gemini, or Codex) to generate/review this code
- I have reviewed the project's contribution guidelines
- New cards target console-marketplace, not this repo
- isDemoData is wired correctly (cards show Demo badge when using demo data)
- I have written unit tests for the changes (if applicable)
- I have tested the changes locally and ensured they work as expected
- All commits are signed with DCO (
git commit -s)
$ go test -v -run "TestMapK8sErrorToHTTP|TestResourceHandlers_QueryExtraction|TestMutationLogic_" ./pkg/agent/...
=== RUN TestMapK8sErrorToHTTP
--- PASS: TestMapK8sErrorToHTTP/AlreadyExists (0.00s)
--- PASS: TestMapK8sErrorToHTTP/Forbidden (0.00s)
--- PASS: TestMapK8sErrorToHTTP/NotFound (0.00s)
...
=== RUN TestResourceHandlers_QueryExtraction
--- PASS: TestResourceHandlers_QueryExtraction/handleNodesHTTP (0.00s)
--- PASS: TestResourceHandlers_QueryExtraction/handleDeploymentsHTTP (0.00s)
=== RUN TestMutationLogic_CreateNamespaceHTTP
--- PASS: TestMutationLogic_CreateNamespaceHTTP (0.00s)
=== RUN TestMutationLogic_CreateServiceAccountHTTP
--- PASS: TestMutationLogic_CreateServiceAccountHTTP (0.00s)
PASS
- The
fakek8sclient library provides an easy and precise way to establish API testing interceptors directly instead of mocking the entire struct manually. We extractfakeCS.Actions()to review exactly how our logic interacts internally withclitesting.