Skip to content

Commit

Permalink
Merge pull request #126 from liztio/liz-fmtvet
Browse files Browse the repository at this point in the history
Add vet to tests
  • Loading branch information
timothysc authored Nov 2, 2017
2 parents ce9517b + 2da7ccc commit 7278301
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 14 deletions.
7 changes: 1 addition & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,4 @@ services:
- docker
install: true

jobs:
include:
- stage: test
script: make test
# - stage: push
# script: echo "TODO"
script: make test
21 changes: 17 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,22 @@ BUILDCMD = go build -o $(TARGET) -v -ldflags "-X github.com/heptio/sonobuoy/pkg/
BUILD = $(BUILDCMD) $(GOTARGET)/cmd/sonobuoy

TESTARGS ?= -v -timeout 60s
TEST = go test $(TEST_PKGS) $(TESTARGS)
TEST_PKGS ?= $(GOTARGET)/cmd/... $(GOTARGET)/pkg/...
TEST = go test $(TEST_PKGS) $(TESTARGS)

VET = go vet $(TEST_PKGS)

# Vendor this someday
INSTALL_GOLINT = go get -u github.com/golang/lint/golint
GOLINT_FLAGS ?= -set_exit_status
LINT = $(INSTALL_GOLINT) && golint $(GOLINT_FLAGS) $(TEST_PKGS)

WORKDIR ?= /sonobuoy
RBAC_ENABLED ?= 1
KUBECFG_CMD = $(DOCKER) run \
-v $(DIR):$(WORKDIR) \
--workdir $(WORKDIR) \
--rm \
- --rm \
$(KSONNET_BUILD_IMAGE) \
kubecfg show -o yaml -V RBAC_ENABLED=$(RBAC_ENABLED) -J $(WORKDIR) -o yaml $< > $@

Expand All @@ -56,8 +63,14 @@ DOCKER_BUILD ?= $(DOCKER) run --rm -v $(DIR):$(BUILDMNT) -w $(BUILDMNT) $(BUILD_

all: container

test: cbuild
$(DOCKER_BUILD) '$(TEST)'
test: cbuild vet
$(DOCKER_BUILD) '$(TEST)'

lint:
$(DOCKER_BUILD) '$(LINT)'

vet:
$(DOCKER_BUILD) '$(VET)'

container: test
$(DOCKER) build \
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestSaveAndLoad(t *testing.T) {
}
defer os.Remove("./config.json")
} else {
t.Fatalf("Failed to serialize ", err)
t.Fatalf("Failed to serialize %v", err)
}

cfg2, err := LoadConfig()
Expand Down Expand Up @@ -145,7 +145,7 @@ func TestLoadAllPlugins(t *testing.T) {
}

if len(dsplugin.GetPodSpec().Containers) != 2 {
t.Fatalf("JobPlugin should have 1 container, got 2", len(jobplugin.GetPodSpec().Containers))
t.Fatalf("JobPlugin should have 2 containers, got %d", len(jobplugin.GetPodSpec().Containers))
}

firstContainerName = jobplugin.GetPodSpec().Containers[0].Name
Expand Down
4 changes: 4 additions & 0 deletions pkg/discovery/queryrecorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ import (
"github.com/pkg/errors"
)

// QueryRecorder records a sequence of queries
type QueryRecorder struct {
queries []*queryData
}

// NewQueryRecorder returns a new empty QueryRecorder
func NewQueryRecorder() *QueryRecorder {
return &QueryRecorder{
queries: make([]*queryData, 0),
Expand All @@ -44,6 +46,7 @@ type queryData struct {
Error error `json:"error,omitempty"`
}

// RecordQuery transcribes a query by name, namespace, duration and error
func (q *QueryRecorder) RecordQuery(name string, namespace string, duration time.Duration, recerr error) {
if recerr != nil {
errlog.LogError(errors.Wrapf(recerr, "error querying %v", name))
Expand All @@ -58,6 +61,7 @@ func (q *QueryRecorder) RecordQuery(name string, namespace string, duration time
q.queries = append(q.queries, summary)
}

// DumpQueryData writes query information out to a file at the give filepath
func (q *QueryRecorder) DumpQueryData(filepath string) error {
// Ensure the leading path is created
err := os.MkdirAll(path.Dir(filepath), 0755)
Expand Down
2 changes: 2 additions & 0 deletions pkg/errlog/errlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import (
"github.com/sirupsen/logrus"
)

// DebugOutput controls whether to output the trace of every error
var DebugOutput = false

// LogError logs an error, optionally with a tracelog
func LogError(err error) {
if DebugOutput {
// Print the error message with the stack trace (%+v) in the "trace" field
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/aggregation/aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func makeTarWithContents(t *testing.T, filename string, fileContents []byte) (ta
tardir := path.Join(dir, "results")
err = os.Mkdir(tardir, 0755)
if err != nil {
t.Fatal("Could not create results directory %v: %v", tardir, err)
t.Fatalf("Could not create results directory %v: %v", tardir, err)
return
}

Expand Down
1 change: 1 addition & 0 deletions pkg/plugin/aggregation/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func Run(client kubernetes.Interface, plugins []plugin.Interface, cfg plugin.Agg
return nil
}

// Cleanup calls cleanup on all plugins
func Cleanup(client kubernetes.Interface, plugins []plugin.Interface) {
// Cleanup after each plugin
for _, p := range plugins {
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ type AggregationConfig struct {
// WorkerConfig is the file given to the sonobuoy worker to configure it to phone home.
type WorkerConfig struct {
// MasterURL is the URL we talk to for submitting results
MasterURL string `json:"masterurl,omitempty mapstructure:"masterurl""`
MasterURL string `json:"masterurl,omitempty" mapstructure:"masterurl"`
// NodeName is the node name we should call ourselves when sending results
NodeName string `json:"nodename,omitempty" mapstructure:"nodename"`
// ResultsDir is the directory that's expected to contain the host's root filesystem
Expand Down

0 comments on commit 7278301

Please sign in to comment.