Skip to content

backend: cmd: Add JSON serialization tests for ClusterReq#6101

Open
CygnusMaximillian wants to merge 1 commit into
kubernetes-sigs:mainfrom
CygnusMaximillian:backend/cmdClusterTest
Open

backend: cmd: Add JSON serialization tests for ClusterReq#6101
CygnusMaximillian wants to merge 1 commit into
kubernetes-sigs:mainfrom
CygnusMaximillian:backend/cmdClusterTest

Conversation

@CygnusMaximillian

Copy link
Copy Markdown
Contributor

PR Description

Title: backend: Add JSON serialization tests for ClusterReq Body: Summary: Adds a unit test to verify the JSON marshaling and unmarshaling of the ClusterReq struct in cluster.go. Related Issue: Fixes #6100

Changes:

Added backend/cmd/cluster_test.go with TestClusterReq

Steps to Test:

Navigate to the backend directory.
Run npm run backend:test and ensure all tests pass. Notes for the Reviewer: A small, isolated test to incrementally improve coverage for the cmd package.

Signed-off-by: CygnusMaximillian <dprajjwal11@gmail.com>
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jun 19, 2026
@vtushar06

Copy link
Copy Markdown
Contributor

Nice @CygnusMaximillian, One thing to round it out: KubeConfig isn't covered here, and a zero-value ClusterReq would also verify the omitempty fields drop from the JSON. Both could go in the same test.

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 a backend unit test in backend/cmd to cover JSON serialization behavior for the ClusterReq request struct (used by the cmd/server layer), aiming to prevent regressions when its JSON tags or field types change.

Changes:

  • Add TestClusterReq to exercise JSON marshal/unmarshal of ClusterReq.

@@ -0,0 +1,35 @@
package main
Comment on lines +22 to +28
b, err := json.Marshal(req)
require.NoError(t, err)

var req2 ClusterReq

err = json.Unmarshal(b, &req2)
require.NoError(t, err)
Comment on lines +30 to +34
assert.Equal(t, *req.Name, *req2.Name)
assert.Equal(t, *req.Server, *req2.Server)
assert.Equal(t, req.InsecureSkipTLSVerify, req2.InsecureSkipTLSVerify)
assert.Equal(t, string(req.CertificateAuthorityData), string(req2.CertificateAuthorityData))
assert.Equal(t, req.Metadata["key"], req2.Metadata["key"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

backend :Missing test coverage for ClusterReq serialization in cmd/cluster.go

4 participants