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:
|
services:
|
||||||
- docker
|
- docker
|
||||||
|
|
||||||
|
go_import_path: "github.com/ibm-messaging/mq-container"
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
|
- 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"
|
- sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
|
||||||
@@ -21,5 +23,10 @@ install:
|
|||||||
|
|
||||||
script:
|
script:
|
||||||
- make deps
|
- make deps
|
||||||
|
- make vet
|
||||||
- make build-devserver
|
- make build-devserver
|
||||||
- make test-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
|
test-all: test-devserver test-advancedserver
|
||||||
|
|
||||||
.PHONY: precommit
|
.PHONY: precommit
|
||||||
precommit: all test-all
|
precommit: vet fmt lint all test-all
|
||||||
|
|
||||||
.PHONY: devserver
|
.PHONY: devserver
|
||||||
devserver: build-devserver test-devserver
|
devserver: build-devserver test-devserver
|
||||||
@@ -144,7 +144,7 @@ test-unit:
|
|||||||
.PHONY: test-advancedserver
|
.PHONY: test-advancedserver
|
||||||
test-advancedserver: test/docker/vendor
|
test-advancedserver: test/docker/vendor
|
||||||
$(info $(SPACER)$(shell printf $(TITLE)"Test $(MQ_IMAGE_ADVANCEDSERVER) on Docker"$(END)))
|
$(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
|
.PHONY: build-devjmstest
|
||||||
build-devjmstest:
|
build-devjmstest:
|
||||||
@@ -235,4 +235,17 @@ build-advancedserver-cover: docker-version
|
|||||||
build-explorer: downloads/$(MQ_ARCHIVE_DEV)
|
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))
|
$(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
|
include formatting.mk
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import (
|
|||||||
"github.com/ibm-messaging/mq-container/internal/command"
|
"github.com/ibm-messaging/mq-container/internal/command"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// KeyStore describes information about a keystore file
|
||||||
type KeyStore struct {
|
type KeyStore struct {
|
||||||
Filename string
|
Filename string
|
||||||
Password string
|
Password string
|
||||||
@@ -72,7 +73,7 @@ func (ks *KeyStore) Create() error {
|
|||||||
return nil
|
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 {
|
func (ks *KeyStore) CreateStash() error {
|
||||||
extension := filepath.Ext(ks.Filename)
|
extension := filepath.Ext(ks.Filename)
|
||||||
stashFile := ks.Filename[0:len(ks.Filename)-len(extension)] + ".sth"
|
stashFile := ks.Filename[0:len(ks.Filename)-len(extension)] + ".sth"
|
||||||
@@ -96,6 +97,7 @@ func (ks *KeyStore) CreateStash() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Import imports a certificate file in the keystore
|
||||||
func (ks *KeyStore) Import(inputFile, password string) error {
|
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)
|
_, _, 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 {
|
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");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with 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.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// capabilities allows querying of information on Linux capabilities
|
// Package capabilities allows querying of information on Linux capabilities
|
||||||
package capabilities
|
package capabilities
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Package logger provides utility functions for logging purposes
|
||||||
package logger
|
package logger
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -108,46 +109,56 @@ func (l *Logger) log(level string, msg string) {
|
|||||||
l.mutex.Unlock()
|
l.mutex.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LogDirect logs a message directly to stdout
|
||||||
func (l *Logger) LogDirect(msg string) {
|
func (l *Logger) LogDirect(msg string) {
|
||||||
fmt.Println(msg)
|
fmt.Println(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Debug logs a line as debug
|
||||||
func (l *Logger) Debug(args ...interface{}) {
|
func (l *Logger) Debug(args ...interface{}) {
|
||||||
if l.debug {
|
if l.debug {
|
||||||
l.log(debugLevel, fmt.Sprint(args...))
|
l.log(debugLevel, fmt.Sprint(args...))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Debugf logs a line as debug using format specifiers
|
||||||
func (l *Logger) Debugf(format string, args ...interface{}) {
|
func (l *Logger) Debugf(format string, args ...interface{}) {
|
||||||
if l.debug {
|
if l.debug {
|
||||||
l.log(debugLevel, fmt.Sprintf(format, args...))
|
l.log(debugLevel, fmt.Sprintf(format, args...))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Print logs a message as info
|
||||||
func (l *Logger) Print(args ...interface{}) {
|
func (l *Logger) Print(args ...interface{}) {
|
||||||
l.log(infoLevel, fmt.Sprint(args...))
|
l.log(infoLevel, fmt.Sprint(args...))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Println logs a message
|
||||||
func (l *Logger) Println(args ...interface{}) {
|
func (l *Logger) Println(args ...interface{}) {
|
||||||
l.Print(args...)
|
l.Print(args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Printf logs a message as info using format specifiers
|
||||||
func (l *Logger) Printf(format string, args ...interface{}) {
|
func (l *Logger) Printf(format string, args ...interface{}) {
|
||||||
l.log(infoLevel, fmt.Sprintf(format, args...))
|
l.log(infoLevel, fmt.Sprintf(format, args...))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PrintString logs a string as info
|
||||||
func (l *Logger) PrintString(msg string) {
|
func (l *Logger) PrintString(msg string) {
|
||||||
l.log(infoLevel, msg)
|
l.log(infoLevel, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Errorf logs a message as error
|
||||||
func (l *Logger) Error(args ...interface{}) {
|
func (l *Logger) Error(args ...interface{}) {
|
||||||
l.log(errorLevel, fmt.Sprint(args...))
|
l.log(errorLevel, fmt.Sprint(args...))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Errorf logs a message as error using format specifiers
|
||||||
func (l *Logger) Errorf(format string, args ...interface{}) {
|
func (l *Logger) Errorf(format string, args ...interface{}) {
|
||||||
l.log(errorLevel, fmt.Sprintf(format, args...))
|
l.log(errorLevel, fmt.Sprintf(format, args...))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fatalf logs a message as fatal using format specifiers
|
||||||
// TODO: Remove this
|
// TODO: Remove this
|
||||||
func (l *Logger) Fatalf(format string, args ...interface{}) {
|
func (l *Logger) Fatalf(format string, args ...interface{}) {
|
||||||
l.log("FATAL", fmt.Sprintf(format, args...))
|
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
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Package mqini provides information about queue managers
|
||||||
package mqini
|
package mqini
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@@ -296,7 +296,7 @@ func TestVolumeUnmount(t *testing.T) {
|
|||||||
t.Errorf("Expected chkmqhealthy to fail")
|
t.Errorf("Expected chkmqhealthy to fail")
|
||||||
_, df := execContainer(t, cli, ctr.ID, "mqm", []string{"df"})
|
_, df := execContainer(t, cli, ctr.ID, "mqm", []string{"df"})
|
||||||
t.Logf(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)
|
t.Logf(ps)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -404,7 +404,7 @@ func TestReadiness(t *testing.T) {
|
|||||||
t.Logf("readyRC=%v,queueCheckRC=%v\n", readyRC, queueCheckRC)
|
t.Logf("readyRC=%v,queueCheckRC=%v\n", readyRC, queueCheckRC)
|
||||||
|
|
||||||
if readyRC == 0 {
|
if readyRC == 0 {
|
||||||
if (queueCheckRC != 0) {
|
if queueCheckRC != 0 {
|
||||||
r := regexp.MustCompile("AMQ[0-9][0-9][0-9][0-9]E")
|
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)
|
t.Fatalf("Runmqsc returned %v with error %v. chkmqready returned %v when MQSC had not finished", queueCheckRC, r.FindString(queueCheckOut), readyRC)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -27,12 +27,12 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
"regexp"
|
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
@@ -86,31 +86,28 @@ func coverageBind(t *testing.T) string {
|
|||||||
func isWSL(t *testing.T) bool {
|
func isWSL(t *testing.T) bool {
|
||||||
if runtime.GOOS == "linux" {
|
if runtime.GOOS == "linux" {
|
||||||
uname, err := exec.Command("uname", "-r").Output()
|
uname, err := exec.Command("uname", "-r").Output()
|
||||||
if (err != nil) {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
return strings.Contains(string(uname), "Microsoft")
|
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
|
// getWindowsRoot get the path of the root directory on Windows, in UNIX or OS-specific style
|
||||||
func getWindowsRoot(unixStylePath bool) string {
|
func getWindowsRoot(unixStylePath bool) string {
|
||||||
if unixStylePath {
|
if unixStylePath {
|
||||||
return "/mnt/c/"
|
return "/mnt/c/"
|
||||||
} else {
|
|
||||||
return "C:/"
|
|
||||||
}
|
}
|
||||||
|
return "C:/"
|
||||||
}
|
}
|
||||||
|
|
||||||
// getTempDir get the path of the tmp directory, in UNIX or OS-specific style
|
// getTempDir get the path of the tmp directory, in UNIX or OS-specific style
|
||||||
func getTempDir(t *testing.T, unixStylePath bool) string {
|
func getTempDir(t *testing.T, unixStylePath bool) string {
|
||||||
if isWSL(t) {
|
if isWSL(t) {
|
||||||
return getWindowsRoot(unixStylePath) + "Temp/"
|
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
|
// 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
|
// 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) {
|
func execContainer(t *testing.T, cli *client.Client, ID string, user string, cmd []string) (int, string) {
|
||||||
rerun:
|
rerun:
|
||||||
config := types.ExecConfig{
|
config := types.ExecConfig{
|
||||||
User: user,
|
User: user,
|
||||||
Privileged: false,
|
Privileged: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user