diff --git a/.travis.yml b/.travis.yml index 04b24b624..478db8dba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,9 +4,4 @@ services: - docker install: true -jobs: - include: - - stage: test - script: make test - # - stage: push - # script: echo "TODO" +script: make test diff --git a/Makefile b/Makefile index aa4beb379..6c7a5f769 100644 --- a/Makefile +++ b/Makefile @@ -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 $< > $@ @@ -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 \ diff --git a/pkg/config/loader_test.go b/pkg/config/loader_test.go index 74515676d..59f7792bb 100644 --- a/pkg/config/loader_test.go +++ b/pkg/config/loader_test.go @@ -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() @@ -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 diff --git a/pkg/discovery/queryrecorder.go b/pkg/discovery/queryrecorder.go index 80030a411..6b54c9430 100644 --- a/pkg/discovery/queryrecorder.go +++ b/pkg/discovery/queryrecorder.go @@ -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), @@ -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)) @@ -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) diff --git a/pkg/errlog/errlog.go b/pkg/errlog/errlog.go index c58fa0b14..a21c8a180 100644 --- a/pkg/errlog/errlog.go +++ b/pkg/errlog/errlog.go @@ -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 diff --git a/pkg/plugin/aggregation/aggregator_test.go b/pkg/plugin/aggregation/aggregator_test.go index d8cfe2485..940d57fe7 100644 --- a/pkg/plugin/aggregation/aggregator_test.go +++ b/pkg/plugin/aggregation/aggregator_test.go @@ -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 } diff --git a/pkg/plugin/aggregation/run.go b/pkg/plugin/aggregation/run.go index f9e3a3dc5..5436ba06c 100644 --- a/pkg/plugin/aggregation/run.go +++ b/pkg/plugin/aggregation/run.go @@ -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 { diff --git a/pkg/plugin/interface.go b/pkg/plugin/interface.go index df637100f..688b8e1fc 100644 --- a/pkg/plugin/interface.go +++ b/pkg/plugin/interface.go @@ -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