Skip to content

Commit

Permalink
Use import alias consistently
Browse files Browse the repository at this point in the history
Signed-off-by: Dusan Borovcanin <[email protected]>
  • Loading branch information
dborovcanin committed Dec 19, 2024
1 parent 5443000 commit 83ac810
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 45 deletions.
8 changes: 4 additions & 4 deletions api/http/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"time"

"github.com/absmach/supermq"
httpapi "github.com/absmach/supermq/api/http"
api "github.com/absmach/supermq/api/http"
apiutil "github.com/absmach/supermq/api/http/util"
"github.com/absmach/supermq/internal/testsutil"
"github.com/absmach/supermq/pkg/errors"
Expand Down Expand Up @@ -103,7 +103,7 @@ func TestValidateUUID(t *testing.T) {

for _, c := range cases {
t.Run(c.desc, func(t *testing.T) {
err := httpapi.ValidateUUID(c.uuid)
err := api.ValidateUUID(c.uuid)
assert.Equal(t, c.err, err)
})
}
Expand Down Expand Up @@ -207,7 +207,7 @@ func TestEncodeResponse(t *testing.T) {
for _, c := range cases {
t.Run(c.desc, func(t *testing.T) {
responseWriter := newResponseWriter()
err := httpapi.EncodeResponse(context.Background(), responseWriter, c.resp)
err := api.EncodeResponse(context.Background(), responseWriter, c.resp)
assert.Equal(t, c.err, err)
assert.Equal(t, c.header, responseWriter.Header())
assert.Equal(t, c.code, responseWriter.StatusCode())
Expand Down Expand Up @@ -316,7 +316,7 @@ func TestEncodeError(t *testing.T) {
t.Run(c.desc, func(t *testing.T) {
responseWriter := newResponseWriter()
for _, err := range c.errs {
httpapi.EncodeError(context.Background(), err, responseWriter)
api.EncodeError(context.Background(), err, responseWriter)
assert.Equal(t, c.code, responseWriter.StatusCode())

message := body{}
Expand Down
4 changes: 2 additions & 2 deletions certs/api/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

apiutil "github.com/absmach/supermq/api/http/util"
"github.com/absmach/supermq/certs"
httpapi "github.com/absmach/supermq/certs/api"
"github.com/absmach/supermq/certs/api"
"github.com/absmach/supermq/certs/mocks"
"github.com/absmach/supermq/internal/testsutil"
smqlog "github.com/absmach/supermq/logger"
Expand Down Expand Up @@ -70,7 +70,7 @@ func newCertServer() (*httptest.Server, *mocks.Service, *authnmocks.Authenticati
svc := new(mocks.Service)
logger := smqlog.NewMock()
authn := new(authnmocks.Authentication)
mux := httpapi.MakeHandler(svc, authn, logger, "")
mux := api.MakeHandler(svc, authn, logger, "")

return httptest.NewServer(mux), svc, authn
}
Expand Down
4 changes: 2 additions & 2 deletions channels/api/http/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"testing"
"time"

httpapi "github.com/absmach/supermq/api/http"
api "github.com/absmach/supermq/api/http"
apiutil "github.com/absmach/supermq/api/http/util"
"github.com/absmach/supermq/channels"
"github.com/absmach/supermq/channels/mocks"
Expand Down Expand Up @@ -517,7 +517,7 @@ func TestListChannels(t *testing.T) {
desc: "list channels with limit greater than max",
token: validToken,
domainID: validID,
query: fmt.Sprintf("limit=%d", httpapi.MaxLimitSize+1),
query: fmt.Sprintf("limit=%d", api.MaxLimitSize+1),
status: http.StatusBadRequest,
err: apiutil.ErrValidation,
},
Expand Down
4 changes: 2 additions & 2 deletions consumers/notifiers/api/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

apiutil "github.com/absmach/supermq/api/http/util"
"github.com/absmach/supermq/consumers/notifiers"
httpapi "github.com/absmach/supermq/consumers/notifiers/api"
"github.com/absmach/supermq/consumers/notifiers/api"
"github.com/absmach/supermq/consumers/notifiers/mocks"
"github.com/absmach/supermq/internal/testsutil"
smqlog "github.com/absmach/supermq/logger"
Expand Down Expand Up @@ -70,7 +70,7 @@ func (tr testRequest) make() (*http.Response, error) {
func newServer() (*httptest.Server, *mocks.Service) {
logger := smqlog.NewMock()
svc := new(mocks.Service)
mux := httpapi.MakeHandler(svc, logger, instanceID)
mux := api.MakeHandler(svc, logger, instanceID)
return httptest.NewServer(mux), svc
}

Expand Down
4 changes: 2 additions & 2 deletions groups/api/http/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"testing"
"time"

httpapi "github.com/absmach/supermq/api/http"
api "github.com/absmach/supermq/api/http"
apiutil "github.com/absmach/supermq/api/http/util"
"github.com/absmach/supermq/groups"
"github.com/absmach/supermq/groups/mocks"
Expand Down Expand Up @@ -763,7 +763,7 @@ func TestListGroups(t *testing.T) {
desc: "list groups with limit greater than max",
token: validToken,
domainID: validID,
query: fmt.Sprintf("limit=%d", httpapi.MaxLimitSize+1),
query: fmt.Sprintf("limit=%d", api.MaxLimitSize+1),
status: http.StatusBadRequest,
err: apiutil.ErrValidation,
},
Expand Down
14 changes: 7 additions & 7 deletions pkg/sdk/domains_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"testing"
"time"

httpapi "github.com/absmach/supermq/api/http"
api "github.com/absmach/supermq/api/http"
apiutil "github.com/absmach/supermq/api/http/util"
"github.com/absmach/supermq/domains"
domainapi "github.com/absmach/supermq/domains/api/http"
Expand Down Expand Up @@ -458,8 +458,8 @@ func TestListDomians(t *testing.T) {
svcReq: domains.Page{
Offset: 0,
Limit: 10,
Order: httpapi.DefOrder,
Dir: httpapi.DefDir,
Order: api.DefOrder,
Dir: api.DefDir,
},
svcRes: domains.DomainsPage{
Total: 1,
Expand All @@ -484,8 +484,8 @@ func TestListDomians(t *testing.T) {
svcReq: domains.Page{
Offset: 0,
Limit: 10,
Order: httpapi.DefOrder,
Dir: httpapi.DefDir,
Order: api.DefOrder,
Dir: api.DefDir,
},
svcRes: domains.DomainsPage{},
authnErr: svcerr.ErrAuthentication,
Expand Down Expand Up @@ -531,8 +531,8 @@ func TestListDomians(t *testing.T) {
svcReq: domains.Page{
Offset: 0,
Limit: 10,
Order: httpapi.DefOrder,
Dir: httpapi.DefDir,
Order: api.DefOrder,
Dir: api.DefDir,
},
svcRes: domains.DomainsPage{
Total: 1,
Expand Down
38 changes: 19 additions & 19 deletions pkg/sdk/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"
"testing"

httpapi "github.com/absmach/supermq/api/http"
api "github.com/absmach/supermq/api/http"
apiutil "github.com/absmach/supermq/api/http/util"
authmocks "github.com/absmach/supermq/auth/mocks"
grpcTokenV1 "github.com/absmach/supermq/internal/grpc/token/v1"
Expand All @@ -23,7 +23,7 @@ import (
oauth2mocks "github.com/absmach/supermq/pkg/oauth2/mocks"
sdk "github.com/absmach/supermq/pkg/sdk"
"github.com/absmach/supermq/users"
"github.com/absmach/supermq/users/api"
httpapi "github.com/absmach/supermq/users/api"
umocks "github.com/absmach/supermq/users/mocks"
"github.com/go-chi/chi/v5"
"github.com/stretchr/testify/assert"
Expand All @@ -43,7 +43,7 @@ func setupUsers() (*httptest.Server, *umocks.Service, *authnmocks.Authentication
provider.On("Name").Return("test")
authn := new(authnmocks.Authentication)
token := new(authmocks.TokenServiceClient)
api.MakeHandler(usvc, authn, token, true, mux, logger, "", passRegex, provider)
httpapi.MakeHandler(usvc, authn, token, true, mux, logger, "", passRegex, provider)

return httptest.NewServer(mux), usvc, authn
}
Expand Down Expand Up @@ -320,8 +320,8 @@ func TestListUsers(t *testing.T) {
svcReq: users.Page{
Offset: offset,
Limit: limit,
Order: httpapi.DefOrder,
Dir: httpapi.DefDir,
Order: api.DefOrder,
Dir: api.DefDir,
},
svcRes: users.UsersPage{
Page: users.Page{
Expand All @@ -348,8 +348,8 @@ func TestListUsers(t *testing.T) {
svcReq: users.Page{
Offset: offset,
Limit: limit,
Order: httpapi.DefOrder,
Dir: httpapi.DefDir,
Order: api.DefOrder,
Dir: api.DefDir,
},
svcRes: users.UsersPage{},
svcErr: svcerr.ErrAuthentication,
Expand Down Expand Up @@ -381,8 +381,8 @@ func TestListUsers(t *testing.T) {
svcReq: users.Page{
Offset: offset,
Limit: 10,
Order: httpapi.DefOrder,
Dir: httpapi.DefDir,
Order: api.DefOrder,
Dir: api.DefDir,
},
svcRes: users.UsersPage{
Page: users.Page{
Expand Down Expand Up @@ -423,8 +423,8 @@ func TestListUsers(t *testing.T) {
Offset: offset,
Limit: limit,
Metadata: users.Metadata{"name": "user_99"},
Order: httpapi.DefOrder,
Dir: httpapi.DefDir,
Order: api.DefOrder,
Dir: api.DefDir,
},
svcRes: users.UsersPage{
Page: users.Page{
Expand Down Expand Up @@ -453,8 +453,8 @@ func TestListUsers(t *testing.T) {
Offset: offset,
Limit: limit,
Status: users.DisabledStatus,
Order: httpapi.DefOrder,
Dir: httpapi.DefDir,
Order: api.DefOrder,
Dir: api.DefDir,
},
svcRes: users.UsersPage{
Page: users.Page{
Expand Down Expand Up @@ -483,8 +483,8 @@ func TestListUsers(t *testing.T) {
Offset: offset,
Limit: limit,
Tag: "tag1",
Order: httpapi.DefOrder,
Dir: httpapi.DefDir,
Order: api.DefOrder,
Dir: api.DefDir,
},
svcRes: users.UsersPage{
Page: users.Page{
Expand Down Expand Up @@ -514,8 +514,8 @@ func TestListUsers(t *testing.T) {
svcReq: users.Page{
Offset: offset,
Limit: limit,
Order: httpapi.DefOrder,
Dir: httpapi.DefDir,
Order: api.DefOrder,
Dir: api.DefDir,
},
svcRes: users.UsersPage{},
svcErr: nil,
Expand All @@ -532,8 +532,8 @@ func TestListUsers(t *testing.T) {
svcReq: users.Page{
Offset: offset,
Limit: limit,
Order: httpapi.DefOrder,
Dir: httpapi.DefDir,
Order: api.DefOrder,
Dir: api.DefDir,
},
svcRes: users.UsersPage{
Page: users.Page{
Expand Down
2 changes: 1 addition & 1 deletion tools/config/golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ linters-settings:
- pkg: github.com/absmach/supermq/api/http/util
alias: apiutil
- pkg: github.com/absmach/supermq/api/http
alias: httpapi
alias: api
gocritic:
enabled-checks:
- importShadow
Expand Down
13 changes: 7 additions & 6 deletions users/api/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2119,6 +2119,7 @@ func TestIssueToken(t *testing.T) {
defer us.Close()

validUsername := "valid"
dataFormat := `{"username": "%s", "password": "%s"}`

cases := []struct {
desc string
Expand All @@ -2129,42 +2130,42 @@ func TestIssueToken(t *testing.T) {
}{
{
desc: "issue token with valid identity and secret",
data: fmt.Sprintf(`{"identity": "%s", "secret": "%s"}`, validUsername, secret),
data: fmt.Sprintf(dataFormat, validUsername, secret),
contentType: contentType,
status: http.StatusCreated,
err: nil,
},
{
desc: "issue token with empty identity",
data: fmt.Sprintf(`{"identity": "%s", "secret": "%s"}`, "", secret),
data: fmt.Sprintf(dataFormat, "", secret),
contentType: contentType,
status: http.StatusBadRequest,
err: apiutil.ErrValidation,
},
{
desc: "issue token with empty secret",
data: fmt.Sprintf(`{"identity": "%s", "secret": "%s"}`, validUsername, ""),
data: fmt.Sprintf(dataFormat, validUsername, ""),
contentType: contentType,
status: http.StatusBadRequest,
err: apiutil.ErrValidation,
},
{
desc: "issue token with invalid email",
data: fmt.Sprintf(`{"identity": "%s", "secret": "%s"}`, "invalid", secret),
data: fmt.Sprintf(dataFormat, "invalid", secret),
contentType: contentType,
status: http.StatusUnauthorized,
err: svcerr.ErrAuthentication,
},
{
desc: "issues token with malformed data",
data: fmt.Sprintf(`{"identity": %s, "secret": %s}`, validUsername, secret),
data: fmt.Sprintf(dataFormat, validUsername, secret),
contentType: contentType,
status: http.StatusBadRequest,
err: apiutil.ErrValidation,
},
{
desc: "issue token with invalid contentype",
data: fmt.Sprintf(`{"identity": "%s", "secret": "%s"}`, "invalid", secret),
data: fmt.Sprintf(dataFormat, "invalid", secret),
contentType: "application/xml",
status: http.StatusUnsupportedMediaType,
err: apiutil.ErrValidation,
Expand Down

0 comments on commit 83ac810

Please sign in to comment.