refactor(general): minor miscellaneous cleanups (#4074)

Cleanups:

- use non-format variants of Log/Print with no additional args;
- fold in Fprintf call with no args into the following one;
- add missing arg placeholder in format strings;
- use require.Positive instead of Greater(..., 0);
- rename function to fillWithZeros to avoid collision with builtin clear;
- define type for context key to avoid collisions.
This commit is contained in:
Julio López authored and GitHub committed 2024-08-25 22:10:46 -07:00
1 parent 6902738e0d
commit 948162dce5
11 files changed
+22 -22

No files matched your search

+4 -5
View File
@@ -96,7 +96,7 @@ func (l *jsonList) begin(o *jsonOutput) {
l.o = o
if o.jsonOutput {
fmt.Fprintf(l.o.out, "[") //nolint:errcheck
fmt.Fprint(l.o.out, "[") //nolint:errcheck
if !o.jsonIndent {
l.separator = "\n "
@@ -107,16 +107,15 @@ func (l *jsonList) begin(o *jsonOutput) {
func (l *jsonList) end() {
if l.o.jsonOutput {
if !l.o.jsonIndent {
fmt.Fprintf(l.o.out, "\n") //nolint:errcheck
fmt.Fprint(l.o.out, "\n") //nolint:errcheck
}
fmt.Fprintf(l.o.out, "]") //nolint:errcheck
fmt.Fprint(l.o.out, "]") //nolint:errcheck
}
}
func (l *jsonList) emit(v interface{}) {
fmt.Fprintf(l.o.out, l.separator) //nolint:errcheck
fmt.Fprintf(l.o.out, "%s", l.o.jsonBytes(v)) //nolint:errcheck
fmt.Fprintf(l.o.out, "%s%s", l.separator, l.o.jsonBytes(v)) //nolint:errcheck
if l.o.jsonIndent {
l.separator = ","
+1 -1
View File
@@ -314,7 +314,7 @@ func TestGatherBytesReaderAtVariableInputBufferSizes(t *testing.T) {
// write the generated data
n, err := preWrt.Write(buf)
require.NoErrorf(t, err, "Write() faiiled, inputBufferSize: %8", tc.inputBufferSize)
require.NoErrorf(t, err, "Write() faiiled, inputBufferSize: %v", tc.inputBufferSize)
require.Equalf(t, defaultAllocator.chunkSize, preWrt.alloc.chunkSize,
"this test expects that the default-allocator will be used, but we are using: %#v", preWrt.alloc)
+1 -1
View File
@@ -53,7 +53,7 @@ func TestLogManager_AutoFlush(t *testing.T) {
var b [1024]byte
rand.Read(b[:])
l.Infof(hex.EncodeToString(b[:]))
l.Info(hex.EncodeToString(b[:]))
}
w.Wait(ctx)
+1 -1
View File
@@ -748,7 +748,7 @@ func compareMetadata(tb testing.TB, a, b versionMetadata) {
// deletion-marker metadata is not returned by the delete blob operation,
// and can only be retrieved later by listing versions.
if !a.IsDeleteMarker {
require.Equalf(tb, a.Version, b.Version, "blob versions do not match a:%v b:v", a, b)
require.Equalf(tb, a.Version, b.Version, "blob versions do not match a:%v b:%v", a, b)
}
}
+1 -1
View File
@@ -833,7 +833,7 @@ func (bm *WriteManager) WriteContent(ctx context.Context, data gather.Bytes, pre
logbuf.AppendInt64(previousWriteTime)
}
bm.log.Debugf(logbuf.String())
bm.log.Debug(logbuf.String())
return contentID, bm.addToPackUnlocked(ctx, contentID, data, false, comp, previousWriteTime, mp)
}
+1 -1
View File
@@ -144,7 +144,7 @@ func (sm *SharedManager) preparePackDataContent(mp format.MutableParameters, pp
sb.AppendUint32(info.PackedLength)
sb.AppendString(" d:")
sb.AppendBoolean(info.Deleted)
sm.log.Debugf(sb.String())
sm.log.Debug(sb.String())
packFileIndex.Add(info)
}
+2 -2
View File
@@ -179,7 +179,7 @@ func (r *ReedSolomonCrcECC) Encrypt(input gather.Bytes, _ []byte, output *gather
// WriteBuffer does not clear the data, so we must clear the padding
if lengthSize+len(copied) < len(inputBytes) {
clear(inputBytes[lengthSize+len(copied):])
fillWithZeros(inputBytes[lengthSize+len(copied):])
}
// Compute and store ECC + checksum
@@ -261,7 +261,7 @@ func (r *ReedSolomonCrcECC) Decrypt(input gather.Bytes, _ []byte, output *gather
// WriteBuffer does not clear the data, so we must clear the padding
if len(copied) < len(inputBytes) {
clear(inputBytes[len(copied):])
fillWithZeros(inputBytes[len(copied):])
}
eccBytes := inputBytes[:parityPlusCrcSizeInBlock*sizes.Blocks]
+3 -3
View File
@@ -34,9 +34,9 @@ func applyPercent(val int, percent float32) int {
return int(math.Floor(float64(val) * float64(percent)))
}
func clear(bytes []byte) {
for i := range bytes {
bytes[i] = 0
func fillWithZeros(b []byte) {
for i := range b {
b[i] = 0
}
}
+1 -1
View File
@@ -740,7 +740,7 @@ func TestParallelUploadUploadsBlobsInParallel(t *testing.T) {
require.NoError(t, th.repo.Flush(ctx))
require.Greater(t, maxParallelCalls.Load(), int32(0))
require.Positive(t, maxParallelCalls.Load())
}
func randomBytes(n int64) []byte {
@@ -218,7 +218,7 @@ func TestConsistencyWhenKill9AfterModify(t *testing.T) {
o, err := cmd.CombinedOutput()
require.NoError(t, err)
t.Logf(string(o))
t.Log(string(o))
// create snapshot with StderrPipe
cmd = exec.Command(kopiaExe, "snap", "create", newDir, "--json", "--parallel=1")
@@ -240,9 +240,8 @@ func TestConsistencyWhenKill9AfterModify(t *testing.T) {
stdout, err := bm.RestoreGivenOrRandomSnapshot("", restoreDir)
require.NoError(t, err)
t.Logf(stdout)
t.Logf("Compare restored data and original data:")
t.Log(stdout)
t.Log("Compare restored data and original data:")
CompareDirs(t, restoreDir, cmpDir)
}
@@ -267,7 +266,7 @@ func killOnCondition(t *testing.T, cmd *exec.Cmd) {
for scanner.Scan() {
output := scanner.Text()
t.Logf(output)
t.Log(output)
// Check if the output contains the "hashing" etc.
if strings.Contains(output, "hashing") && strings.Contains(output, "hashed") && strings.Contains(output, "uploaded") {
@@ -12,7 +12,9 @@ import (
const nameLen int = 2
var clientKey = struct{}{}
type clientKeyT struct{}
var clientKey clientKeyT
// Client is a unique client for use in multiclient robustness tests.
type Client struct {