1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-29 13:49:28 +08:00
b1ackd0t 5e060d5620
NOISSUE - Add More Linters (#1924)
* Fix linting errors

Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>

* feat(linters): add ineffassign linter

This commit adds the `ineffassign` linter to the project's `.golangci.yml` configuration file. The `ineffassign` linter helps identify and flag assignments to variables that are never used, helping to improve code quality and maintainability.

Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>

* Add extra linters

Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>

* feat(golangci): Add header check

- Added goheader check to ensure all files have license headers
- Added build tags for "nats" in the .golangci.yml file to include the necessary dependencies for the "nats" package during the build process.
- Also, increased the maximum number of issues per linter and the maximum number of same issues reported by the linter to improve the code quality analysis.

Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>

* feat(.golangci.yml): Add new linters

Add the following new linters to the .golangci.yml configuration file:
- asasalint
- asciicheck
- bidichk
- contextcheck
- decorder
- dogsled
- errchkjson
- errname
- execinquery
- exportloopref
- ginkgolinter
- gocheckcompilerdirectives

These linters will help improve code quality and catch potential issues during the code review process.

Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>

---------

Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
2023-10-16 11:43:33 +02:00

55 lines
1.8 KiB
Go

// Copyright (c) Mainflux
// SPDX-License-Identifier: Apache-2.0
package testsutil
import (
"context"
"fmt"
"testing"
"github.com/jmoiron/sqlx"
"github.com/mainflux/mainflux"
mfclients "github.com/mainflux/mainflux/pkg/clients"
"github.com/mainflux/mainflux/pkg/errors"
"github.com/mainflux/mainflux/users"
cmocks "github.com/mainflux/mainflux/users/mocks"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func GenerateUUID(t *testing.T, idProvider mainflux.IDProvider) string {
ulid, err := idProvider.ID()
require.Nil(t, err, fmt.Sprintf("unexpected error: %s", err))
return ulid
}
func GenerateValidToken(t *testing.T, clientID string, svc users.Service, cRepo *cmocks.Repository, phasher users.Hasher) string {
client := mfclients.Client{
ID: clientID,
Name: "validtoken",
Credentials: mfclients.Credentials{
Identity: "validtoken",
Secret: "secret",
},
Status: mfclients.EnabledStatus,
}
rClient := client
rClient.Credentials.Secret, _ = phasher.Hash(client.Credentials.Secret)
repoCall := cRepo.On("RetrieveByIdentity", context.Background(), client.Credentials.Identity).Return(rClient, nil)
token, err := svc.IssueToken(context.Background(), client.Credentials.Identity, client.Credentials.Secret)
assert.True(t, errors.Contains(err, nil), fmt.Sprintf("Create token expected nil got %s\n", err))
ok := repoCall.Parent.AssertCalled(t, "RetrieveByIdentity", context.Background(), client.Credentials.Identity)
assert.True(t, ok, "RetrieveByIdentity was not called on creating token")
repoCall.Unset()
return token.AccessToken
}
func CleanUpDB(t *testing.T, db *sqlx.DB) {
_, err := db.Exec("DELETE FROM groups")
require.Nil(t, err, fmt.Sprintf("clean groups unexpected error: %s", err))
_, err = db.Exec("DELETE FROM clients")
require.Nil(t, err, fmt.Sprintf("clean clients unexpected error: %s", err))
}