Skip to content

Commit ce56d12

Browse files
committed
lint: Remove non-constant format string in calls (govet)
We were incorrectly using 'fmt.Printf', 'fmt.Errorf' and 't.Logf' with non-template strings/no arguments. The fix to this is replace these calls with the non-suffixed variants. There are many users of 'fmt.Fprint' - too many to do by hand - so this replacement was resolved using 'sed': sed 's/Fprintf/Fprint/g' -i $(ag fmt.Fprintf -l) We then manually fix the 25 cases where 'fmt.Fprintf' is actually warranted and manually replaced the errant users of 'fmt.Errorf' and 't.Logf'. We also rework 'internal/acceptance/clients/clients.go' slightly to make the code a bit clearer. PS: This is apparently going to be an issue in go 1.24 (specifically in 'go vet') [1] so this is not just golangci-lint being annoying. @pierreprinetti, that's directed at you ;) [1] golang/go#60529 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
1 parent eaf2923 commit ce56d12

183 files changed

Lines changed: 882 additions & 884 deletions

File tree

Some content is hidden

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

internal/acceptance/clients/clients.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,14 @@ func AcceptanceTestChoicesFromEnv() (*AcceptanceTestChoices, error) {
107107
notDistinct = "OS_FLAVOR_ID and OS_FLAVOR_ID_RESIZE must be distinct."
108108
}
109109

110-
if len(missing) > 0 || notDistinct != "" {
111-
text := "You're missing some important setup:\n"
112-
if len(missing) > 0 {
113-
text += " * These environment variables must be provided: " + strings.Join(missing, ", ") + "\n"
114-
}
115-
if notDistinct != "" {
116-
text += " * " + notDistinct + "\n"
117-
}
110+
if len(missing) > 0 {
111+
text := "You're missing some important setup:\n * These environment variables must be provided: %s\n"
112+
return nil, fmt.Errorf(text, strings.Join(missing, ", "))
113+
}
118114

119-
return nil, fmt.Errorf(text)
115+
if notDistinct != "" {
116+
text := "You're missing some important setup:\n * %s\n"
117+
return nil, fmt.Errorf(text, notDistinct)
120118
}
121119

122120
return &AcceptanceTestChoices{

internal/acceptance/tools/tools.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,5 @@ func Elide(value string) string {
8181
// PrintResource returns a resource as a readable structure
8282
func PrintResource(t *testing.T, resource any) {
8383
b, _ := json.MarshalIndent(resource, "", " ")
84-
t.Logf(string(b))
84+
t.Log(string(b))
8585
}

openstack/baremetal/apiversions/testing/fixtures_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func MockListResponse(t *testing.T) {
8989
w.Header().Add("Content-Type", "application/json")
9090
w.WriteHeader(http.StatusOK)
9191

92-
fmt.Fprintf(w, IronicAPIAllVersionResponse)
92+
fmt.Fprint(w, IronicAPIAllVersionResponse)
9393
})
9494
}
9595

@@ -101,6 +101,6 @@ func MockGetResponse(t *testing.T) {
101101
w.Header().Add("Content-Type", "application/json")
102102
w.WriteHeader(http.StatusOK)
103103

104-
fmt.Fprintf(w, IronicAPIVersionResponse)
104+
fmt.Fprint(w, IronicAPIVersionResponse)
105105
})
106106
}

openstack/baremetal/v1/allocations/testing/fixtures_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ func HandleAllocationListSuccessfully(t *testing.T) {
120120
marker := r.Form.Get("marker")
121121
switch marker {
122122
case "":
123-
fmt.Fprintf(w, AllocationListBody)
123+
fmt.Fprint(w, AllocationListBody)
124124

125125
case "eff80f47-75f0-4d41-b1aa-cf07c201adac":
126-
fmt.Fprintf(w, `{ "allocations": [] }`)
126+
fmt.Fprint(w, `{ "allocations": [] }`)
127127
default:
128128
t.Fatalf("/allocations invoked with unexpected marker=[%s]", marker)
129129
}
@@ -145,7 +145,7 @@ func HandleAllocationCreationSuccessfully(t *testing.T, response string) {
145145

146146
w.WriteHeader(http.StatusAccepted)
147147
w.Header().Add("Content-Type", "application/json")
148-
fmt.Fprintf(w, response)
148+
fmt.Fprint(w, response)
149149
})
150150
}
151151

@@ -165,6 +165,6 @@ func HandleAllocationGetSuccessfully(t *testing.T) {
165165
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
166166
th.TestHeader(t, r, "Accept", "application/json")
167167

168-
fmt.Fprintf(w, SingleAllocationBody)
168+
fmt.Fprint(w, SingleAllocationBody)
169169
})
170170
}

openstack/baremetal/v1/conductors/testing/fixtures_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ func HandleConductorListSuccessfully(t *testing.T) {
150150
marker := r.Form.Get("marker")
151151
switch marker {
152152
case "":
153-
fmt.Fprintf(w, ConductorListBody)
153+
fmt.Fprint(w, ConductorListBody)
154154

155155
case "9e5476bd-a4ec-4653-93d6-72c93aa682ba":
156-
fmt.Fprintf(w, `{ "servers": [] }`)
156+
fmt.Fprint(w, `{ "servers": [] }`)
157157
default:
158158
t.Fatalf("/conductors invoked with unexpected marker=[%s]", marker)
159159
}
@@ -170,7 +170,7 @@ func HandleConductorListDetailSuccessfully(t *testing.T) {
170170
t.Errorf("Failed to parse request form %v", err)
171171
}
172172

173-
fmt.Fprintf(w, ConductorListDetailBody)
173+
fmt.Fprint(w, ConductorListDetailBody)
174174
})
175175
}
176176

@@ -180,6 +180,6 @@ func HandleConductorGetSuccessfully(t *testing.T) {
180180
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
181181
th.TestHeader(t, r, "Accept", "application/json")
182182

183-
fmt.Fprintf(w, SingleConductorBody)
183+
fmt.Fprint(w, SingleConductorBody)
184184
})
185185
}

openstack/baremetal/v1/drivers/testing/fixtures_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ func HandleListDriversSuccessfully(t *testing.T) {
377377
t.Errorf("Failed to parse request form %v", err)
378378
}
379379

380-
fmt.Fprintf(w, ListDriversBody)
380+
fmt.Fprint(w, ListDriversBody)
381381
})
382382
}
383383

@@ -388,7 +388,7 @@ func HandleGetDriverDetailsSuccessfully(t *testing.T) {
388388
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
389389
th.TestHeader(t, r, "Accept", "application/json")
390390

391-
fmt.Fprintf(w, SingleDriverDetails)
391+
fmt.Fprint(w, SingleDriverDetails)
392392
})
393393
}
394394

@@ -399,7 +399,7 @@ func HandleGetDriverPropertiesSuccessfully(t *testing.T) {
399399
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
400400
th.TestHeader(t, r, "Accept", "application/json")
401401

402-
fmt.Fprintf(w, SingleDriverProperties)
402+
fmt.Fprint(w, SingleDriverProperties)
403403
})
404404
}
405405

@@ -410,6 +410,6 @@ func HandleGetDriverDiskPropertiesSuccessfully(t *testing.T) {
410410
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
411411
th.TestHeader(t, r, "Accept", "application/json")
412412

413-
fmt.Fprintf(w, SingleDriverDiskProperties)
413+
fmt.Fprint(w, SingleDriverDiskProperties)
414414
})
415415
}

openstack/baremetal/v1/nodes/testing/fixtures_test.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,10 +1404,10 @@ func HandleNodeListSuccessfully(t *testing.T) {
14041404
marker := r.Form.Get("marker")
14051405
switch marker {
14061406
case "":
1407-
fmt.Fprintf(w, NodeListBody)
1407+
fmt.Fprint(w, NodeListBody)
14081408

14091409
case "9e5476bd-a4ec-4653-93d6-72c93aa682ba":
1410-
fmt.Fprintf(w, `{ "servers": [] }`)
1410+
fmt.Fprint(w, `{ "servers": [] }`)
14111411
default:
14121412
t.Fatalf("/nodes invoked with unexpected marker=[%s]", marker)
14131413
}
@@ -1424,7 +1424,7 @@ func HandleNodeListDetailSuccessfully(t *testing.T) {
14241424
t.Errorf("Failed to parse request form %v", err)
14251425
}
14261426

1427-
fmt.Fprintf(w, NodeListDetailBody)
1427+
fmt.Fprint(w, NodeListDetailBody)
14281428
})
14291429
}
14301430

@@ -1451,7 +1451,7 @@ func HandleNodeCreationSuccessfully(t *testing.T, response string) {
14511451

14521452
w.WriteHeader(http.StatusAccepted)
14531453
w.Header().Add("Content-Type", "application/json")
1454-
fmt.Fprintf(w, response)
1454+
fmt.Fprint(w, response)
14551455
})
14561456
}
14571457

@@ -1471,7 +1471,7 @@ func HandleNodeGetSuccessfully(t *testing.T) {
14711471
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
14721472
th.TestHeader(t, r, "Accept", "application/json")
14731473

1474-
fmt.Fprintf(w, SingleNodeBody)
1474+
fmt.Fprint(w, SingleNodeBody)
14751475
})
14761476
}
14771477

@@ -1483,7 +1483,7 @@ func HandleNodeUpdateSuccessfully(t *testing.T, response string) {
14831483
th.TestHeader(t, r, "Content-Type", "application/json")
14841484
th.TestJSONRequest(t, r, `[{"op": "replace", "path": "/properties", "value": {"root_gb": 25}}]`)
14851485

1486-
fmt.Fprintf(w, response)
1486+
fmt.Fprint(w, response)
14871487
})
14881488
}
14891489

@@ -1493,7 +1493,7 @@ func HandleNodeValidateSuccessfully(t *testing.T) {
14931493
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
14941494
th.TestHeader(t, r, "Accept", "application/json")
14951495

1496-
fmt.Fprintf(w, NodeValidationBody)
1496+
fmt.Fprint(w, NodeValidationBody)
14971497
})
14981498
}
14991499

@@ -1525,7 +1525,7 @@ func HandleGetBootDeviceSuccessfully(t *testing.T) {
15251525
th.TestMethod(t, r, "GET")
15261526
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
15271527
w.WriteHeader(http.StatusOK)
1528-
fmt.Fprintf(w, NodeBootDeviceBody)
1528+
fmt.Fprint(w, NodeBootDeviceBody)
15291529
})
15301530
}
15311531

@@ -1535,7 +1535,7 @@ func HandleGetSupportedBootDeviceSuccessfully(t *testing.T) {
15351535
th.TestMethod(t, r, "GET")
15361536
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
15371537
w.WriteHeader(http.StatusOK)
1538-
fmt.Fprintf(w, NodeSupportedBootDeviceBody)
1538+
fmt.Fprint(w, NodeSupportedBootDeviceBody)
15391539
})
15401540
}
15411541

@@ -1667,7 +1667,7 @@ func HandleListBIOSSettingsSuccessfully(t *testing.T) {
16671667
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
16681668
th.TestHeader(t, r, "Accept", "application/json")
16691669

1670-
fmt.Fprintf(w, NodeBIOSSettingsBody)
1670+
fmt.Fprint(w, NodeBIOSSettingsBody)
16711671
})
16721672
}
16731673

@@ -1677,7 +1677,7 @@ func HandleListDetailBIOSSettingsSuccessfully(t *testing.T) {
16771677
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
16781678
th.TestHeader(t, r, "Accept", "application/json")
16791679

1680-
fmt.Fprintf(w, NodeDetailBIOSSettingsBody)
1680+
fmt.Fprint(w, NodeDetailBIOSSettingsBody)
16811681
})
16821682
}
16831683

@@ -1687,7 +1687,7 @@ func HandleGetBIOSSettingSuccessfully(t *testing.T) {
16871687
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
16881688
th.TestHeader(t, r, "Accept", "application/json")
16891689

1690-
fmt.Fprintf(w, NodeSingleBIOSSettingBody)
1690+
fmt.Fprint(w, NodeSingleBIOSSettingBody)
16911691
})
16921692
}
16931693

@@ -1697,7 +1697,7 @@ func HandleGetVendorPassthruMethodsSuccessfully(t *testing.T) {
16971697
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
16981698
th.TestHeader(t, r, "Accept", "application/json")
16991699

1700-
fmt.Fprintf(w, NodeVendorPassthruMethodsBody)
1700+
fmt.Fprint(w, NodeVendorPassthruMethodsBody)
17011701
})
17021702
}
17031703

@@ -1708,7 +1708,7 @@ func HandleGetAllSubscriptionsVendorPassthruSuccessfully(t *testing.T) {
17081708
th.TestHeader(t, r, "Accept", "application/json")
17091709
th.TestFormValues(t, r, map[string]string{"method": "get_all_subscriptions"})
17101710

1711-
fmt.Fprintf(w, NodeGetAllSubscriptionsVnedorPassthruBody)
1711+
fmt.Fprint(w, NodeGetAllSubscriptionsVnedorPassthruBody)
17121712
})
17131713
}
17141714

@@ -1724,7 +1724,7 @@ func HandleGetSubscriptionVendorPassthruSuccessfully(t *testing.T) {
17241724
}
17251725
`)
17261726

1727-
fmt.Fprintf(w, NodeGetSubscriptionVendorPassthruBody)
1727+
fmt.Fprint(w, NodeGetSubscriptionVendorPassthruBody)
17281728
})
17291729
}
17301730

@@ -1744,7 +1744,7 @@ func HandleCreateSubscriptionVendorPassthruAllParametersSuccessfully(t *testing.
17441744
}
17451745
`)
17461746

1747-
fmt.Fprintf(w, NodeCreateSubscriptionVendorPassthruAllParametersBody)
1747+
fmt.Fprint(w, NodeCreateSubscriptionVendorPassthruAllParametersBody)
17481748
})
17491749
}
17501750

@@ -1760,7 +1760,7 @@ func HandleCreateSubscriptionVendorPassthruRequiredParametersSuccessfully(t *tes
17601760
}
17611761
`)
17621762

1763-
fmt.Fprintf(w, NodeCreateSubscriptionVendorPassthruRequiredParametersBody)
1763+
fmt.Fprint(w, NodeCreateSubscriptionVendorPassthruRequiredParametersBody)
17641764
})
17651765
}
17661766

@@ -1805,7 +1805,7 @@ func HandleGetInventorySuccessfully(t *testing.T) {
18051805
th.TestMethod(t, r, "GET")
18061806
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
18071807
w.WriteHeader(http.StatusOK)
1808-
fmt.Fprintf(w, NodeInventoryBody)
1808+
fmt.Fprint(w, NodeInventoryBody)
18091809
})
18101810
}
18111811

@@ -1815,7 +1815,7 @@ func HandleListFirmwareSuccessfully(t *testing.T) {
18151815
th.TestMethod(t, r, "GET")
18161816
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
18171817
w.WriteHeader(http.StatusOK)
1818-
fmt.Fprintf(w, NodeFirmwareListBody)
1818+
fmt.Fprint(w, NodeFirmwareListBody)
18191819
})
18201820
}
18211821

openstack/baremetal/v1/ports/testing/fixtures_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,10 @@ func HandlePortListSuccessfully(t *testing.T) {
181181
marker := r.Form.Get("marker")
182182
switch marker {
183183
case "":
184-
fmt.Fprintf(w, PortListBody)
184+
fmt.Fprint(w, PortListBody)
185185

186186
case "f2845e11-dbd4-4728-a8c0-30d19f48924a":
187-
fmt.Fprintf(w, `{ "ports": [] }`)
187+
fmt.Fprint(w, `{ "ports": [] }`)
188188
default:
189189
t.Fatalf("/ports invoked with unexpected marker=[%s]", marker)
190190
}
@@ -201,7 +201,7 @@ func HandlePortListDetailSuccessfully(t *testing.T) {
201201
t.Errorf("Failed to parse request form %v", err)
202202
}
203203

204-
fmt.Fprintf(w, PortListDetailBody)
204+
fmt.Fprint(w, PortListDetailBody)
205205
})
206206
}
207207

@@ -219,7 +219,7 @@ func HandlePortCreationSuccessfully(t *testing.T, response string) {
219219

220220
w.WriteHeader(http.StatusAccepted)
221221
w.Header().Add("Content-Type", "application/json")
222-
fmt.Fprintf(w, response)
222+
fmt.Fprint(w, response)
223223
})
224224
}
225225

@@ -239,7 +239,7 @@ func HandlePortGetSuccessfully(t *testing.T) {
239239
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
240240
th.TestHeader(t, r, "Accept", "application/json")
241241

242-
fmt.Fprintf(w, SinglePortBody)
242+
fmt.Fprint(w, SinglePortBody)
243243
})
244244
}
245245

@@ -251,6 +251,6 @@ func HandlePortUpdateSuccessfully(t *testing.T, response string) {
251251
th.TestHeader(t, r, "Content-Type", "application/json")
252252
th.TestJSONRequest(t, r, `[{"op": "replace", "path": "/address", "value": "22:22:22:22:22:22"}]`)
253253

254-
fmt.Fprintf(w, response)
254+
fmt.Fprint(w, response)
255255
})
256256
}

openstack/baremetalintrospection/v1/introspection/testing/fixtures.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -467,10 +467,10 @@ func HandleListIntrospectionsSuccessfully(t *testing.T) {
467467

468468
switch marker {
469469
case "":
470-
fmt.Fprintf(w, IntrospectionListBody)
470+
fmt.Fprint(w, IntrospectionListBody)
471471

472472
case "c244557e-899f-46fa-a1ff-5b2c6718616b":
473-
fmt.Fprintf(w, `{ "introspection": [] }`)
473+
fmt.Fprint(w, `{ "introspection": [] }`)
474474

475475
default:
476476
t.Fatalf("/introspection invoked with unexpected marker=[%s]", marker)
@@ -484,7 +484,7 @@ func HandleGetIntrospectionStatusSuccessfully(t *testing.T) {
484484
th.TestMethod(t, r, "GET")
485485
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
486486
th.TestHeader(t, r, "Accept", "application/json")
487-
fmt.Fprintf(w, IntrospectionStatus)
487+
fmt.Fprint(w, IntrospectionStatus)
488488
})
489489
}
490490

@@ -513,7 +513,7 @@ func HandleGetIntrospectionDataSuccessfully(t *testing.T) {
513513
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
514514
th.TestHeader(t, r, "Accept", "application/json")
515515

516-
fmt.Fprintf(w, IntrospectionDataJSONSample)
516+
fmt.Fprint(w, IntrospectionDataJSONSample)
517517
})
518518
}
519519

0 commit comments

Comments
 (0)