From ba7c72c19646da4ec49c819512adffa44b1d8b6c Mon Sep 17 00:00:00 2001 From: Jimmi Dyson Date: Wed, 22 May 2024 15:52:33 +0100 Subject: [PATCH] refactor: Delete unused code --- api/v1alpha1/zz_generated.deepcopy.go | 4 +- api/variables/enums.go | 18 ------- api/variables/eums_test.go | 70 --------------------------- api/variables/json.go | 22 ++++----- 4 files changed, 13 insertions(+), 101 deletions(-) delete mode 100644 api/variables/enums.go delete mode 100644 api/variables/eums_test.go diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index ba57d9a6d..1fbf78849 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -1144,7 +1144,9 @@ func (in *NutanixNodeSpec) DeepCopy() *NutanixNodeSpec { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *NutanixPrismCentralEndpointCredentials) DeepCopyInto(out *NutanixPrismCentralEndpointCredentials) { +func (in *NutanixPrismCentralEndpointCredentials) DeepCopyInto( + out *NutanixPrismCentralEndpointCredentials, +) { *out = *in out.SecretRef = in.SecretRef } diff --git a/api/variables/enums.go b/api/variables/enums.go deleted file mode 100644 index ce2daf8e5..000000000 --- a/api/variables/enums.go +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2023 Nutanix. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package variables - -import ( - apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" -) - -func MustMarshalValuesToEnumJSON[T any](vals ...T) []apiextensionsv1.JSON { - enumJSON := make([]apiextensionsv1.JSON, 0, len(vals)) - - for _, v := range vals { - enumJSON = append(enumJSON, *MustMarshal(v)) - } - - return enumJSON -} diff --git a/api/variables/eums_test.go b/api/variables/eums_test.go deleted file mode 100644 index 55e3a7b73..000000000 --- a/api/variables/eums_test.go +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2023 Nutanix. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 -package variables - -import ( - "testing" - - "github.com/onsi/gomega" -) - -func TestValuesToEnumJSON(t *testing.T) { - t.Parallel() - - testCases := []struct { - name string - input []interface{} - expected []interface{} - }{{ - name: "Empty input", - input: []any{}, - expected: []interface{}{}, - }, { - name: "Single value", - input: []any{"value1"}, - expected: []interface{}{`"value1"`}, - }, { - name: "Multiple values", - input: []interface{}{"value1", "value2", "value3"}, - expected: []interface{}{`"value1"`, `"value2"`, `"value3"`}, - }, { - name: "Multiple integer values", - input: []interface{}{1, 2, 3}, - expected: []interface{}{`1`, `2`, `3`}, - }, { - name: "Multiple integer array values", - input: []interface{}{[]int{1, 2}, []int{2, 3}, []int{49, 64}}, - expected: []interface{}{`[1,2]`, `[2,3]`, `[49,64]`}, - }, { - name: "Multiple string array values", - input: []interface{}{ - []string{"value1", "value2"}, - []string{"value2", "value3"}, - []string{"value49", "value64"}, - }, - expected: []interface{}{ - `["value1","value2"]`, - `["value2","value3"]`, - `["value49","value64"]`, - }, - }} - - for i := range testCases { - tt := testCases[i] - - t.Run(tt.name, func(t *testing.T) { - t.Parallel() - - g := gomega.NewWithT(t) - - // Call the function under test - jsonData := MustMarshalValuesToEnumJSON(tt.input...) - - // Assert the result - g.Expect(jsonData).To(gomega.HaveLen(len(tt.expected))) - for i, expected := range tt.expected { - g.Expect(string(jsonData[i].Raw)).To(gomega.Equal(expected)) - } - }) - } -} diff --git a/api/variables/json.go b/api/variables/json.go index 625803f54..871a8f65b 100644 --- a/api/variables/json.go +++ b/api/variables/json.go @@ -13,15 +13,6 @@ import ( "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1" ) -func MustMarshal(val any) *apiextensionsv1.JSON { - marshaled, err := json.Marshal(val) - if err != nil { - panic(fmt.Errorf("failed to marshal enum value: %w", err)) - } - - return &apiextensionsv1.JSON{Raw: marshaled} -} - func MarshalToClusterVariable[T any](name string, obj T) (*clusterv1.ClusterVariable, error) { marshaled, err := json.Marshal(obj) if err != nil { @@ -33,7 +24,9 @@ func MarshalToClusterVariable[T any](name string, obj T) (*clusterv1.ClusterVari }, nil } -func UnmarshalClusterConfigVariable(clusterVariables []clusterv1.ClusterVariable) (*ClusterConfigSpec, error) { +func UnmarshalClusterConfigVariable( + clusterVariables []clusterv1.ClusterVariable, +) (*ClusterConfigSpec, error) { variableName := v1alpha1.ClusterConfigVariableName clusterConfig := GetClusterVariableByName(variableName, clusterVariables) if clusterConfig == nil { @@ -48,7 +41,9 @@ func UnmarshalClusterConfigVariable(clusterVariables []clusterv1.ClusterVariable return spec, nil } -func UnmarshalWorkerConfigVariable(clusterVariables []clusterv1.ClusterVariable) (*WorkerNodeConfigSpec, error) { +func UnmarshalWorkerConfigVariable( + clusterVariables []clusterv1.ClusterVariable, +) (*WorkerNodeConfigSpec, error) { variableName := v1alpha1.WorkerConfigVariableName workerConfig := GetClusterVariableByName(variableName, clusterVariables) if workerConfig == nil { @@ -72,7 +67,10 @@ func UnmarshalClusterVariable[T any](clusterVariable *clusterv1.ClusterVariable, return nil } -func GetClusterVariableByName(name string, clusterVariables []clusterv1.ClusterVariable) *clusterv1.ClusterVariable { +func GetClusterVariableByName( + name string, + clusterVariables []clusterv1.ClusterVariable, +) *clusterv1.ClusterVariable { for _, clusterVar := range clusterVariables { if clusterVar.Name == name { return &clusterVar