Skip to content

Commit

Permalink
lint: Remove non-constant format string in calls (govet)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
stephenfin committed Nov 28, 2024
1 parent bf27b7b commit dc046b5
Show file tree
Hide file tree
Showing 183 changed files with 882 additions and 884 deletions.
16 changes: 7 additions & 9 deletions internal/acceptance/clients/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,14 @@ func AcceptanceTestChoicesFromEnv() (*AcceptanceTestChoices, error) {
notDistinct = "OS_FLAVOR_ID and OS_FLAVOR_ID_RESIZE must be distinct."
}

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

return nil, fmt.Errorf(text)
if notDistinct != "" {
text := "You're missing some important setup:\n * %s\n"
return nil, fmt.Errorf(text, notDistinct)
}

return &AcceptanceTestChoices{
Expand Down
2 changes: 1 addition & 1 deletion internal/acceptance/tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,5 @@ func Elide(value string) string {
// PrintResource returns a resource as a readable structure
func PrintResource(t *testing.T, resource any) {
b, _ := json.MarshalIndent(resource, "", " ")
t.Logf(string(b))
t.Log(string(b))
}
4 changes: 2 additions & 2 deletions openstack/baremetal/apiversions/testing/fixtures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func MockListResponse(t *testing.T) {
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)

fmt.Fprintf(w, IronicAPIAllVersionResponse)
fmt.Fprint(w, IronicAPIAllVersionResponse)
})
}

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

fmt.Fprintf(w, IronicAPIVersionResponse)
fmt.Fprint(w, IronicAPIVersionResponse)
})
}
8 changes: 4 additions & 4 deletions openstack/baremetal/v1/allocations/testing/fixtures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ func HandleAllocationListSuccessfully(t *testing.T) {
marker := r.Form.Get("marker")
switch marker {
case "":
fmt.Fprintf(w, AllocationListBody)
fmt.Fprint(w, AllocationListBody)

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

w.WriteHeader(http.StatusAccepted)
w.Header().Add("Content-Type", "application/json")
fmt.Fprintf(w, response)
fmt.Fprint(w, response)
})
}

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

fmt.Fprintf(w, SingleAllocationBody)
fmt.Fprint(w, SingleAllocationBody)
})
}
8 changes: 4 additions & 4 deletions openstack/baremetal/v1/conductors/testing/fixtures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ func HandleConductorListSuccessfully(t *testing.T) {
marker := r.Form.Get("marker")
switch marker {
case "":
fmt.Fprintf(w, ConductorListBody)
fmt.Fprint(w, ConductorListBody)

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

fmt.Fprintf(w, ConductorListDetailBody)
fmt.Fprint(w, ConductorListDetailBody)
})
}

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

fmt.Fprintf(w, SingleConductorBody)
fmt.Fprint(w, SingleConductorBody)
})
}
8 changes: 4 additions & 4 deletions openstack/baremetal/v1/drivers/testing/fixtures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ func HandleListDriversSuccessfully(t *testing.T) {
t.Errorf("Failed to parse request form %v", err)
}

fmt.Fprintf(w, ListDriversBody)
fmt.Fprint(w, ListDriversBody)
})
}

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

fmt.Fprintf(w, SingleDriverDetails)
fmt.Fprint(w, SingleDriverDetails)
})
}

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

fmt.Fprintf(w, SingleDriverProperties)
fmt.Fprint(w, SingleDriverProperties)
})
}

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

fmt.Fprintf(w, SingleDriverDiskProperties)
fmt.Fprint(w, SingleDriverDiskProperties)
})
}
38 changes: 19 additions & 19 deletions openstack/baremetal/v1/nodes/testing/fixtures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1404,10 +1404,10 @@ func HandleNodeListSuccessfully(t *testing.T) {
marker := r.Form.Get("marker")
switch marker {
case "":
fmt.Fprintf(w, NodeListBody)
fmt.Fprint(w, NodeListBody)

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

fmt.Fprintf(w, NodeListDetailBody)
fmt.Fprint(w, NodeListDetailBody)
})
}

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

w.WriteHeader(http.StatusAccepted)
w.Header().Add("Content-Type", "application/json")
fmt.Fprintf(w, response)
fmt.Fprint(w, response)
})
}

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

fmt.Fprintf(w, SingleNodeBody)
fmt.Fprint(w, SingleNodeBody)
})
}

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

fmt.Fprintf(w, response)
fmt.Fprint(w, response)
})
}

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

fmt.Fprintf(w, NodeValidationBody)
fmt.Fprint(w, NodeValidationBody)
})
}

Expand Down Expand Up @@ -1525,7 +1525,7 @@ func HandleGetBootDeviceSuccessfully(t *testing.T) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, NodeBootDeviceBody)
fmt.Fprint(w, NodeBootDeviceBody)
})
}

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

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

fmt.Fprintf(w, NodeBIOSSettingsBody)
fmt.Fprint(w, NodeBIOSSettingsBody)
})
}

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

fmt.Fprintf(w, NodeDetailBIOSSettingsBody)
fmt.Fprint(w, NodeDetailBIOSSettingsBody)
})
}

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

fmt.Fprintf(w, NodeSingleBIOSSettingBody)
fmt.Fprint(w, NodeSingleBIOSSettingBody)
})
}

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

fmt.Fprintf(w, NodeVendorPassthruMethodsBody)
fmt.Fprint(w, NodeVendorPassthruMethodsBody)
})
}

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

fmt.Fprintf(w, NodeGetAllSubscriptionsVnedorPassthruBody)
fmt.Fprint(w, NodeGetAllSubscriptionsVnedorPassthruBody)
})
}

Expand All @@ -1724,7 +1724,7 @@ func HandleGetSubscriptionVendorPassthruSuccessfully(t *testing.T) {
}
`)

fmt.Fprintf(w, NodeGetSubscriptionVendorPassthruBody)
fmt.Fprint(w, NodeGetSubscriptionVendorPassthruBody)
})
}

Expand All @@ -1744,7 +1744,7 @@ func HandleCreateSubscriptionVendorPassthruAllParametersSuccessfully(t *testing.
}
`)

fmt.Fprintf(w, NodeCreateSubscriptionVendorPassthruAllParametersBody)
fmt.Fprint(w, NodeCreateSubscriptionVendorPassthruAllParametersBody)
})
}

Expand All @@ -1760,7 +1760,7 @@ func HandleCreateSubscriptionVendorPassthruRequiredParametersSuccessfully(t *tes
}
`)

fmt.Fprintf(w, NodeCreateSubscriptionVendorPassthruRequiredParametersBody)
fmt.Fprint(w, NodeCreateSubscriptionVendorPassthruRequiredParametersBody)
})
}

Expand Down Expand Up @@ -1805,7 +1805,7 @@ func HandleGetInventorySuccessfully(t *testing.T) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, NodeInventoryBody)
fmt.Fprint(w, NodeInventoryBody)
})
}

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

Expand Down
12 changes: 6 additions & 6 deletions openstack/baremetal/v1/ports/testing/fixtures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ func HandlePortListSuccessfully(t *testing.T) {
marker := r.Form.Get("marker")
switch marker {
case "":
fmt.Fprintf(w, PortListBody)
fmt.Fprint(w, PortListBody)

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

fmt.Fprintf(w, PortListDetailBody)
fmt.Fprint(w, PortListDetailBody)
})
}

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

w.WriteHeader(http.StatusAccepted)
w.Header().Add("Content-Type", "application/json")
fmt.Fprintf(w, response)
fmt.Fprint(w, response)
})
}

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

fmt.Fprintf(w, SinglePortBody)
fmt.Fprint(w, SinglePortBody)
})
}

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

fmt.Fprintf(w, response)
fmt.Fprint(w, response)
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,10 @@ func HandleListIntrospectionsSuccessfully(t *testing.T) {

switch marker {
case "":
fmt.Fprintf(w, IntrospectionListBody)
fmt.Fprint(w, IntrospectionListBody)

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

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

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

fmt.Fprintf(w, IntrospectionDataJSONSample)
fmt.Fprint(w, IntrospectionDataJSONSample)
})
}

Expand Down
Loading

0 comments on commit dc046b5

Please sign in to comment.