MF-1128 - Add golangci-linter to a CI script (#1131)
* Add golangci-linter to CI script Signed-off-by: Ivan Milošević <iva@blokovi.com> * add no-config flag Signed-off-by: Ivan Milošević <iva@blokovi.com> * disable staticcheck Signed-off-by: Ivan Milošević <iva@blokovi.com> * disable all except errcheck Signed-off-by: Ivan Milošević <iva@blokovi.com> * add more linters Signed-off-by: Ivan Milošević <iva@blokovi.com> * add verbose flag for debug decrease concurrency to 1 Signed-off-by: Ivan Milošević <iva@blokovi.com> * remove errcheck and verbose flag Signed-off-by: Ivan Milošević <iva@blokovi.com> * enable just golint Signed-off-by: Ivan Milošević <iva@blokovi.com> * fix lint errors Signed-off-by: Ivan Milošević <iva@blokovi.com>
This commit is contained in:
parent
88fa724fc3
commit
eb9092494e
|
@ -1169,68 +1169,68 @@ func TestBootstrap(t *testing.T) {
|
|||
data := toJSON(s)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
external_id string
|
||||
external_key string
|
||||
status int
|
||||
res string
|
||||
secure bool
|
||||
desc string
|
||||
externalID string
|
||||
externalKey string
|
||||
status int
|
||||
res string
|
||||
secure bool
|
||||
}{
|
||||
{
|
||||
desc: "bootstrap a Thing with unknown ID",
|
||||
external_id: unknown,
|
||||
external_key: c.ExternalKey,
|
||||
status: http.StatusNotFound,
|
||||
res: notFoundRes,
|
||||
secure: false,
|
||||
desc: "bootstrap a Thing with unknown ID",
|
||||
externalID: unknown,
|
||||
externalKey: c.ExternalKey,
|
||||
status: http.StatusNotFound,
|
||||
res: notFoundRes,
|
||||
secure: false,
|
||||
},
|
||||
{
|
||||
desc: "bootstrap a Thing with an empty ID",
|
||||
external_id: "",
|
||||
external_key: c.ExternalKey,
|
||||
status: http.StatusBadRequest,
|
||||
res: malformedRes,
|
||||
secure: false,
|
||||
desc: "bootstrap a Thing with an empty ID",
|
||||
externalID: "",
|
||||
externalKey: c.ExternalKey,
|
||||
status: http.StatusBadRequest,
|
||||
res: malformedRes,
|
||||
secure: false,
|
||||
},
|
||||
{
|
||||
desc: "bootstrap a Thing with unknown key",
|
||||
external_id: c.ExternalID,
|
||||
external_key: unknown,
|
||||
status: http.StatusNotFound,
|
||||
res: extKeyNotFoundRes,
|
||||
secure: false,
|
||||
desc: "bootstrap a Thing with unknown key",
|
||||
externalID: c.ExternalID,
|
||||
externalKey: unknown,
|
||||
status: http.StatusNotFound,
|
||||
res: extKeyNotFoundRes,
|
||||
secure: false,
|
||||
},
|
||||
{
|
||||
desc: "bootstrap a Thing with an empty key",
|
||||
external_id: c.ExternalID,
|
||||
external_key: "",
|
||||
status: http.StatusForbidden,
|
||||
res: unauthRes,
|
||||
secure: false,
|
||||
desc: "bootstrap a Thing with an empty key",
|
||||
externalID: c.ExternalID,
|
||||
externalKey: "",
|
||||
status: http.StatusForbidden,
|
||||
res: unauthRes,
|
||||
secure: false,
|
||||
},
|
||||
{
|
||||
desc: "bootstrap known Thing",
|
||||
external_id: c.ExternalID,
|
||||
external_key: c.ExternalKey,
|
||||
status: http.StatusOK,
|
||||
res: data,
|
||||
secure: false,
|
||||
desc: "bootstrap known Thing",
|
||||
externalID: c.ExternalID,
|
||||
externalKey: c.ExternalKey,
|
||||
status: http.StatusOK,
|
||||
res: data,
|
||||
secure: false,
|
||||
},
|
||||
{
|
||||
desc: "bootstrap secure",
|
||||
external_id: fmt.Sprintf("secure/%s", c.ExternalID),
|
||||
external_key: hex.EncodeToString(encExternKey),
|
||||
status: http.StatusOK,
|
||||
res: data,
|
||||
secure: true,
|
||||
desc: "bootstrap secure",
|
||||
externalID: fmt.Sprintf("secure/%s", c.ExternalID),
|
||||
externalKey: hex.EncodeToString(encExternKey),
|
||||
status: http.StatusOK,
|
||||
res: data,
|
||||
secure: true,
|
||||
},
|
||||
{
|
||||
desc: "bootstrap secure with unencrypted key",
|
||||
external_id: fmt.Sprintf("secure/%s", c.ExternalID),
|
||||
external_key: c.ExternalKey,
|
||||
status: http.StatusNotFound,
|
||||
res: extSecKeyNotFoundRes,
|
||||
secure: true,
|
||||
desc: "bootstrap secure with unencrypted key",
|
||||
externalID: fmt.Sprintf("secure/%s", c.ExternalID),
|
||||
externalKey: c.ExternalKey,
|
||||
status: http.StatusNotFound,
|
||||
res: extSecKeyNotFoundRes,
|
||||
secure: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -1238,8 +1238,8 @@ func TestBootstrap(t *testing.T) {
|
|||
req := testRequest{
|
||||
client: bs.Client(),
|
||||
method: http.MethodGet,
|
||||
url: fmt.Sprintf("%s/things/bootstrap/%s", bs.URL, tc.external_id),
|
||||
token: tc.external_key,
|
||||
url: fmt.Sprintf("%s/things/bootstrap/%s", bs.URL, tc.externalID),
|
||||
token: tc.externalKey,
|
||||
}
|
||||
res, err := req.make()
|
||||
assert.Nil(t, err, fmt.Sprintf("%s: unexpected error %s", tc.desc, err))
|
||||
|
|
|
@ -72,14 +72,22 @@ setup_mf() {
|
|||
make -j$NPROC
|
||||
}
|
||||
|
||||
setup_lint() {
|
||||
# binary will be $(go env GOPATH)/bin/golangci-lint
|
||||
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.24.0
|
||||
}
|
||||
|
||||
setup() {
|
||||
echo "Setting up..."
|
||||
update_go
|
||||
setup_protoc
|
||||
setup_mf
|
||||
setup_lint
|
||||
}
|
||||
|
||||
run_test() {
|
||||
echo "Running lint..."
|
||||
golangci-lint run --concurrency=1 --no-config --disable-all --enable=golint
|
||||
echo "Running tests..."
|
||||
echo "" > coverage.txt
|
||||
for d in $(go list ./... | grep -v 'vendor\|cmd'); do
|
||||
|
|
|
@ -141,7 +141,7 @@ func TestCreateChannels(t *testing.T) {
|
|||
res, err := mainfluxSDK.CreateChannels(tc.channels, tc.token)
|
||||
assert.Equal(t, tc.err, err, fmt.Sprintf("%s: expected error %s, got %s", tc.desc, tc.err, err))
|
||||
|
||||
for idx, _ := range tc.res {
|
||||
for idx := range tc.res {
|
||||
assert.Equal(t, tc.res[idx].ID, res[idx].ID, fmt.Sprintf("%s: expected response ID %s got %s", tc.desc, tc.res[idx].ID, res[idx].ID))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -178,7 +178,7 @@ func TestCreateThings(t *testing.T) {
|
|||
res, err := mainfluxSDK.CreateThings(tc.things, tc.token)
|
||||
assert.Equal(t, tc.err, err, fmt.Sprintf("%s: expected error %s, got %s", tc.desc, tc.err, err))
|
||||
|
||||
for idx, _ := range tc.res {
|
||||
for idx := range tc.res {
|
||||
assert.Equal(t, tc.res[idx].ID, res[idx].ID, fmt.Sprintf("%s: expected response ID %s got %s", tc.desc, tc.res[idx].ID, res[idx].ID))
|
||||
}
|
||||
}
|
||||
|
@ -205,28 +205,28 @@ func TestThing(t *testing.T) {
|
|||
|
||||
cases := []struct {
|
||||
desc string
|
||||
thId string
|
||||
thID string
|
||||
token string
|
||||
err error
|
||||
response sdk.Thing
|
||||
}{
|
||||
{
|
||||
desc: "get existing thing",
|
||||
thId: id,
|
||||
thID: id,
|
||||
token: token,
|
||||
err: nil,
|
||||
response: thing,
|
||||
},
|
||||
{
|
||||
desc: "get non-existent thing",
|
||||
thId: "43",
|
||||
thID: "43",
|
||||
token: token,
|
||||
err: createError(sdk.ErrFailedFetch, http.StatusNotFound),
|
||||
response: sdk.Thing{},
|
||||
},
|
||||
{
|
||||
desc: "get thing with invalid token",
|
||||
thId: id,
|
||||
thID: id,
|
||||
token: wrongValue,
|
||||
err: createError(sdk.ErrFailedFetch, http.StatusForbidden),
|
||||
response: sdk.Thing{},
|
||||
|
@ -234,7 +234,7 @@ func TestThing(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
respTh, err := mainfluxSDK.Thing(tc.thId, tc.token)
|
||||
respTh, err := mainfluxSDK.Thing(tc.thID, tc.token)
|
||||
|
||||
assert.Equal(t, tc.err, err, fmt.Sprintf("%s: expected error %s, got %s", tc.desc, tc.err, err))
|
||||
assert.Equal(t, tc.response, respTh, fmt.Sprintf("%s: expected response thing %s, got %s", tc.desc, tc.response, respTh))
|
||||
|
|
|
@ -66,7 +66,7 @@ func (lm *loggingMiddleware) ViewTwin(ctx context.Context, token, id string) (vi
|
|||
return lm.svc.ViewTwin(ctx, token, id)
|
||||
}
|
||||
|
||||
func (lm *loggingMiddleware) ListTwins(ctx context.Context, token string, offset uint64, limit uint64, name string, metadata twins.Metadata) (tw twins.TwinsPage, err error) {
|
||||
func (lm *loggingMiddleware) ListTwins(ctx context.Context, token string, offset uint64, limit uint64, name string, metadata twins.Metadata) (tw twins.Page, err error) {
|
||||
defer func(begin time.Time) {
|
||||
message := fmt.Sprintf("Method list_twins for token %s took %s to complete", token, time.Since(begin))
|
||||
if err != nil {
|
||||
|
|
|
@ -59,7 +59,7 @@ func (ms *metricsMiddleware) ViewTwin(ctx context.Context, token, id string) (vi
|
|||
return ms.svc.ViewTwin(ctx, token, id)
|
||||
}
|
||||
|
||||
func (ms *metricsMiddleware) ListTwins(ctx context.Context, token string, offset uint64, limit uint64, name string, metadata twins.Metadata) (tw twins.TwinsPage, err error) {
|
||||
func (ms *metricsMiddleware) ListTwins(ctx context.Context, token string, offset uint64, limit uint64, name string, metadata twins.Metadata) (tw twins.Page, err error) {
|
||||
defer func(begin time.Time) {
|
||||
ms.counter.With("method", "list_twins").Add(1)
|
||||
ms.latency.With("method", "list_twins").Observe(time.Since(begin).Seconds())
|
||||
|
|
|
@ -7,5 +7,4 @@
|
|||
// It holds the sequence of attribute based definitions of a real world
|
||||
// thing and refers to the time series of definition based states that
|
||||
// hold the historical data about the represented real world thing.
|
||||
|
||||
package twins
|
||||
|
|
|
@ -29,6 +29,6 @@ func (svc authNServiceClient) Identify(ctx context.Context, in *mainflux.Token,
|
|||
return nil, users.ErrUnauthorizedAccess
|
||||
}
|
||||
|
||||
func (c *authNServiceClient) Issue(ctx context.Context, in *mainflux.IssueReq, opts ...grpc.CallOption) (*mainflux.Token, error) {
|
||||
func (svc *authNServiceClient) Issue(ctx context.Context, in *mainflux.IssueReq, opts ...grpc.CallOption) (*mainflux.Token, error) {
|
||||
return new(mainflux.Token), nil
|
||||
}
|
||||
|
|
|
@ -100,14 +100,14 @@ func (trm *twinRepositoryMock) RetrieveByThing(_ context.Context, thingid string
|
|||
|
||||
}
|
||||
|
||||
func (trm *twinRepositoryMock) RetrieveAll(_ context.Context, owner string, offset uint64, limit uint64, name string, metadata twins.Metadata) (twins.TwinsPage, error) {
|
||||
func (trm *twinRepositoryMock) RetrieveAll(_ context.Context, owner string, offset uint64, limit uint64, name string, metadata twins.Metadata) (twins.Page, error) {
|
||||
trm.mu.Lock()
|
||||
defer trm.mu.Unlock()
|
||||
|
||||
items := make([]twins.Twin, 0)
|
||||
|
||||
if limit <= 0 {
|
||||
return twins.TwinsPage{}, nil
|
||||
return twins.Page{}, nil
|
||||
}
|
||||
|
||||
// This obscure way to examine map keys is enforced by the key structure in mocks/commons.go
|
||||
|
@ -130,7 +130,7 @@ func (trm *twinRepositoryMock) RetrieveAll(_ context.Context, owner string, offs
|
|||
return items[i].ID < items[j].ID
|
||||
})
|
||||
|
||||
page := twins.TwinsPage{
|
||||
page := twins.Page{
|
||||
Twins: items,
|
||||
PageMetadata: twins.PageMetadata{
|
||||
Total: trm.counter,
|
||||
|
|
|
@ -139,7 +139,7 @@ func (tr *twinRepository) RetrieveByAttribute(ctx context.Context, channel, subt
|
|||
return ids, nil
|
||||
}
|
||||
|
||||
func (tr *twinRepository) RetrieveAll(ctx context.Context, owner string, offset uint64, limit uint64, name string, metadata twins.Metadata) (twins.TwinsPage, error) {
|
||||
func (tr *twinRepository) RetrieveAll(ctx context.Context, owner string, offset uint64, limit uint64, name string, metadata twins.Metadata) (twins.Page, error) {
|
||||
coll := tr.db.Collection(twinsCollection)
|
||||
|
||||
findOptions := options.Find()
|
||||
|
@ -159,20 +159,20 @@ func (tr *twinRepository) RetrieveAll(ctx context.Context, owner string, offset
|
|||
}
|
||||
cur, err := coll.Find(ctx, filter, findOptions)
|
||||
if err != nil {
|
||||
return twins.TwinsPage{}, err
|
||||
return twins.Page{}, err
|
||||
}
|
||||
|
||||
results, err := decodeTwins(ctx, cur)
|
||||
if err != nil {
|
||||
return twins.TwinsPage{}, err
|
||||
return twins.Page{}, err
|
||||
}
|
||||
|
||||
total, err := coll.CountDocuments(ctx, filter)
|
||||
if err != nil {
|
||||
return twins.TwinsPage{}, err
|
||||
return twins.Page{}, err
|
||||
}
|
||||
|
||||
return twins.TwinsPage{
|
||||
return twins.Page{
|
||||
Twins: results,
|
||||
PageMetadata: twins.PageMetadata{
|
||||
Total: uint64(total),
|
||||
|
@ -182,7 +182,7 @@ func (tr *twinRepository) RetrieveAll(ctx context.Context, owner string, offset
|
|||
}, nil
|
||||
}
|
||||
|
||||
func (tr *twinRepository) RetrieveAllByThing(ctx context.Context, thingid string, offset uint64, limit uint64) (twins.TwinsPage, error) {
|
||||
func (tr *twinRepository) RetrieveAllByThing(ctx context.Context, thingid string, offset uint64, limit uint64) (twins.Page, error) {
|
||||
coll := tr.db.Collection(twinsCollection)
|
||||
|
||||
findOptions := options.Find()
|
||||
|
@ -192,20 +192,20 @@ func (tr *twinRepository) RetrieveAllByThing(ctx context.Context, thingid string
|
|||
filter := bson.D{{"thingid", thingid}}
|
||||
cur, err := coll.Find(ctx, filter, findOptions)
|
||||
if err != nil {
|
||||
return twins.TwinsPage{}, err
|
||||
return twins.Page{}, err
|
||||
}
|
||||
|
||||
results, err := decodeTwins(ctx, cur)
|
||||
if err != nil {
|
||||
return twins.TwinsPage{}, err
|
||||
return twins.Page{}, err
|
||||
}
|
||||
|
||||
total, err := coll.CountDocuments(ctx, filter)
|
||||
if err != nil {
|
||||
return twins.TwinsPage{}, err
|
||||
return twins.Page{}, err
|
||||
}
|
||||
|
||||
return twins.TwinsPage{
|
||||
return twins.Page{
|
||||
Twins: results,
|
||||
PageMetadata: twins.PageMetadata{
|
||||
Total: uint64(total),
|
||||
|
|
|
@ -63,7 +63,7 @@ type Service interface {
|
|||
|
||||
// ListTwins retrieves data about subset of twins that belongs to the
|
||||
// user identified by the provided key.
|
||||
ListTwins(ctx context.Context, token string, offset uint64, limit uint64, name string, metadata Metadata) (TwinsPage, error)
|
||||
ListTwins(ctx context.Context, token string, offset uint64, limit uint64, name string, metadata Metadata) (Page, error)
|
||||
|
||||
// ListStates retrieves data about subset of states that belongs to the
|
||||
// twin identified by the id.
|
||||
|
@ -261,10 +261,10 @@ func (ts *twinsService) RemoveTwin(ctx context.Context, token, id string) (err e
|
|||
return nil
|
||||
}
|
||||
|
||||
func (ts *twinsService) ListTwins(ctx context.Context, token string, offset uint64, limit uint64, name string, metadata Metadata) (TwinsPage, error) {
|
||||
func (ts *twinsService) ListTwins(ctx context.Context, token string, offset uint64, limit uint64, name string, metadata Metadata) (Page, error) {
|
||||
res, err := ts.auth.Identify(ctx, &mainflux.Token{Value: token})
|
||||
if err != nil {
|
||||
return TwinsPage{}, ErrUnauthorizedAccess
|
||||
return Page{}, ErrUnauthorizedAccess
|
||||
}
|
||||
|
||||
return ts.twins.RetrieveAll(ctx, res.GetValue(), offset, limit, name, metadata)
|
||||
|
|
|
@ -49,9 +49,9 @@ type PageMetadata struct {
|
|||
Name string
|
||||
}
|
||||
|
||||
// TwinsPage contains page related metadata as well as a list of twins that
|
||||
// Page contains page related metadata as well as a list of twins that
|
||||
// belong to this page.
|
||||
type TwinsPage struct {
|
||||
type Page struct {
|
||||
PageMetadata
|
||||
Twins []Twin
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ type TwinRepository interface {
|
|||
RetrieveByAttribute(ctx context.Context, channel, subtopic string) ([]string, error)
|
||||
|
||||
// RetrieveAll retrieves the subset of things owned by the specified user.
|
||||
RetrieveAll(context.Context, string, uint64, uint64, string, Metadata) (TwinsPage, error)
|
||||
RetrieveAll(context.Context, string, uint64, uint64, string, Metadata) (Page, error)
|
||||
|
||||
// RetrieveByThing retrieves twin that represents specified thing
|
||||
RetrieveByThing(context.Context, string) (Twin, error)
|
||||
|
|
Loading…
Reference in New Issue