From 4a73bd7c3ca35842a9fbc18e8bc049a2739e26a0 Mon Sep 17 00:00:00 2001 From: guoguangwu Date: Tue, 1 Aug 2023 16:44:33 +0800 Subject: [PATCH] chore: unnecessary use of fmt.Sprintf --- core/orchestrator_core_test.go | 10 ++--- frontend/crd/trident_mirror_relationship.go | 7 ++-- storage_attribute/storage_attribute_test.go | 8 ++-- storage_drivers/fake/fake.go | 2 +- storage_drivers/gcp/api/gcp_test.go | 42 +++++++++---------- storage_drivers/ontap/ontap_common.go | 2 +- storage_drivers/ontap/ontap_nas_qtree.go | 2 +- .../ontap/ontap_san_economy_test.go | 18 ++++---- 8 files changed, 45 insertions(+), 46 deletions(-) diff --git a/core/orchestrator_core_test.go b/core/orchestrator_core_test.go index bce3da793..9012219e6 100644 --- a/core/orchestrator_core_test.go +++ b/core/orchestrator_core_test.go @@ -3084,7 +3084,7 @@ func TestListVolumePublicationsError(t *testing.T) { orchestrator.bootstrapError = fmt.Errorf("some error") actualPubs, err := orchestrator.ListVolumePublications(context.Background()) - assert.NotNil(t, err, fmt.Sprintf("unexpected success listing volume publications")) + assert.NotNil(t, err, "unexpected success listing volume publications") assert.Empty(t, actualPubs, "non-empty publication list returned") } @@ -3190,7 +3190,7 @@ func TestListVolumePublicationsForVolumeError(t *testing.T) { orchestrator.bootstrapError = fmt.Errorf("some error") actualPubs, err := orchestrator.ListVolumePublicationsForVolume(context.Background(), fakePub.VolumeName) - assert.NotNil(t, err, fmt.Sprintf("unexpected success listing volume publications")) + assert.NotNil(t, err, "unexpected success listing volume publications") assert.Empty(t, actualPubs, "non-empty publication list returned") } @@ -3296,7 +3296,7 @@ func TestListVolumePublicationsForNodeError(t *testing.T) { orchestrator.bootstrapError = fmt.Errorf("some error") actualPubs, err := orchestrator.ListVolumePublicationsForNode(context.Background(), fakePub.NodeName) - assert.NotNil(t, err, fmt.Sprintf("unexpected success listing volume publications")) + assert.NotNil(t, err, "unexpected success listing volume publications") assert.Empty(t, actualPubs, "non-empty publication list returned") } @@ -3424,7 +3424,7 @@ func TestDeleteVolumePublicationNotFound(t *testing.T) { mockStoreClient.EXPECT().DeleteVolumePublication(coreCtx, fakePub).Return(nil).Times(1) err := orchestrator.DeleteVolumePublication(ctx(), fakePub.VolumeName, fakePub.NodeName) cachedPubs := orchestrator.volumePublications.Map() - assert.NoError(t, err, fmt.Sprintf("unexpected error deleting volume publication")) + assert.NoError(t, err, "unexpected error deleting volume publication") assert.Nil(t, cachedPubs[fakePub.VolumeName][fakePub.NodeName], "expected no cache entry") } @@ -3488,7 +3488,7 @@ func TestDeleteVolumePublicationError(t *testing.T) { mockStoreClient.EXPECT().DeleteVolumePublication(gomock.Any(), fakePub).Return(fmt.Errorf("some error")) err := orchestrator.DeleteVolumePublication(ctx(), fakePub.VolumeName, fakePub.NodeName) - assert.NotNil(t, err, fmt.Sprintf("unexpected success deleting volume publication")) + assert.NotNil(t, err, "unexpected success deleting volume publication") assert.False(t, errors.IsNotFoundError(err), "incorrect error type returned") assert.Equal(t, fakePub, orchestrator.volumePublications.Get(fakePub.VolumeName, fakePub.NodeName), "publication improperly removed/updated in cache") diff --git a/frontend/crd/trident_mirror_relationship.go b/frontend/crd/trident_mirror_relationship.go index 912563b21..0e31f6037 100644 --- a/frontend/crd/trident_mirror_relationship.go +++ b/frontend/crd/trident_mirror_relationship.go @@ -376,7 +376,7 @@ func (c *TridentCrdController) handleIndividualVolumeMapping( ) statusErr, ok := err.(*k8sapierrors.StatusError) if (ok && statusErr.Status().Reason == metav1.StatusReasonNotFound) || localPVC == nil { - message := fmt.Sprintf("Local PVC for TridentMirrorRelationship does not yet exist.") + message := "Local PVC for TridentMirrorRelationship does not yet exist." Logx(ctx).WithFields(logFields).WithField("PVC", localPVCName).Trace(message) // If PVC does not yet exist, do not update the TMR and retry later return nil, errors.ReconcileDeferredError(message) @@ -387,14 +387,13 @@ func (c *TridentCrdController) handleIndividualVolumeMapping( // Check if local PVC is bound to a PV localPV, _ := c.kubeClientset.CoreV1().PersistentVolumes().Get(ctx, localPVC.Spec.VolumeName, metav1.GetOptions{}) if localPV == nil || localPV.Spec.CSI == nil || localPV.Spec.CSI.VolumeAttributes == nil { - message := fmt.Sprintf("PV for local PVC for TridentMirrorRelationship does not yet exist.") + message := "PV for local PVC for TridentMirrorRelationship does not yet exist." Logx(ctx).WithFields(logFields).WithField("PVC", localPVCName).Trace(message) return nil, errors.ReconcileDeferredError(message) } // Check if PV has internal name set if localPV.Spec.CSI.VolumeAttributes["internalName"] == "" { - message := fmt.Sprintf( - "PV for local PVC for TridentMirrorRelationship does not yet have an internal volume name set.") + message := "PV for local PVC for TridentMirrorRelationship does not yet have an internal volume name set." Logx(ctx).WithFields(logFields).WithField("PVC", localPVCName).Trace(message) return nil, errors.ReconcileDeferredError(message) } diff --git a/storage_attribute/storage_attribute_test.go b/storage_attribute/storage_attribute_test.go index aecf1d87b..01d356a41 100644 --- a/storage_attribute/storage_attribute_test.go +++ b/storage_attribute/storage_attribute_test.go @@ -317,14 +317,14 @@ func TestCreateBackendStoragePoolsMapFromEncodedString(t *testing.T) { actualMap, _ := CreateBackendStoragePoolsMapFromEncodedString("backend1:pool1,pool2;backend2:pool3") targetMap := map[string][]string{"backend1": {"pool1", "pool2"}, "backend2": {"pool3"}} - assert.Equal(t, targetMap, actualMap, fmt.Sprintf("Test case failed")) + assert.Equal(t, targetMap, actualMap, "Test case failed") } func TestCreateBackendStoragePoolsMapFromEncodedStringNegative(t *testing.T) { _, actualErr := CreateBackendStoragePoolsMapFromEncodedString("backend1;backend2:pool3") expectedErr := fmt.Errorf("the encoded backend-storage pool string does not have the right format") - assert.Equal(t, expectedErr, actualErr, fmt.Sprintf("Test case failed")) + assert.Equal(t, expectedErr, actualErr, "Test case failed") } func TestBoolString(t *testing.T) { @@ -377,7 +377,7 @@ func TestUnmarshalRequestMapNil(t *testing.T) { _, actualErr := UnmarshalRequestMap(nil) expectedErr := error(nil) - assert.Equal(t, expectedErr, actualErr, fmt.Sprintf("Test case failed")) + assert.Equal(t, expectedErr, actualErr, "Test case failed") } func TestUnmarshalRequestMapNegative(t *testing.T) { @@ -398,7 +398,7 @@ func TestMarshalRequestMapNil(t *testing.T) { _, actualErr := MarshalRequestMap(nil) expectedErr := error(nil) - assert.Equal(t, expectedErr, actualErr, fmt.Sprintf("Test case failed")) + assert.Equal(t, expectedErr, actualErr, "Test case failed") } func TestCreateAttributeRequestFromAttributeValueNegative(t *testing.T) { diff --git a/storage_drivers/fake/fake.go b/storage_drivers/fake/fake.go index f8537a059..90a55762f 100644 --- a/storage_drivers/fake/fake.go +++ b/storage_drivers/fake/fake.go @@ -263,7 +263,7 @@ func (d *StorageDriver) Name() string { func (d *StorageDriver) BackendName() string { if d.Config.BackendName == "" { // Use the old naming scheme if no name is specified - return fmt.Sprintf("fake-#{Config.InstanceName}") + return "fake-#{Config.InstanceName}" } else { return d.Config.BackendName } diff --git a/storage_drivers/gcp/api/gcp_test.go b/storage_drivers/gcp/api/gcp_test.go index 428c34bab..0e4837e74 100644 --- a/storage_drivers/gcp/api/gcp_test.go +++ b/storage_drivers/gcp/api/gcp_test.go @@ -255,7 +255,7 @@ func TestClient_GetVersion(t *testing.T) { }) } - t.Run(fmt.Sprintf("GetVersion_invalidToken"), func(t *testing.T) { + t.Run("GetVersion_invalidToken", func(t *testing.T) { d := getGCPClientInvalidToken("srv.URL") _, _, err := d.GetVersion(ctx) assert.Error(t, err, "An error is expected when invalid token is used.") @@ -304,7 +304,7 @@ func TestClient_GetServiceLevels(t *testing.T) { }) } - t.Run(fmt.Sprintf("GetServiceLevels_InvalidToken"), func(t *testing.T) { + t.Run("GetServiceLevels_InvalidToken", func(t *testing.T) { d := getGCPClientInvalidToken("srv.URL") _, err := d.GetServiceLevels(ctx) assert.Error(t, err, "An error is expected when invalid token is used.") @@ -352,7 +352,7 @@ func TestClient_GetVolumes(t *testing.T) { }) } - t.Run(fmt.Sprintf("GetVolumes_InvalidToken"), func(t *testing.T) { + t.Run("GetVolumes_InvalidToken", func(t *testing.T) { d := getGCPClientInvalidToken("srv.URL") _, err := d.GetVolumes(ctx) assert.Error(t, err, "An error is expected when invalid token is used.") @@ -409,7 +409,7 @@ func TestClient_GetVolumeByName(t *testing.T) { }) } - t.Run(fmt.Sprintf("GetVolumeByName_InvalidToken"), func(t *testing.T) { + t.Run("GetVolumeByName_InvalidToken", func(t *testing.T) { d := getGCPClientInvalidToken("srv.URL") _, err := d.GetVolumeByName(ctx, "volumeName") assert.Error(t, err, "An error is expected when invalid token is used.") @@ -446,7 +446,7 @@ func TestClient_GetVolumeByCreationToken(t *testing.T) { }) } - t.Run(fmt.Sprintf("GetVolumeByCreationToken_InvalidToken"), func(t *testing.T) { + t.Run("GetVolumeByCreationToken_InvalidToken", func(t *testing.T) { d := getGCPClientInvalidToken("srv.URL") _, err := d.GetVolumeByCreationToken(ctx, "CreationToken") assert.Error(t, err, "An error is expected when invalid token is used.") @@ -494,7 +494,7 @@ func TestClient_VolumeExistsByCreationToken(t *testing.T) { }) } - t.Run(fmt.Sprintf("VolumeExistsByCreationToken_InvalidToken"), func(t *testing.T) { + t.Run("VolumeExistsByCreationToken_InvalidToken", func(t *testing.T) { d := getGCPClientInvalidToken("srv.URL") _, _, err := d.VolumeExistsByCreationToken(ctx, "CreationToken") assert.Error(t, err, "An error is expected when invalid token is used.") @@ -554,7 +554,7 @@ func TestClient_GetVolumeByID(t *testing.T) { }) } - t.Run(fmt.Sprintf("GetVolumeByID_InvalidToekn"), func(t *testing.T) { + t.Run("GetVolumeByID_InvalidToekn", func(t *testing.T) { d := getGCPClientInvalidToken("srv.URL") _, err := d.GetVolumeByID(ctx, "VolumeID") assert.Error(t, err, "An error is expected when invalid token is used.") @@ -634,7 +634,7 @@ func TestClient_CreateVolume(t *testing.T) { }) } - t.Run(fmt.Sprintf("CreateVolume_InvalidToken"), func(t *testing.T) { + t.Run("CreateVolume_InvalidToken", func(t *testing.T) { d := getGCPClientInvalidToken("srv.URL") err := d.CreateVolume(ctx, &VolumeCreateRequest{Name: "valid Vol"}) assert.Error(t, err, "An error is expected when invalid token is used.") @@ -667,7 +667,7 @@ func TestClient_RenameVolume(t *testing.T) { }) } - t.Run(fmt.Sprintf("RenameVolume_InvalidToken"), func(t *testing.T) { + t.Run("RenameVolume_InvalidToken", func(t *testing.T) { d := getGCPClientInvalidToken("srv.URL") _, err := d.RenameVolume(ctx, &Volume{Name: "oldVolume"}, "newVolume") assert.Error(t, err, "An error is expected when invalid token is used.") @@ -709,7 +709,7 @@ func TestClient_ChangeVolumeUnixPermissions(t *testing.T) { }) } - t.Run(fmt.Sprintf("ChangeVolumeUnixPermissions_InvalidToken"), func(t *testing.T) { + t.Run("ChangeVolumeUnixPermissions_InvalidToken", func(t *testing.T) { d := getGCPClientInvalidToken("srv.URL") _, err := d.ChangeVolumeUnixPermissions(ctx, &Volume{Name: "oldVolume"}, "ro") assert.Error(t, err, "An error is expected when invalid token is used.") @@ -751,7 +751,7 @@ func TestClient_RelabelVolume(t *testing.T) { }) } - t.Run(fmt.Sprintf("RelabelVolume_InvalidToken"), func(t *testing.T) { + t.Run("RelabelVolume_InvalidToken", func(t *testing.T) { d := getGCPClientInvalidToken("srv.URL") _, err := d.RelabelVolume(ctx, &Volume{Name: "oldVolume"}, []string{"rw"}) assert.Error(t, err, "An error is expected when invalid token is used.") @@ -793,7 +793,7 @@ func TestClient_RenameRelabelVolume(t *testing.T) { }) } - t.Run(fmt.Sprintf("RenameRelabelVolume_InvalidToken"), func(t *testing.T) { + t.Run("RenameRelabelVolume_InvalidToken", func(t *testing.T) { d := getGCPClientInvalidToken("srv.URL") _, err := d.RenameRelabelVolume(ctx, &Volume{Name: "oldVolume"}, "newVolume", []string{"rw"}) assert.Error(t, err, "An error is expected when invalid token is used.") @@ -835,7 +835,7 @@ func TestClient_ResizeVolume(t *testing.T) { }) } - t.Run(fmt.Sprintf("ResizeVolume_InvalidToken"), func(t *testing.T) { + t.Run("ResizeVolume_InvalidToken", func(t *testing.T) { d := getGCPClientInvalidToken("srv.URL") _, err := d.ResizeVolume(ctx, &Volume{Name: "oldVolume"}, 1024) assert.Error(t, err, "An error is expected when invalid token is used.") @@ -872,7 +872,7 @@ func TestClient_DeleteVolume(t *testing.T) { }) } - t.Run(fmt.Sprintf("DeleteVolume_InvalidToken"), func(t *testing.T) { + t.Run("DeleteVolume_InvalidToken", func(t *testing.T) { d := getGCPClientInvalidToken("srv.URL") err := d.DeleteVolume(ctx, &Volume{Name: "oldVolume"}) assert.Error(t, err, "An error is expected when invalid token is used.") @@ -912,7 +912,7 @@ func TestClient_GetSnapshotsForVolume(t *testing.T) { }) } - t.Run(fmt.Sprintf("GetSnapshotsForVolume_InvalidToken"), func(t *testing.T) { + t.Run("GetSnapshotsForVolume_InvalidToken", func(t *testing.T) { d := getGCPClientInvalidToken("srv.URL") _, err := d.GetSnapshotsForVolume(ctx, &Volume{Name: "oldVolume"}) assert.Error(t, err, "An error is expected when invalid token is used.") @@ -951,7 +951,7 @@ func TestClient_GetSnapshotForVolume(t *testing.T) { }) } - t.Run(fmt.Sprintf("GetSnapshotForVolume_InvalidToken"), func(t *testing.T) { + t.Run("GetSnapshotForVolume_InvalidToken", func(t *testing.T) { d := getGCPClientInvalidToken("srv.URL") _, err := d.GetSnapshotsForVolume(ctx, &Volume{Name: "oldVolume"}) assert.Error(t, err, "An error is expected when invalid token is used.") @@ -999,7 +999,7 @@ func TestClient_GetSnapshotByID(t *testing.T) { }) } - t.Run(fmt.Sprintf("GetSnapshotByID_InvalidToken"), func(t *testing.T) { + t.Run("GetSnapshotByID_InvalidToken", func(t *testing.T) { d := getGCPClientInvalidToken("srv.URL") _, err := d.GetSnapshotByID(ctx, "snapshotID") assert.Error(t, err, "An error is expected when invalid token is used.") @@ -1073,7 +1073,7 @@ func TestClient_CreateSnapshot(t *testing.T) { }) } - t.Run(fmt.Sprintf("CreateSnapshot_InvalidToken"), func(t *testing.T) { + t.Run("CreateSnapshot_InvalidToken", func(t *testing.T) { d := getGCPClientInvalidToken("srv.URL") err := d.CreateSnapshot(ctx, &SnapshotCreateRequest{Name: "testSnapshot"}) assert.Error(t, err, "An error is expected when invalid token is used.") @@ -1110,7 +1110,7 @@ func TestClient_RestoreSnapshot(t *testing.T) { }) } - t.Run(fmt.Sprintf("RestoreSnapshot_InvalidToken"), func(t *testing.T) { + t.Run("RestoreSnapshot_InvalidToken", func(t *testing.T) { d := getGCPClientInvalidToken("srv.URL") err := d.RestoreSnapshot(ctx, &Volume{Name: "SnapshotVolume"}, &Snapshot{Name: "testSnapshot"}) assert.Error(t, err, "An error is expected when invalid token is used.") @@ -1147,7 +1147,7 @@ func TestClient_DeleteSnapshot(t *testing.T) { }) } - t.Run(fmt.Sprintf("DeleteSnapshot_InvalidToken"), func(t *testing.T) { + t.Run("DeleteSnapshot_InvalidToken", func(t *testing.T) { d := getGCPClientInvalidToken("srv.URL") err := d.DeleteSnapshot(ctx, &Volume{Name: "SnapshotVolume"}, &Snapshot{Name: "testSnapshot"}) assert.Error(t, err, "An error is expected when invalid token is used.") @@ -1186,7 +1186,7 @@ func TestClient_GetPools(t *testing.T) { }) } - t.Run(fmt.Sprintf("GetPools_InvalidToken"), func(t *testing.T) { + t.Run("GetPools_InvalidToken", func(t *testing.T) { d := getGCPClientInvalidToken("srv.URL") _, err := d.GetVolumes(ctx) assert.Error(t, err, "An error is expected when invalid token is used.") diff --git a/storage_drivers/ontap/ontap_common.go b/storage_drivers/ontap/ontap_common.go index a1dcc4696..064961693 100644 --- a/storage_drivers/ontap/ontap_common.go +++ b/storage_drivers/ontap/ontap_common.go @@ -2763,7 +2763,7 @@ func LunUnmapIgroup(ctx context.Context, clientAPI api.OntapAPI, igroup, lunPath lunID, err := clientAPI.LunMapInfo(ctx, igroup, lunPath) if err != nil { - msg := fmt.Sprintf("error reading LUN maps") + msg := "error reading LUN maps" Logc(ctx).WithError(err).Error(msg) return fmt.Errorf(msg) } diff --git a/storage_drivers/ontap/ontap_nas_qtree.go b/storage_drivers/ontap/ontap_nas_qtree.go index 8918db7a3..42d647536 100644 --- a/storage_drivers/ontap/ontap_nas_qtree.go +++ b/storage_drivers/ontap/ontap_nas_qtree.go @@ -698,7 +698,7 @@ func (d *NASQtreeStorageDriver) CanSnapshot( return fmt.Errorf("invalid value for snapshotDir; %v", err) } if !snapshotDirBool { - return errors.UnsupportedError(fmt.Sprintf("snapshots cannot be taken if snapdir access is disabled")) + return errors.UnsupportedError("snapshots cannot be taken if snapdir access is disabled") } return nil diff --git a/storage_drivers/ontap/ontap_san_economy_test.go b/storage_drivers/ontap/ontap_san_economy_test.go index ac3fa3960..5f59d0f9f 100644 --- a/storage_drivers/ontap/ontap_san_economy_test.go +++ b/storage_drivers/ontap/ontap_san_economy_test.go @@ -3771,7 +3771,7 @@ func TestOntapSanEconomyInitialize(t *testing.T) { DriverContext: tridentconfig.ContextCSI, DebugTraceFlags: debugTraceFlags, } - commonConfigJSON := fmt.Sprintf(` + commonConfigJSON := ` { "managementLIF": "10.0.207.8", "dataLIF": "10.0.207.7", @@ -3783,7 +3783,7 @@ func TestOntapSanEconomyInitialize(t *testing.T) { "storagePrefix": "san-eco", "debugTraceFlags": {"method": true, "api": true}, "version":1 - }`) + }` secrets := map[string]string{ "clientcertificate": "dummy-certificate", } @@ -3828,7 +3828,7 @@ func TestOntapSanEconomyInitialize_InvalidConfig(t *testing.T) { DriverContext: tridentconfig.ContextCSI, DebugTraceFlags: debugTraceFlags, } - commonConfigJSON := fmt.Sprintf(`{invalid-json}`) + commonConfigJSON := `{invalid-json}` secrets := map[string]string{ "clientcertificate": "dummy-certificate", } @@ -3849,7 +3849,7 @@ func TestOntapSanEconomyInitialize_NoDataLIFs(t *testing.T) { DriverContext: tridentconfig.ContextCSI, DebugTraceFlags: debugTraceFlags, } - commonConfigJSON := fmt.Sprintf(` + commonConfigJSON := ` { "managementLIF": "10.0.207.8", "dataLIF": "10.0.207.7", @@ -3861,7 +3861,7 @@ func TestOntapSanEconomyInitialize_NoDataLIFs(t *testing.T) { "storagePrefix": "san-eco", "debugTraceFlags": {"method": true, "api": true}, "version":1 - }`) + }` secrets := map[string]string{ "clientcertificate": "dummy-certificate", } @@ -3967,7 +3967,7 @@ func TestOntapSanEconomyInitialize_OtherContext(t *testing.T) { DriverContext: tridentconfig.ContextCSI, DebugTraceFlags: debugTraceFlags, } - commonConfigJSON := fmt.Sprintf(` + commonConfigJSON := ` { "managementLIF": "10.0.207.8", "dataLIF": "10.0.207.7", @@ -3979,7 +3979,7 @@ func TestOntapSanEconomyInitialize_OtherContext(t *testing.T) { "storagePrefix": "san-eco", "debugTraceFlags": {"method": true, "api": true}, "version":1 - }`) + }` secrets := map[string]string{ "clientcertificate": "dummy-certificate", } @@ -4017,7 +4017,7 @@ func TestOntapSanEconomyInitialize_NoSVMAggregates(t *testing.T) { DriverContext: tridentconfig.ContextCSI, DebugTraceFlags: debugTraceFlags, } - commonConfigJSON := fmt.Sprintf(` + commonConfigJSON := ` { "managementLIF": "10.0.207.8", "dataLIF": "10.0.207.7", @@ -4029,7 +4029,7 @@ func TestOntapSanEconomyInitialize_NoSVMAggregates(t *testing.T) { "storagePrefix": "san-eco", "debugTraceFlags": {"method": true, "api": true}, "version":1 - }`) + }` secrets := map[string]string{ "clientcertificate": "dummy-certificate", }