Skip to content

Commit bdba4bd

Browse files
committed
fix: go modernize fix tests
1 parent 06ae46d commit bdba4bd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+100
-161
lines changed

cmd/admin-bucket-remote-add_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ func TestGetBandwidthInBytes(t *testing.T) {
121121
}
122122
t.Parallel()
123123
for _, tt := range tests {
124-
tt := tt
125124
t.Run(tt.name, func(t *testing.T) {
126125
if got, err := getBandwidthInBytes(tt.args.bandwidthStr); err != nil || got != tt.want {
127126
t.Errorf("getBandwidthInBytes() = %v, want %v", got, tt.want)

cmd/admin-decom-status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func mainAdminDecommissionStatus(ctx *cli.Context) error {
125125
}
126126

127127
dspOrder := []col{colGreen} // Header
128-
for i := 0; i < len(poolStatuses); i++ {
128+
for range poolStatuses {
129129
dspOrder = append(dspOrder, colGrey)
130130
}
131131
var printColors []*color.Color

cmd/admin-replicate-resync-status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ func (m *resyncMetricsUI) View() string {
206206
table.SetNoWhiteSpace(true)
207207

208208
var data [][]string
209-
addLine := func(prefix string, value interface{}) {
209+
addLine := func(prefix string, value any) {
210210
data = append(data, []string{
211211
prefix,
212212
whiteStyle.Render(fmt.Sprint(value)),

cmd/admin-replicate-status.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,10 +426,7 @@ func (i srStatus) String() string {
426426
currDowntime = UTCNow().Sub(m.LastOnline)
427427
}
428428
// normalize because total downtime is calculated at server side at heartbeat interval, may be slightly behind
429-
totalDowntime := m.TotalDowntime
430-
if currDowntime > totalDowntime {
431-
totalDowntime = currDowntime
432-
}
429+
totalDowntime := max(currDowntime, m.TotalDowntime)
433430
var linkStatus string
434431
if m.Online {
435432
linkStatus = healthDot + fmt.Sprintf(" online (total downtime: %s)", timeDurationToHumanizedDuration(totalDowntime).String())

cmd/admin-scanner-status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ func (m *scannerMetricsUI) View() string {
397397
writtenRows++
398398
}
399399
_ = addRow
400-
addRowF := func(format string, vals ...interface{}) {
400+
addRowF := func(format string, vals ...any) {
401401
s := fmt.Sprintf(format, vals...)
402402
table.Append([]string{s})
403403
writtenRows++

cmd/admin-service-restart.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func (m *serviceRestartUI) View() string {
173173

174174
func initServiceRestartUI(rowCount int, currentCh chan serviceRestartMessage) *serviceRestartUI {
175175
var printColors []*color.Color
176-
for i := 0; i < rowCount; i++ {
176+
for range rowCount {
177177
printColors = append(printColors, getPrintCol(colGreen))
178178
}
179179

cmd/admin-user-svcacct-add.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ func generateCredentials() (accessKey, secretKey string, err *probe.Error) {
244244
if e != nil {
245245
return "", "", probe.NewError(e)
246246
}
247-
for i := 0; i < accessKeyMaxLen; i++ {
247+
for i := range accessKeyMaxLen {
248248
keyBytes[i] = alphaNumericTable[keyBytes[i]%alphaNumericTableLen]
249249
}
250250
accessKey = string(keyBytes)

cmd/anonymous-main.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ func (s anonymousRules) JSON() string {
116116

117117
// anonymousMessage is container for anonymous command on bucket success and failure messages.
118118
type anonymousMessage struct {
119-
Operation string `json:"operation"`
120-
Status string `json:"status"`
121-
Bucket string `json:"bucket"`
122-
Perms accessPerms `json:"permission"`
123-
Anonymous map[string]interface{} `json:"anonymous,omitempty"`
119+
Operation string `json:"operation"`
120+
Status string `json:"status"`
121+
Bucket string `json:"bucket"`
122+
Perms accessPerms `json:"permission"`
123+
Anonymous map[string]any `json:"anonymous,omitempty"`
124124
}
125125

126126
// String colorized access message.
@@ -464,7 +464,7 @@ func runAnonymousCmd(args cli.Args) {
464464
"Unable to "+operation+" anonymous `"+string(perms)+"` for `"+targetURL+"`.")
465465
}
466466
}
467-
anonymousJSON := map[string]interface{}{}
467+
anonymousJSON := map[string]any{}
468468
if anonymousStr != "" {
469469
e := json.Unmarshal([]byte(anonymousStr), &anonymousJSON)
470470
fatalIf(probe.NewError(e), "Unable to unmarshal custom anonymous file.")

cmd/batch-list.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func (c batchListMessage) JSON() string {
134134
c.Status = "success"
135135

136136
// Create a temporary slice to hold jobs with derived statuses
137-
jobsWithStatus := make([]map[string]interface{}, len(c.Jobs))
137+
jobsWithStatus := make([]map[string]any, len(c.Jobs))
138138

139139
// Fetch the status for the batch job using BatchJobStatus API
140140
for i, job := range c.Jobs {
@@ -155,7 +155,7 @@ func (c batchListMessage) JSON() string {
155155
}
156156

157157
// Add the job details along with the derived status
158-
jobsWithStatus[i] = map[string]interface{}{
158+
jobsWithStatus[i] = map[string]any{
159159
"id": job.ID,
160160
"type": job.Type,
161161
"user": job.User,
@@ -165,7 +165,7 @@ func (c batchListMessage) JSON() string {
165165
}
166166

167167
// Marshal the updated jobs into JSON
168-
batchListMessageBytes, e := json.MarshalIndent(map[string]interface{}{
168+
batchListMessageBytes, e := json.MarshalIndent(map[string]any{
169169
"status": c.Status,
170170
"jobs": jobsWithStatus,
171171
}, "", " ")

cmd/batch-status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func (m *batchJobMetricsUI) View() string {
232232
table.SetNoWhiteSpace(true)
233233

234234
var data [][]string
235-
addLine := func(prefix string, value interface{}) {
235+
addLine := func(prefix string, value any) {
236236
data = append(data, []string{
237237
prefix,
238238
whiteStyle.Render(fmt.Sprint(value)),

0 commit comments

Comments
 (0)