mirror of
https://github.com/minio/mc.git
synced 2025-04-18 10:04:03 +03:00
enable golang-lint CI run and -race tests (#3247)
This commit is contained in:
parent
166db95464
commit
fa520cbd1a
14
.github/workflows/go.yml
vendored
14
.github/workflows/go.yml
vendored
@ -30,14 +30,18 @@ jobs:
|
||||
if: matrix.os == 'windows-latest'
|
||||
env:
|
||||
GO111MODULE: on
|
||||
run: go test -v -race ./...
|
||||
run: |
|
||||
go build --ldflags="-s -w" -o %GOPATH%\bin\mc.exe
|
||||
go test -v -race --timeout 30m ./...
|
||||
- name: Build on ${{ matrix.os }}
|
||||
if: matrix.os == 'ubuntu-latest'
|
||||
env:
|
||||
GO111MODULE: on
|
||||
run: |
|
||||
make
|
||||
diff -au <(gofmt -d *.go) <(printf "")
|
||||
diff -au <(gofmt -d cmd) <(printf "")
|
||||
diff -au <(gofmt -d pkg) <(printf "")
|
||||
go test -v -race ./...
|
||||
make test
|
||||
diff -au <(gofmt -s -d cmd) <(printf "")
|
||||
diff -au <(gofmt -s -d pkg) <(printf "")
|
||||
make test-race
|
||||
make verify
|
||||
make crosscompile
|
||||
|
28
.golangci.yml
Normal file
28
.golangci.yml
Normal file
@ -0,0 +1,28 @@
|
||||
linters-settings:
|
||||
golint:
|
||||
min-confidence: 0
|
||||
|
||||
misspell:
|
||||
locale: US
|
||||
|
||||
linters:
|
||||
disable-all: true
|
||||
enable:
|
||||
- typecheck
|
||||
- goimports
|
||||
- misspell
|
||||
- govet
|
||||
- golint
|
||||
- ineffassign
|
||||
- gosimple
|
||||
- deadcode
|
||||
- structcheck
|
||||
|
||||
issues:
|
||||
exclude-use-default: false
|
||||
exclude:
|
||||
- instead of using struct literal
|
||||
- should have a package comment
|
||||
- error strings should not be capitalized or end with punctuation or a newline
|
||||
service:
|
||||
golangci-lint-version: 1.20.0 # use the fixed version to not introduce new linters unexpectedly
|
39
Makefile
39
Makefile
@ -18,18 +18,12 @@ checks:
|
||||
|
||||
getdeps:
|
||||
@mkdir -p ${GOPATH}/bin
|
||||
@which golint 1>/dev/null || (echo "Installing golint" && GO111MODULE=off go get -u golang.org/x/lint/golint)
|
||||
ifeq ($(GOARCH),s390x)
|
||||
@which staticcheck 1>/dev/null || (echo "Installing staticcheck" && GO111MODULE=off go get honnef.co/go/tools/cmd/staticcheck)
|
||||
else
|
||||
@which staticcheck 1>/dev/null || (echo "Installing staticcheck" && wget --quiet https://github.com/dominikh/go-tools/releases/download/2019.2.3/staticcheck_${GOOS}_${GOARCH}.tar.gz && tar xf staticcheck_${GOOS}_${GOARCH}.tar.gz && mv staticcheck/staticcheck ${GOPATH}/bin/staticcheck && chmod +x ${GOPATH}/bin/staticcheck && rm -f staticcheck_${GOOS}_${GOARCH}.tar.gz && rm -rf staticcheck)
|
||||
endif
|
||||
@which misspell 1>/dev/null || (echo "Installing misspell" && GO111MODULE=off go get -u github.com/client9/misspell/cmd/misspell)
|
||||
@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)
|
||||
|
||||
crosscompile:
|
||||
@(env bash $(PWD)/buildscripts/cross-compile.sh)
|
||||
|
||||
verifiers: getdeps vet fmt lint staticcheck spelling
|
||||
verifiers: getdeps vet fmt lint
|
||||
|
||||
docker: build
|
||||
@docker build -t $(TAG) . -f Dockerfile.dev
|
||||
@ -44,19 +38,9 @@ fmt:
|
||||
@GO111MODULE=on gofmt -d pkg/
|
||||
|
||||
lint:
|
||||
@echo "Running $@"
|
||||
@GO111MODULE=on ${GOPATH}/bin/golint -set_exit_status github.com/minio/mc/cmd/...
|
||||
@GO111MODULE=on ${GOPATH}/bin/golint -set_exit_status github.com/minio/mc/pkg/...
|
||||
|
||||
staticcheck:
|
||||
@echo "Running $@"
|
||||
@GO111MODULE=on ${GOPATH}/bin/staticcheck github.com/minio/mc/cmd/...
|
||||
@GO111MODULE=on ${GOPATH}/bin/staticcheck github.com/minio/mc/pkg/...
|
||||
|
||||
spelling:
|
||||
@GO111MODULE=on ${GOPATH}/bin/misspell -locale US -error `find cmd/`
|
||||
@GO111MODULE=on ${GOPATH}/bin/misspell -locale US -error `find pkg/`
|
||||
@GO111MODULE=on ${GOPATH}/bin/misspell -locale US -error `find docs/`
|
||||
@echo "Running $@ check"
|
||||
@GO111MODULE=on ${GOPATH}/bin/golangci-lint cache clean
|
||||
@GO111MODULE=on ${GOPATH}/bin/golangci-lint run --timeout=5m --config ./.golangci.yml
|
||||
|
||||
# Builds mc, runs the verifiers then runs the tests.
|
||||
check: test
|
||||
@ -66,9 +50,16 @@ test: verifiers build
|
||||
@echo "Running functional tests"
|
||||
@(env bash $(PWD)/functional-tests.sh)
|
||||
|
||||
coverage: build
|
||||
@echo "Running all coverage for MinIO"
|
||||
@(env bash $(PWD)/buildscripts/go-coverage.sh)
|
||||
test-race: verifiers build
|
||||
@echo "Running unit tests under -race"
|
||||
@GO111MODULE=on go test -race -v --timeout 20m ./... 1>/dev/null
|
||||
|
||||
# Verify mc binary
|
||||
verify:
|
||||
@echo "Verifying build with race"
|
||||
@GO111MODULE=on CGO_ENABLED=1 go build -race -tags kqueue -trimpath --ldflags "$(LDFLAGS)" -o $(PWD)/mc 1>/dev/null
|
||||
@echo "Running functional tests"
|
||||
@(env bash $(PWD)/functional-tests.sh)
|
||||
|
||||
# Builds mc locally.
|
||||
build: checks
|
||||
|
@ -1,5 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
GO111MODULE=on CGO_ENABLED=0 go test -v -coverprofile=coverage.txt -covermode=atomic ./...
|
@ -185,8 +185,7 @@ func mainAdminConsole(ctx *cli.Context) error {
|
||||
fatalIf(errInvalidArgument().Trace(ctx.Args()...), "please set a proper limit, for example: '--limit 5' to display last 5 logs, omit this flag to display all available logs")
|
||||
}
|
||||
}
|
||||
var logType string
|
||||
logType = strings.ToLower(ctx.String("type"))
|
||||
logType := strings.ToLower(ctx.String("type"))
|
||||
if logType != "minio" && logType != "application" && logType != "all" {
|
||||
fatalIf(errInvalidArgument().Trace(ctx.Args()...), "Invalid value for --type flag. Valid options are [minio, application, all]")
|
||||
}
|
||||
|
@ -352,8 +352,7 @@ func (s *TestSuite) TestCopy(c *C) {
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
data := "hello world"
|
||||
var reader io.Reader
|
||||
reader = bytes.NewReader([]byte(data))
|
||||
reader := bytes.NewReader([]byte(data))
|
||||
n, err := fsClientSource.Put(context.Background(), reader, int64(len(data)), map[string]string{
|
||||
"Content-Type": "application/octet-stream",
|
||||
}, nil, nil, false, false)
|
||||
|
@ -52,16 +52,12 @@ const (
|
||||
idLabel string = "ID"
|
||||
prefixLabel string = "Prefix"
|
||||
statusLabel string = "Enabled "
|
||||
statusDisabledLabel string = "Disabled"
|
||||
expiryLabel string = "Expiry"
|
||||
expiryDatesLabel string = "Date/Days "
|
||||
singleTagLabel string = "Tag"
|
||||
tagLabel string = "Tags"
|
||||
transitionLabel string = "Transition"
|
||||
transitionDateLabel string = "Date/Days "
|
||||
storageClassLabel string = "Storage-Class "
|
||||
forceLabel string = "force"
|
||||
allLabel string = "all"
|
||||
)
|
||||
|
||||
// Keys to be used in map structure which stores the columns to be displayed.
|
||||
@ -70,7 +66,6 @@ const (
|
||||
storageClassLabelKey string = "Storage-Class"
|
||||
expiryDatesLabelKey string = "Expiry-Dates"
|
||||
transitionDatesLabelKey string = "Transition-Date"
|
||||
transitionDaysLabelKey string = "Transition-Days"
|
||||
)
|
||||
|
||||
// Some cell values
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* MinIO Cloud Storage, (C) 2015 MinIO, Inc.
|
||||
* MinIO Cloud Storage, (C) 2015-2020 MinIO, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -143,7 +143,7 @@ func (e *Error) trace(fields ...string) *Error {
|
||||
function := runtime.FuncForPC(pc).Name()
|
||||
_, function = filepath.Split(function)
|
||||
file = strings.TrimPrefix(file, rootPath+string(os.PathSeparator)) // trims project's root path.
|
||||
tp := TracePoint{}
|
||||
var tp TracePoint
|
||||
if len(fields) > 0 {
|
||||
tp = TracePoint{Line: line, Filename: file, Function: function, Env: map[string][]string{"Tags": fields}}
|
||||
} else {
|
||||
|
@ -1 +1 @@
|
||||
checks = ["all", "-S1021", "-ST1005", "-S1016"]
|
||||
checks = ["all", "-S1016"]
|
||||
|
Loading…
x
Reference in New Issue
Block a user