Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: unnecessary use of fmt.Sprintf #847

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions core/orchestrator_core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -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")
}

Expand Down Expand Up @@ -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")
}

Expand Down Expand Up @@ -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")
}

Expand Down Expand Up @@ -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")
Expand Down
7 changes: 3 additions & 4 deletions frontend/crd/trident_mirror_relationship.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
Expand Down
8 changes: 4 additions & 4 deletions storage_attribute/storage_attribute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion storage_drivers/fake/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
42 changes: 21 additions & 21 deletions storage_drivers/gcp/api/gcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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.")
Expand Down
2 changes: 1 addition & 1 deletion storage_drivers/ontap/ontap_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion storage_drivers/ontap/ontap_nas_qtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading