Skip to content

Commit

Permalink
lint: Enable additional linters
Browse files Browse the repository at this point in the history
Fix in the one go. We can remove the separate 'go vet' and 'go fmt'
invocations since these are now run by golangci-lint

Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
  • Loading branch information
stephenfin committed Apr 17, 2024
1 parent f745836 commit 872e9f1
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 34 deletions.
11 changes: 11 additions & 0 deletions .golangci.yaml
@@ -1,4 +1,15 @@
---
linters:
disable-all: true
enable:
- errcheck
- gofmt
- goimports
- govet
- staticcheck
- unparam
- unused

issues:
exclude:
- SA1006 # printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck)
Expand Down
2 changes: 0 additions & 2 deletions Makefile
Expand Up @@ -17,8 +17,6 @@ endif
# chcon -Rt svirt_sandbox_file_t .
# chcon -Rt svirt_sandbox_file_t ~/.cache/golangci-lint
lint:
go fmt ./...
go vet -tags "fixtures acceptance" ./...
$(RUNNER) run -t --rm \
-v $(shell pwd):/app \
-v ~/.cache/golangci-lint/$(GOLANGCI_LINT_VERSION):/root/.cache \
Expand Down
4 changes: 2 additions & 2 deletions internal/acceptance/openstack/identity/v3/oauth1_test.go
Expand Up @@ -93,11 +93,11 @@ func TestOAuth1CRUD(t *testing.T) {

// test HMACSHA1 and PLAINTEXT signature methods
for _, method := range []oauth1.SignatureMethod{oauth1.HMACSHA1, oauth1.PLAINTEXT} {
oauth1MethodTest(t, client, consumer, method, user, project, roles, ao.IdentityEndpoint)
oauth1MethodTest(t, client, consumer, method, user, project, roles)
}
}

func oauth1MethodTest(t *testing.T, client *gophercloud.ServiceClient, consumer *oauth1.Consumer, method oauth1.SignatureMethod, user *tokens.User, project *tokens.Project, roles []tokens.Role, identityEndpoint string) {
func oauth1MethodTest(t *testing.T, client *gophercloud.ServiceClient, consumer *oauth1.Consumer, method oauth1.SignatureMethod, user *tokens.User, project *tokens.Project, roles []tokens.Role) {
// Request a token
requestTokenOpts := oauth1.RequestTokenOpts{
OAuthConsumerKey: consumer.ID,
Expand Down
Expand Up @@ -57,7 +57,7 @@ func TestLayer3RouterScheduling(t *testing.T) {

containsRouterFunc := func(rs []routers.Router, routerID string) bool {
for _, r := range rs {
if r.ID == router.ID {
if r.ID == routerID {
return true
}
}
Expand Down
16 changes: 8 additions & 8 deletions internal/acceptance/openstack/sharedfilesystems/v2/replicas.go
Expand Up @@ -28,7 +28,7 @@ func CreateReplica(t *testing.T, client *gophercloud.ServiceClient, share *share
return nil, err
}

_, err = waitForReplicaStatus(t, client, replica.ID, "available")
err = waitForReplicaStatus(t, client, replica.ID, "available")
if err != nil {
t.Logf("Failed to get %s replica status", replica.ID)
DeleteReplica(t, client, replica)
Expand All @@ -49,7 +49,7 @@ func DeleteReplica(t *testing.T, client *gophercloud.ServiceClient, replica *rep
t.Errorf("Unable to delete replica %s: %v", replica.ID, err)
}

_, err = waitForReplicaStatus(t, client, replica.ID, "deleted")
err = waitForReplicaStatus(t, client, replica.ID, "deleted")
if err != nil {
t.Errorf("Failed to wait for 'deleted' status for %s replica: %v", replica.ID, err)
} else {
Expand All @@ -71,7 +71,7 @@ func ListShareReplicas(t *testing.T, client *gophercloud.ServiceClient, shareID
return replicas.ExtractReplicas(pages)
}

func waitForReplicaStatus(t *testing.T, c *gophercloud.ServiceClient, id, status string) (*replicas.Replica, error) {
func waitForReplicaStatus(t *testing.T, c *gophercloud.ServiceClient, id, status string) error {
var current *replicas.Replica

err := tools.WaitFor(func(ctx context.Context) (bool, error) {
Expand Down Expand Up @@ -104,14 +104,14 @@ func waitForReplicaStatus(t *testing.T, c *gophercloud.ServiceClient, id, status
if err != nil {
mErr := PrintMessages(t, c, id)
if mErr != nil {
return current, fmt.Errorf("Replica status is '%s' and unable to get manila messages: %s", err, mErr)
return fmt.Errorf("Replica status is '%s' and unable to get manila messages: %s", err, mErr)
}
}

return current, err
return err
}

func waitForReplicaState(t *testing.T, c *gophercloud.ServiceClient, id, state string) (*replicas.Replica, error) {
func waitForReplicaState(t *testing.T, c *gophercloud.ServiceClient, id, state string) error {
var current *replicas.Replica

err := tools.WaitFor(func(ctx context.Context) (bool, error) {
Expand All @@ -136,9 +136,9 @@ func waitForReplicaState(t *testing.T, c *gophercloud.ServiceClient, id, state s
if err != nil {
mErr := PrintMessages(t, c, id)
if mErr != nil {
return current, fmt.Errorf("Replica state is '%s' and unable to get manila messages: %s", err, mErr)
return fmt.Errorf("Replica state is '%s' and unable to get manila messages: %s", err, mErr)
}
}

return current, err
return err
}
Expand Up @@ -86,7 +86,7 @@ func TestReplicaPromote(t *testing.T) {
// sync new replica
err = replicas.Resync(context.TODO(), client, created.ID).ExtractErr()
th.AssertNoErr(t, err)
_, err = waitForReplicaState(t, client, created.ID, "in_sync")
err = waitForReplicaState(t, client, created.ID, "in_sync")
if err != nil {
t.Fatalf("Replica status error: %v", err)
}
Expand All @@ -95,7 +95,7 @@ func TestReplicaPromote(t *testing.T) {
err = replicas.Promote(context.TODO(), client, created.ID, &replicas.PromoteOpts{}).ExtractErr()
th.AssertNoErr(t, err)

_, err = waitForReplicaState(t, client, created.ID, "active")
err = waitForReplicaState(t, client, created.ID, "active")
if err != nil {
t.Fatalf("Replica status error: %v", err)
}
Expand All @@ -117,14 +117,14 @@ func TestReplicaPromote(t *testing.T) {
// sync old replica
err = replicas.Resync(context.TODO(), client, oldReplicaID).ExtractErr()
th.AssertNoErr(t, err)
_, err = waitForReplicaState(t, client, oldReplicaID, "in_sync")
err = waitForReplicaState(t, client, oldReplicaID, "in_sync")
if err != nil {
t.Fatalf("Replica status error: %v", err)
}
err = replicas.Promote(context.TODO(), client, oldReplicaID, &replicas.PromoteOpts{}).ExtractErr()
th.AssertNoErr(t, err)

_, err = waitForReplicaState(t, client, oldReplicaID, "active")
err = waitForReplicaState(t, client, oldReplicaID, "active")
if err != nil {
t.Fatalf("Replica status error: %v", err)
}
Expand Down Expand Up @@ -262,7 +262,7 @@ func TestReplicaResetStatus(t *testing.T) {
}

// We need to wait till the Extend operation is done
_, err = waitForReplicaStatus(t, client, replica.ID, "error")
err = waitForReplicaStatus(t, client, replica.ID, "error")
if err != nil {
t.Fatalf("Replica status error: %v", err)
}
Expand Down Expand Up @@ -300,7 +300,7 @@ func TestReplicaForceDelete(t *testing.T) {
t.Fatalf("Unable to force delete a replica: %v", err)
}

_, err = waitForReplicaStatus(t, client, replica.ID, "deleted")
err = waitForReplicaStatus(t, client, replica.ID, "deleted")
if err != nil {
t.Fatalf("Replica status error: %v", err)
}
Expand Down
Expand Up @@ -224,9 +224,9 @@ func TestGetAdvertisedRoutes(t *testing.T) {
}

expected := []speakers.AdvertisedRoute{
speakers.AdvertisedRoute{NextHop: "172.17.128.212", Destination: "172.17.129.192/27"},
speakers.AdvertisedRoute{NextHop: "172.17.128.218", Destination: "172.17.129.0/27"},
speakers.AdvertisedRoute{NextHop: "172.17.128.231", Destination: "172.17.129.160/27"},
{NextHop: "172.17.128.212", Destination: "172.17.129.192/27"},
{NextHop: "172.17.128.218", Destination: "172.17.129.0/27"},
{NextHop: "172.17.128.231", Destination: "172.17.129.160/27"},
}
th.CheckDeepEquals(t, count, 1)
th.CheckDeepEquals(t, expected, actual)
Expand Down
5 changes: 1 addition & 4 deletions openstack/objectstorage/v1/objects/requests.go
Expand Up @@ -596,10 +596,7 @@ func CreateTempURL(ctx context.Context, c *gophercloud.ServiceClient, containerN
if err != nil {
return "", err
}
urlToBeSigned, err := tempURL(c, containerName, objectName)
if err != nil {
return "", err
}
urlToBeSigned := tempURL(c, containerName, objectName)

if opts.Split == "" {
opts.Split = "/v1/"
Expand Down
4 changes: 2 additions & 2 deletions openstack/objectstorage/v1/objects/urls.go
Expand Up @@ -11,8 +11,8 @@ import (
// Names must not be URL-encoded in this case.
//
// See: https://docs.openstack.org/swift/latest/api/temporary_url_middleware.html#hmac-signature-for-temporary-urls
func tempURL(c *gophercloud.ServiceClient, container, object string) (string, error) {
return c.ServiceURL(container, object), nil
func tempURL(c *gophercloud.ServiceClient, container, object string) string {
return c.ServiceURL(container, object)
}

func listURL(c *gophercloud.ServiceClient, container string) (string, error) {
Expand Down
6 changes: 3 additions & 3 deletions pagination/testing/linked_test.go
Expand Up @@ -30,7 +30,7 @@ func ExtractLinkedInts(r pagination.Page) ([]int, error) {
return s.Ints, err
}

func createLinked(t *testing.T) pagination.Pager {
func createLinked() pagination.Pager {
testhelper.SetupHTTP()

testhelper.Mux.HandleFunc("/page1", func(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -58,7 +58,7 @@ func createLinked(t *testing.T) pagination.Pager {
}

func TestEnumerateLinked(t *testing.T) {
pager := createLinked(t)
pager := createLinked()
defer testhelper.TeardownHTTP()

callCount := 0
Expand Down Expand Up @@ -100,7 +100,7 @@ func TestEnumerateLinked(t *testing.T) {
}

func TestAllPagesLinked(t *testing.T) {
pager := createLinked(t)
pager := createLinked()
defer testhelper.TeardownHTTP()

page, err := pager.AllPages(context.TODO())
Expand Down
6 changes: 3 additions & 3 deletions testhelper/convenience.go
Expand Up @@ -268,15 +268,15 @@ func CheckDeepEquals(t *testing.T, expected, actual interface{}) {
})
}

func isByteArrayEquals(t *testing.T, expectedBytes []byte, actualBytes []byte) bool {
func isByteArrayEquals(expectedBytes []byte, actualBytes []byte) bool {
return bytes.Equal(expectedBytes, actualBytes)
}

// AssertByteArrayEquals a convenience function for checking whether two byte arrays are equal
func AssertByteArrayEquals(t *testing.T, expectedBytes []byte, actualBytes []byte) {
t.Helper()

if !isByteArrayEquals(t, expectedBytes, actualBytes) {
if !isByteArrayEquals(expectedBytes, actualBytes) {
logFatal(t, "The bytes differed.")
}
}
Expand All @@ -285,7 +285,7 @@ func AssertByteArrayEquals(t *testing.T, expectedBytes []byte, actualBytes []byt
func CheckByteArrayEquals(t *testing.T, expectedBytes []byte, actualBytes []byte) {
t.Helper()

if !isByteArrayEquals(t, expectedBytes, actualBytes) {
if !isByteArrayEquals(expectedBytes, actualBytes) {
logError(t, "The bytes differed.")
}
}
Expand Down

0 comments on commit 872e9f1

Please sign in to comment.