Skip to content

Commit

Permalink
upgrade linter and cleanup makefile (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
harshavardhana authored May 19, 2020
1 parent c5b2419 commit 92a8aab
Show file tree
Hide file tree
Showing 9 changed files with 213 additions and 872 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,19 @@ jobs:
os: [ubuntu-latest]
steps:
- name: Set up Go ${{ matrix.go-version }} on ${{ matrix.os }}
uses: actions/setup-go@v1
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
id: go

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

- name: Build on ${{ matrix.os }}
env:
GO111MODULE: on
GOOS: linux
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.24.0
$(go env GOPATH)/bin/golangci-lint run --timeout=5m --config ./.golangci.yml
go mod vendor
go test -v -race ./...
make verifiers
make test
make mcs
7 changes: 7 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
linters-settings:
golint:
min-confidence: 0

misspell:
locale: US

Expand All @@ -14,4 +17,8 @@ linters:
- gosimple
- deadcode
- unparam
- unused
- structcheck

service:
golangci-lint-version: 1.21.0 # use the fixed version to not introduce new linters unexpectedly
1,023 changes: 173 additions & 850 deletions CREDITS

Large diffs are not rendered by default.

24 changes: 20 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,23 @@ default: mcs
.PHONY: mcs
mcs:
@echo "Building mcs binary to './mcs'"
@(CGO_ENABLED=0 go build -trimpath --tags=kqueue --ldflags "-s -w" -o mcs ./cmd/mcs)
@(GO111MODULE=on CGO_ENABLED=0 go build -trimpath --tags=kqueue --ldflags "-s -w" -o mcs ./cmd/mcs)

getdeps:
@mkdir -p ${GOPATH}/bin
@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)

verifiers: getdeps fmt lint

fmt:
@echo "Running $@ check"
@GO111MODULE=on gofmt -d cmd/
@GO111MODULE=on gofmt -d pkg/

lint:
@echo "Running $@ check"
@GO111MODULE=on ${GOPATH}/bin/golangci-lint cache clean
@GO111MODULE=on ${GOPATH}/bin/golangci-lint run --timeout=5m --config ./.golangci.yml

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

test:
@(go test -race -v github.com/minio/mcs/restapi/...)
@(go test -race -v github.com/minio/mcs/pkg/...)
@(GO111MODULE=on go test -race -v github.com/minio/mcs/restapi/...)
@(GO111MODULE=on go test -race -v github.com/minio/mcs/pkg/...)

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

clean:
@echo "Cleaning up all the generated files"
Expand Down
2 changes: 1 addition & 1 deletion pkg/auth/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
)

var (
errAuthentication = errors.New("Authentication failed, check your access credentials")
errAuthentication = errors.New("authentication failed, check your access credentials")
errNoAuthToken = errors.New("JWT token missing")
errReadingToken = errors.New("JWT internal data is malformed")
errClaimsFormat = errors.New("encrypted jwt claims not in the right format")
Expand Down
2 changes: 1 addition & 1 deletion pkg/auth/jwt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestJWTAuthenticate(t *testing.T) {
}
// Test-2 : JWTAuthenticate() return an error because of a tampered jwt
if _, err := JWTAuthenticate(badToken); err != nil {
funcAssert.Equal("Authentication failed, check your access credentials", err.Error())
funcAssert.Equal("authentication failed, check your access credentials", err.Error())
}
// Test-3 : JWTAuthenticate() return an error because of an empty jwt
if _, err := JWTAuthenticate(""); err != nil {
Expand Down
11 changes: 4 additions & 7 deletions restapi/admin_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@ import (
"github.com/go-openapi/swag"
"github.com/stretchr/testify/assert"

"github.com/minio/minio/pkg/event/target"

"github.com/minio/minio/cmd/config"

"github.com/minio/mcs/models"

"github.com/minio/minio/cmd/config"
"github.com/minio/minio/pkg/event/target"
"github.com/minio/minio/pkg/madmin"
)

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

// mock function response from getConfig()
minioGetConfigKVMock = func(key string) ([]byte, error) {
return nil, errors.New("Invalid config")
return nil, errors.New("invalid config")
}

mockConfigList := madmin.Help{}
Expand All @@ -553,7 +550,7 @@ func Test_getConfig(t *testing.T) {
mock: func() {
// mock function response from getConfig()
minioGetConfigKVMock = func(key string) ([]byte, error) {
return nil, errors.New("Invalid config")
return nil, errors.New("invalid config")
}
// mock function response from listConfig()
minioHelpConfigKVMock = func(subSys, key string, envOnly bool) (madmin.Help, error) {
Expand Down
4 changes: 2 additions & 2 deletions restapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ var STSClient = PrepareSTSClient()
func newMcsCredentials(accessKey, secretKey, location string) (*credentials.Credentials, error) {
mcsEndpoint := getMinIOServer()
if mcsEndpoint == "" {
return nil, errors.New("STS endpoint cannot be empty")
return nil, errors.New("endpoint cannot be empty for AssumeRoleSTS")
}
if accessKey == "" || secretKey == "" {
return nil, errors.New("AssumeRole credentials access/secretkey is mandatory")
return nil, errors.New("creredentials access/secretkey is mandatory for AssumeRoleSTS")
}

// Future authentication methods can be added under this switch statement
Expand Down
2 changes: 1 addition & 1 deletion restapi/user_login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func Test_getConfiguredRegion(t *testing.T) {
mock: func() {
// mock function response from getConfig()
minioGetConfigKVMock = func(key string) ([]byte, error) {
return nil, errors.New("Invalid config")
return nil, errors.New("invalid config")
}
// mock function response from listConfig()
minioHelpConfigKVMock = func(subSys, key string, envOnly bool) (madmin.Help, error) {
Expand Down

0 comments on commit 92a8aab

Please sign in to comment.