Skip to content

Commit 92a8aab

Browse files
upgrade linter and cleanup makefile (#126)
1 parent c5b2419 commit 92a8aab

File tree

9 files changed

+213
-872
lines changed

9 files changed

+213
-872
lines changed

.github/workflows/go.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,19 @@ jobs:
1818
os: [ubuntu-latest]
1919
steps:
2020
- name: Set up Go ${{ matrix.go-version }} on ${{ matrix.os }}
21-
uses: actions/setup-go@v1
21+
uses: actions/setup-go@v2
2222
with:
2323
go-version: ${{ matrix.go-version }}
2424
id: go
2525

2626
- name: Check out code into the Go module directory
27-
uses: actions/checkout@v1
27+
uses: actions/checkout@v2
2828

2929
- name: Build on ${{ matrix.os }}
3030
env:
3131
GO111MODULE: on
3232
GOOS: linux
3333
run: |
34-
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.24.0
35-
$(go env GOPATH)/bin/golangci-lint run --timeout=5m --config ./.golangci.yml
36-
go mod vendor
37-
go test -v -race ./...
34+
make verifiers
35+
make test
3836
make mcs

.golangci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
linters-settings:
2+
golint:
3+
min-confidence: 0
4+
25
misspell:
36
locale: US
47

@@ -14,4 +17,8 @@ linters:
1417
- gosimple
1518
- deadcode
1619
- unparam
20+
- unused
1721
- structcheck
22+
23+
service:
24+
golangci-lint-version: 1.21.0 # use the fixed version to not introduce new linters unexpectedly

CREDITS

Lines changed: 173 additions & 850 deletions
Large diffs are not rendered by default.

Makefile

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,23 @@ default: mcs
66
.PHONY: mcs
77
mcs:
88
@echo "Building mcs binary to './mcs'"
9-
@(CGO_ENABLED=0 go build -trimpath --tags=kqueue --ldflags "-s -w" -o mcs ./cmd/mcs)
9+
@(GO111MODULE=on CGO_ENABLED=0 go build -trimpath --tags=kqueue --ldflags "-s -w" -o mcs ./cmd/mcs)
10+
11+
getdeps:
12+
@mkdir -p ${GOPATH}/bin
13+
@which golangci-lint 1>/dev/null || (echo "Installing golangci-lint" && curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin v1.27.0)
14+
15+
verifiers: getdeps fmt lint
16+
17+
fmt:
18+
@echo "Running $@ check"
19+
@GO111MODULE=on gofmt -d cmd/
20+
@GO111MODULE=on gofmt -d pkg/
21+
22+
lint:
23+
@echo "Running $@ check"
24+
@GO111MODULE=on ${GOPATH}/bin/golangci-lint cache clean
25+
@GO111MODULE=on ${GOPATH}/bin/golangci-lint run --timeout=5m --config ./.golangci.yml
1026

1127
install: mcs
1228
@echo "Installing mcs binary to '$(GOPATH)/bin/mcs'"
@@ -21,11 +37,11 @@ assets:
2137
@(cd portal-ui; yarn install; make build-static; cd ..)
2238

2339
test:
24-
@(go test -race -v github.com/minio/mcs/restapi/...)
25-
@(go test -race -v github.com/minio/mcs/pkg/...)
40+
@(GO111MODULE=on go test -race -v github.com/minio/mcs/restapi/...)
41+
@(GO111MODULE=on go test -race -v github.com/minio/mcs/pkg/...)
2642

2743
coverage:
28-
@(go test -v -coverprofile=coverage.out github.com/minio/mcs/restapi/... && go tool cover -html=coverage.out && open coverage.html)
44+
@(GO111MODULE=on go test -v -coverprofile=coverage.out github.com/minio/mcs/restapi/... && go tool cover -html=coverage.out && open coverage.html)
2945

3046
clean:
3147
@echo "Cleaning up all the generated files"

pkg/auth/jwt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import (
3737
)
3838

3939
var (
40-
errAuthentication = errors.New("Authentication failed, check your access credentials")
40+
errAuthentication = errors.New("authentication failed, check your access credentials")
4141
errNoAuthToken = errors.New("JWT token missing")
4242
errReadingToken = errors.New("JWT internal data is malformed")
4343
errClaimsFormat = errors.New("encrypted jwt claims not in the right format")

pkg/auth/jwt_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func TestJWTAuthenticate(t *testing.T) {
6363
}
6464
// Test-2 : JWTAuthenticate() return an error because of a tampered jwt
6565
if _, err := JWTAuthenticate(badToken); err != nil {
66-
funcAssert.Equal("Authentication failed, check your access credentials", err.Error())
66+
funcAssert.Equal("authentication failed, check your access credentials", err.Error())
6767
}
6868
// Test-3 : JWTAuthenticate() return an error because of an empty jwt
6969
if _, err := JWTAuthenticate(""); err != nil {

restapi/admin_config_test.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,9 @@ import (
2828
"github.com/go-openapi/swag"
2929
"github.com/stretchr/testify/assert"
3030

31-
"github.com/minio/minio/pkg/event/target"
32-
33-
"github.com/minio/minio/cmd/config"
34-
3531
"github.com/minio/mcs/models"
36-
32+
"github.com/minio/minio/cmd/config"
33+
"github.com/minio/minio/pkg/event/target"
3734
"github.com/minio/minio/pkg/madmin"
3835
)
3936

@@ -532,7 +529,7 @@ func Test_getConfig(t *testing.T) {
532529

533530
// mock function response from getConfig()
534531
minioGetConfigKVMock = func(key string) ([]byte, error) {
535-
return nil, errors.New("Invalid config")
532+
return nil, errors.New("invalid config")
536533
}
537534

538535
mockConfigList := madmin.Help{}
@@ -553,7 +550,7 @@ func Test_getConfig(t *testing.T) {
553550
mock: func() {
554551
// mock function response from getConfig()
555552
minioGetConfigKVMock = func(key string) ([]byte, error) {
556-
return nil, errors.New("Invalid config")
553+
return nil, errors.New("invalid config")
557554
}
558555
// mock function response from listConfig()
559556
minioHelpConfigKVMock = func(subSys, key string, envOnly bool) (madmin.Help, error) {

restapi/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ var STSClient = PrepareSTSClient()
163163
func newMcsCredentials(accessKey, secretKey, location string) (*credentials.Credentials, error) {
164164
mcsEndpoint := getMinIOServer()
165165
if mcsEndpoint == "" {
166-
return nil, errors.New("STS endpoint cannot be empty")
166+
return nil, errors.New("endpoint cannot be empty for AssumeRoleSTS")
167167
}
168168
if accessKey == "" || secretKey == "" {
169-
return nil, errors.New("AssumeRole credentials access/secretkey is mandatory")
169+
return nil, errors.New("creredentials access/secretkey is mandatory for AssumeRoleSTS")
170170
}
171171

172172
// Future authentication methods can be added under this switch statement

restapi/user_login_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func Test_getConfiguredRegion(t *testing.T) {
126126
mock: func() {
127127
// mock function response from getConfig()
128128
minioGetConfigKVMock = func(key string) ([]byte, error) {
129-
return nil, errors.New("Invalid config")
129+
return nil, errors.New("invalid config")
130130
}
131131
// mock function response from listConfig()
132132
minioHelpConfigKVMock = func(subSys, key string, envOnly bool) (madmin.Help, error) {

0 commit comments

Comments
 (0)