From 4a80550e1ad86e691c6de8ef254fd086a892dccb Mon Sep 17 00:00:00 2001 From: Ying Zhang Date: Mon, 8 Dec 2025 14:41:14 +0800 Subject: [PATCH] Fix the lint failures --- pkg/api/presenters/cluster_test.go | 9 ++++++--- pkg/api/presenters/node_pool_test.go | 6 ++++-- pkg/middleware/schema_validation.go | 4 ++-- test/integration/clusters_test.go | 10 ++++------ test/integration/integration_test.go | 2 +- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/pkg/api/presenters/cluster_test.go b/pkg/api/presenters/cluster_test.go index bd93699..9d6293b 100644 --- a/pkg/api/presenters/cluster_test.go +++ b/pkg/api/presenters/cluster_test.go @@ -86,7 +86,8 @@ func TestConvertCluster_WithLabels(t *testing.T) { Expect(err).To(BeNil()) var resultLabels map[string]string - json.Unmarshal(result.Labels, &resultLabels) + err = json.Unmarshal(result.Labels, &resultLabels) + Expect(err).To(BeNil()) Expect(resultLabels["env"]).To(Equal("production")) Expect(resultLabels["team"]).To(Equal("platform")) } @@ -106,7 +107,8 @@ func TestConvertCluster_WithoutLabels(t *testing.T) { Expect(err).To(BeNil()) var resultLabels map[string]string - json.Unmarshal(result.Labels, &resultLabels) + err = json.Unmarshal(result.Labels, &resultLabels) + Expect(err).To(BeNil()) Expect(len(resultLabels)).To(Equal(0)) // Empty map } @@ -136,7 +138,8 @@ func TestConvertCluster_SpecMarshaling(t *testing.T) { Expect(err).To(BeNil()) var resultSpec map[string]interface{} - json.Unmarshal(result.Spec, &resultSpec) + err = json.Unmarshal(result.Spec, &resultSpec) + Expect(err).To(BeNil()) Expect(resultSpec["provider"]).To(Equal("gcp")) Expect(resultSpec["region"]).To(Equal("us-east1")) diff --git a/pkg/api/presenters/node_pool_test.go b/pkg/api/presenters/node_pool_test.go index f1d1d2f..e39229f 100644 --- a/pkg/api/presenters/node_pool_test.go +++ b/pkg/api/presenters/node_pool_test.go @@ -124,7 +124,8 @@ func TestConvertNodePool_WithLabels(t *testing.T) { Expect(err).To(BeNil()) var resultLabels map[string]string - json.Unmarshal(result.Labels, &resultLabels) + err = json.Unmarshal(result.Labels, &resultLabels) + Expect(err).To(BeNil()) Expect(resultLabels["environment"]).To(Equal("production")) Expect(resultLabels["team"]).To(Equal("platform")) Expect(resultLabels["region"]).To(Equal("us-east")) @@ -144,7 +145,8 @@ func TestConvertNodePool_WithoutLabels(t *testing.T) { Expect(err).To(BeNil()) var resultLabels map[string]string - json.Unmarshal(result.Labels, &resultLabels) + err = json.Unmarshal(result.Labels, &resultLabels) + Expect(err).To(BeNil()) Expect(len(resultLabels)).To(Equal(0)) // Empty map } diff --git a/pkg/middleware/schema_validation.go b/pkg/middleware/schema_validation.go index 286d7b9..da77772 100644 --- a/pkg/middleware/schema_validation.go +++ b/pkg/middleware/schema_validation.go @@ -23,7 +23,7 @@ func handleValidationError(w http.ResponseWriter, r *http.Request, err *errors.S // Write JSON error response w.Header().Set("Content-Type", "application/json") w.WriteHeader(err.HttpCode) - json.NewEncoder(w).Encode(err.AsOpenapiError(operationID)) + _ = json.NewEncoder(w).Encode(err.AsOpenapiError(operationID)) } // SchemaValidationMiddleware validates cluster and nodepool spec fields against OpenAPI schemas @@ -44,7 +44,7 @@ func SchemaValidationMiddleware(validator *validators.SchemaValidator) func(http handleValidationError(w, r, serviceErr) return } - r.Body.Close() + _ = r.Body.Close() // Restore the request body for the next handler r.Body = io.NopCloser(bytes.NewBuffer(bodyBytes)) diff --git a/test/integration/clusters_test.go b/test/integration/clusters_test.go index 39ac38e..700a57d 100644 --- a/test/integration/clusters_test.go +++ b/test/integration/clusters_test.go @@ -320,7 +320,7 @@ func TestClusterSchemaValidation(t *testing.T) { jwtToken := ctx.Value(openapi.ContextAccessToken) - resp2, err := resty.R(). + resp2, _ := resty.R(). SetHeader("Content-Type", "application/json"). SetHeader("Authorization", fmt.Sprintf("Bearer %s", jwtToken)). SetBody(invalidTypeJSON). @@ -330,7 +330,7 @@ func TestClusterSchemaValidation(t *testing.T) { t.Logf("Schema validation correctly rejected invalid spec type") // Verify error response contains details var errorResponse openapi.Error - json.Unmarshal(resp2.Body(), &errorResponse) + _ = json.Unmarshal(resp2.Body(), &errorResponse) Expect(errorResponse.Code).ToNot(BeNil()) Expect(errorResponse.Reason).ToNot(BeNil()) } else { @@ -389,7 +389,7 @@ func TestClusterSchemaValidationWithProviderSchema(t *testing.T) { _, resp, err := client.DefaultAPI.PostCluster(ctx).ClusterCreateRequest(invalidInput).Execute() Expect(err).To(HaveOccurred(), "Should reject spec with missing required field") Expect(resp.StatusCode).To(Equal(http.StatusBadRequest)) - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() // Parse error response to verify field-level details bodyBytes, err := io.ReadAll(resp.Body) @@ -539,7 +539,6 @@ func TestClusterList_OrderByName(t *testing.T) { fmt.Sprintf("%s-bravo", testPrefix), } - var createdClusters []openapi.Cluster for _, name := range names { clusterInput := openapi.ClusterCreateRequest{ Kind: "Cluster", @@ -547,9 +546,8 @@ func TestClusterList_OrderByName(t *testing.T) { Spec: map[string]interface{}{"test": "value"}, } - cluster, _, err := client.DefaultAPI.PostCluster(ctx).ClusterCreateRequest(clusterInput).Execute() + _, _, err := client.DefaultAPI.PostCluster(ctx).ClusterCreateRequest(clusterInput).Execute() Expect(err).NotTo(HaveOccurred(), "Failed to create cluster %s", name) - createdClusters = append(createdClusters, *cluster) } // List with orderBy=name asc diff --git a/test/integration/integration_test.go b/test/integration/integration_test.go index e072c68..b8fe42a 100755 --- a/test/integration/integration_test.go +++ b/test/integration/integration_test.go @@ -38,7 +38,7 @@ func TestMain(m *testing.M) { if _, err := os.Stat(schemaPath); err != nil { glog.Warningf("Schema file not found at %s: %v, skipping OPENAPI_SCHEMA_PATH setup", schemaPath, err) } else { - os.Setenv("OPENAPI_SCHEMA_PATH", schemaPath) + _ = os.Setenv("OPENAPI_SCHEMA_PATH", schemaPath) glog.Infof("Set OPENAPI_SCHEMA_PATH=%s for integration tests", schemaPath) } }