backend: cmd: Add JSON serialization tests for ClusterReq#6101
backend: cmd: Add JSON serialization tests for ClusterReq#6101CygnusMaximillian wants to merge 1 commit into
Conversation
Signed-off-by: CygnusMaximillian <dprajjwal11@gmail.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: CygnusMaximillian The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
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. |
There was a problem hiding this comment.
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
TestClusterReqto exercise JSON marshal/unmarshal ofClusterReq.
| @@ -0,0 +1,35 @@ | |||
| package main | |||
| b, err := json.Marshal(req) | ||
| require.NoError(t, err) | ||
|
|
||
| var req2 ClusterReq | ||
|
|
||
| err = json.Unmarshal(b, &req2) | ||
| require.NoError(t, err) |
| 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"]) |
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.