Merge pull request #54 from riccardobiraghi/master
Add go vet, go fmt and golint to makefile
This commit is contained in:
@@ -7,6 +7,8 @@ go:
|
||||
services:
|
||||
- docker
|
||||
|
||||
go_import_path: "github.com/ibm-messaging/mq-container"
|
||||
|
||||
before_install:
|
||||
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
|
||||
- sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
|
||||
@@ -21,5 +23,10 @@ install:
|
||||
|
||||
script:
|
||||
- make deps
|
||||
- make vet
|
||||
- make build-devserver
|
||||
- make test-devserver
|
||||
|
||||
after_success:
|
||||
- go get golang.org/x/lint/golint
|
||||
- make lint
|
||||
|
||||
17
Makefile
17
Makefile
@@ -100,7 +100,7 @@ all: build-devserver build-advancedserver
|
||||
test-all: test-devserver test-advancedserver
|
||||
|
||||
.PHONY: precommit
|
||||
precommit: all test-all
|
||||
precommit: vet fmt lint all test-all
|
||||
|
||||
.PHONY: devserver
|
||||
devserver: build-devserver test-devserver
|
||||
@@ -144,7 +144,7 @@ test-unit:
|
||||
.PHONY: test-advancedserver
|
||||
test-advancedserver: test/docker/vendor
|
||||
$(info $(SPACER)$(shell printf $(TITLE)"Test $(MQ_IMAGE_ADVANCEDSERVER) on Docker"$(END)))
|
||||
cd test/docker && TEST_IMAGE=$(MQ_IMAGE_ADVANCEDSERVER) go test -timeout 20m -parallel $(NUM_CPU) $(TEST_OPTS_DOCKER)
|
||||
cd test/docker && TEST_IMAGE=$(MQ_IMAGE_ADVANCEDSERVER) go test -parallel $(NUM_CPU) $(TEST_OPTS_DOCKER)
|
||||
|
||||
.PHONY: build-devjmstest
|
||||
build-devjmstest:
|
||||
@@ -235,4 +235,17 @@ build-advancedserver-cover: docker-version
|
||||
build-explorer: downloads/$(MQ_ARCHIVE_DEV)
|
||||
$(call docker-build-mq,mq-explorer:latest-$(ARCH),incubating/mq-explorer/Dockerfile-mq-explorer,$(MQ_ARCHIVE_DEV),"98102d16795c4263ad9ca075190a2d4d","IBM MQ Advanced for Developers (Non-Warranted)",$(MQ_VERSION))
|
||||
|
||||
GO_PKG_DIRS = ./cmd ./internal ./test
|
||||
|
||||
fmt: $(addsuffix /$(wildcard *.go), $(GO_PKG_DIRS))
|
||||
go fmt $(addsuffix /..., $(GO_PKG_DIRS))
|
||||
|
||||
vet: $(addsuffix /$(wildcard *.go), $(GO_PKG_DIRS)) test/docker/vendor
|
||||
go vet $(addsuffix /..., $(GO_PKG_DIRS))
|
||||
|
||||
lint: $(addsuffix /$(wildcard *.go), $(GO_PKG_DIRS))
|
||||
@# This expression is necessary because /... includes the vendor directory in golint
|
||||
@# As of 11/04/2018 there is an open issue to fix it: https://github.com/golang/lint/issues/320
|
||||
golint -set_exit_status $(sort $(dir $(wildcard $(addsuffix /*/*.go, $(GO_PKG_DIRS)))))
|
||||
|
||||
include formatting.mk
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
"github.com/ibm-messaging/mq-container/internal/command"
|
||||
)
|
||||
|
||||
// KeyStore describes information about a keystore file
|
||||
type KeyStore struct {
|
||||
Filename string
|
||||
Password string
|
||||
@@ -72,7 +73,7 @@ func (ks *KeyStore) Create() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Create a key stash, if it doesn't already exist
|
||||
// CreateStash creates a key stash, if it doesn't already exist
|
||||
func (ks *KeyStore) CreateStash() error {
|
||||
extension := filepath.Ext(ks.Filename)
|
||||
stashFile := ks.Filename[0:len(ks.Filename)-len(extension)] + ".sth"
|
||||
@@ -96,6 +97,7 @@ func (ks *KeyStore) CreateStash() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Import imports a certificate file in the keystore
|
||||
func (ks *KeyStore) Import(inputFile, password string) error {
|
||||
_, _, err := command.Run(ks.command, "-cert", "-import", "-file", inputFile, "-pw", password, "-target", ks.Filename, "-target_pw", ks.Password, "-target_type", ks.keyStoreType)
|
||||
if err != nil {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
© Copyright IBM Corporation 2017
|
||||
© Copyright IBM Corporation 2017, 2018
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// capabilities allows querying of information on Linux capabilities
|
||||
// Package capabilities allows querying of information on Linux capabilities
|
||||
package capabilities
|
||||
|
||||
import (
|
||||
|
||||
@@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Package logger provides utility functions for logging purposes
|
||||
package logger
|
||||
|
||||
import (
|
||||
@@ -108,46 +109,56 @@ func (l *Logger) log(level string, msg string) {
|
||||
l.mutex.Unlock()
|
||||
}
|
||||
|
||||
// LogDirect logs a message directly to stdout
|
||||
func (l *Logger) LogDirect(msg string) {
|
||||
fmt.Println(msg)
|
||||
}
|
||||
|
||||
// Debug logs a line as debug
|
||||
func (l *Logger) Debug(args ...interface{}) {
|
||||
if l.debug {
|
||||
l.log(debugLevel, fmt.Sprint(args...))
|
||||
}
|
||||
}
|
||||
|
||||
// Debugf logs a line as debug using format specifiers
|
||||
func (l *Logger) Debugf(format string, args ...interface{}) {
|
||||
if l.debug {
|
||||
l.log(debugLevel, fmt.Sprintf(format, args...))
|
||||
}
|
||||
}
|
||||
|
||||
// Print logs a message as info
|
||||
func (l *Logger) Print(args ...interface{}) {
|
||||
l.log(infoLevel, fmt.Sprint(args...))
|
||||
}
|
||||
|
||||
// Println logs a message
|
||||
func (l *Logger) Println(args ...interface{}) {
|
||||
l.Print(args...)
|
||||
}
|
||||
|
||||
// Printf logs a message as info using format specifiers
|
||||
func (l *Logger) Printf(format string, args ...interface{}) {
|
||||
l.log(infoLevel, fmt.Sprintf(format, args...))
|
||||
}
|
||||
|
||||
// PrintString logs a string as info
|
||||
func (l *Logger) PrintString(msg string) {
|
||||
l.log(infoLevel, msg)
|
||||
}
|
||||
|
||||
// Errorf logs a message as error
|
||||
func (l *Logger) Error(args ...interface{}) {
|
||||
l.log(errorLevel, fmt.Sprint(args...))
|
||||
}
|
||||
|
||||
// Errorf logs a message as error using format specifiers
|
||||
func (l *Logger) Errorf(format string, args ...interface{}) {
|
||||
l.log(errorLevel, fmt.Sprintf(format, args...))
|
||||
}
|
||||
|
||||
// Fatalf logs a message as fatal using format specifiers
|
||||
// TODO: Remove this
|
||||
func (l *Logger) Fatalf(format string, args ...interface{}) {
|
||||
l.log("FATAL", fmt.Sprintf(format, args...))
|
||||
|
||||
@@ -13,6 +13,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Package mqini provides information about queue managers
|
||||
package mqini
|
||||
|
||||
import (
|
||||
|
||||
@@ -296,7 +296,7 @@ func TestVolumeUnmount(t *testing.T) {
|
||||
t.Errorf("Expected chkmqhealthy to fail")
|
||||
_, df := execContainer(t, cli, ctr.ID, "mqm", []string{"df"})
|
||||
t.Logf(df)
|
||||
_, ps :=execContainer(t, cli, ctr.ID, "mqm", []string{"ps", "-ef"})
|
||||
_, ps := execContainer(t, cli, ctr.ID, "mqm", []string{"ps", "-ef"})
|
||||
t.Logf(ps)
|
||||
}
|
||||
}
|
||||
@@ -404,7 +404,7 @@ func TestReadiness(t *testing.T) {
|
||||
t.Logf("readyRC=%v,queueCheckRC=%v\n", readyRC, queueCheckRC)
|
||||
|
||||
if readyRC == 0 {
|
||||
if (queueCheckRC != 0) {
|
||||
if queueCheckRC != 0 {
|
||||
r := regexp.MustCompile("AMQ[0-9][0-9][0-9][0-9]E")
|
||||
t.Fatalf("Runmqsc returned %v with error %v. chkmqready returned %v when MQSC had not finished", queueCheckRC, r.FindString(queueCheckOut), readyRC)
|
||||
} else {
|
||||
|
||||
@@ -27,12 +27,12 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
"regexp"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
@@ -86,31 +86,28 @@ func coverageBind(t *testing.T) string {
|
||||
func isWSL(t *testing.T) bool {
|
||||
if runtime.GOOS == "linux" {
|
||||
uname, err := exec.Command("uname", "-r").Output()
|
||||
if (err != nil) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return strings.Contains(string(uname), "Microsoft")
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// getWindowsRoot get the path of the root directory on Windows, in UNIX or OS-specific style
|
||||
func getWindowsRoot(unixStylePath bool) string {
|
||||
if unixStylePath {
|
||||
return "/mnt/c/"
|
||||
} else {
|
||||
return "C:/"
|
||||
}
|
||||
return "C:/"
|
||||
}
|
||||
|
||||
// getTempDir get the path of the tmp directory, in UNIX or OS-specific style
|
||||
func getTempDir(t *testing.T, unixStylePath bool) string {
|
||||
if isWSL(t) {
|
||||
return getWindowsRoot(unixStylePath) + "Temp/"
|
||||
} else {
|
||||
return "/tmp/"
|
||||
}
|
||||
return "/tmp/"
|
||||
}
|
||||
|
||||
// terminationLogUnixPath returns the name of the file to use for the termination log message, with a UNIX path
|
||||
@@ -304,7 +301,7 @@ func waitForContainer(t *testing.T, cli *client.Client, ID string, timeout int64
|
||||
|
||||
// execContainer runs a command in a running container, and returns the exit code and output
|
||||
func execContainer(t *testing.T, cli *client.Client, ID string, user string, cmd []string) (int, string) {
|
||||
rerun:
|
||||
rerun:
|
||||
config := types.ExecConfig{
|
||||
User: user,
|
||||
Privileged: false,
|
||||
|
||||
Reference in New Issue
Block a user