Add vetting, formatting and vetting make commands and fix related errors

This commit is contained in:
Riccardo Biraghi
2018-04-11 13:43:57 +01:00
parent f96304ae8f
commit 831f0695a9
8 changed files with 49 additions and 14 deletions

View File

@@ -21,5 +21,6 @@ install:
script: script:
- make deps - make deps
- make vet
- make build-devserver - make build-devserver
- make test-devserver - make test-devserver

View File

@@ -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 all test-all lint
.PHONY: devserver .PHONY: devserver
devserver: build-devserver test-devserver devserver: build-devserver test-devserver
@@ -235,4 +235,26 @@ 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))
# Select all go packages inside the test directory
GO_TEST_PKG = $(sort $(dir $(wildcard ./test/*/*.go)))
GO_TEST_FILES = $(addsuffix /$(wildcard *.go), $(GO_TEST_PKG))
# Select all go packages inside the internal directory
GO_INTERNAL_PKG = $(sort $(dir $(wildcard ./internal/*/*.go)))
GO_INTERNAL_FILES = $(addsuffix /$(wildcard *.go), $(GO_CMD_PKG))
# Select all go packages inside the cmd directory
GO_CMD_PKG = $(sort $(dir $(wildcard ./cmd/*/*.go)))
GO_CMD_FILES = $(addsuffix /$(wildcard *.go), $(GO_CMD_PKG))
fmt: $(GO_CMD_FILES) $(GO_TEST_FILES) $(GO_INTERNAL_FILES)
go fmt $(GO_TEST_PKG) $(GO_CMD_PKG) $(GO_INTERNAL_PKG)
vet: $(GO_CMD_FILES) $(GO_TEST_FILES) $(GO_INTERNAL_FILES)
go vet $(GO_TEST_PKG) $(GO_CMD_PKG) $(GO_INTERNAL_PKG)
lint: $(GO_CMD_FILES) $(GO_TEST_FILES) $(GO_INTERNAL_FILES)
echo "\033[0;31m"; golint $(GO_TEST_PKG) $(GO_CMD_PKG) $(GO_INTERNAL_PKG)
@echo "\033[0m"
include formatting.mk include formatting.mk

View File

@@ -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 {

View File

@@ -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 (

View File

@@ -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...))

View File

@@ -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 (

View File

@@ -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 {

View File

@@ -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,