Skip to content

Commit

Permalink
added optional test timeout flag
Browse files Browse the repository at this point in the history
  • Loading branch information
nikogura committed Apr 20, 2021
1 parent 3c22a7a commit fe7447f
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Binaries are dropped into the current working directory.
}

if !buildSkipTests {
err = lang.Test(workDir, meta.Package)
err = lang.Test(workDir, meta.Package, testTimeout)
if err != nil {
log.Fatalf("error running go test: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Publish will upload your binaries to wherever it is you've configured them to go
}

if !pubSkipTests {
err = lang.Test(workDir, meta.Package)
err = lang.Test(workDir, meta.Package, testTimeout)
if err != nil {
log.Fatalf("error running go test: %s", err)
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var branch string
var dryrun bool
var workdir string
var buildSkipTargets string
var testTimeout string

//var pubSkipTargets string

Expand Down Expand Up @@ -59,6 +60,7 @@ func init() {
rootCmd.PersistentFlags().StringVarP(&branch, "branch", "b", "master", "Branch to operate upon")
rootCmd.PersistentFlags().StringVarP(&workdir, "workdir", "w", "", "Workdir. If omitted, a temp dir will be created and subsequently cleaned up.")
rootCmd.PersistentFlags().StringVarP(&buildSkipTargets, "skip-build-targets", "", "", fmt.Sprintf("Comma separated list of build targets from %s to skip.", gomason.METADATA_FILENAME))
rootCmd.PersistentFlags().StringVarP(&testTimeout, "test-timeout", "", "", "timeout for tests to complete (must be valid time input for language)")

//rootCmd.PersistentFlags().StringVarP(&pubSkipTargets, fmt.Sprintf("skip-publish-targets", "", "", "Comma separated list of publish targets from %s to skip.", gomason.METADATA_FILENAME))
}
2 changes: 1 addition & 1 deletion cmd/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Signing sorta implies something to sign, which in turn, implies that it built, w
log.Fatalf("error running prep steps: %s", err)
}

err = lang.Test(workDir, meta.Package)
err = lang.Test(workDir, meta.Package, testTimeout)
if err != nil {
log.Fatalf("error running go test: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Sometimes you need the benefits of a full system here. Now. Right at your fing
log.Fatalf("error running prep steps: %s", err)
}

err = lang.Test(workDir, meta.Package)
err = lang.Test(workDir, meta.Package, testTimeout)
if err != nil {
log.Fatalf("error running go test: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.7.0",
"version": "2.8.0",
"package": "github.com/nikogura/gomason",
"description": "A tool for testing, building, signing, and publishing your project from a clean workspace.",
"repository": "http://localhost:8081/artifactory/generic-local",
Expand Down
10 changes: 8 additions & 2 deletions pkg/gomason/golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (Golang) Prep(gopath string, meta Metadata) (err error) {
}

// Test Runs 'go test -v ./...' in the checked out code directory
func (Golang) Test(gopath string, gomodule string) (err error) {
func (Golang) Test(gopath string, gomodule string, timeout string) (err error) {
wd := filepath.Join(gopath, "src", gomodule)

log.Printf("[DEBUG] Changing working directory to %s.\n", wd)
Expand All @@ -168,7 +168,13 @@ func (Golang) Test(gopath string, gomodule string) (err error) {

log.Print("[DEBUG] Running 'go test -v ./...'.\n\n")

cmd := exec.Command("go", "test", "-v", "./...")
var timeoutArg string

if timeout != "" {
timeoutArg = fmt.Sprintf("-timeout %s", timeout)
}

cmd := exec.Command("go", "test", "-v", timeoutArg, "./...")

runenv := append(os.Environ(), fmt.Sprintf("GOPATH=%s", gopath))
runenv = append(runenv, "GO111MODULE=on")
Expand Down
2 changes: 1 addition & 1 deletion pkg/gomason/golang_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func TestTest(t *testing.T) {
t.FailNow()
}

err = lang.Test(gopath, testMetadataObj().Package)
err = lang.Test(gopath, testMetadataObj().Package, "10m")
if err != nil {
log.Printf("error running go test: %s", err)
t.FailNow()
Expand Down
4 changes: 2 additions & 2 deletions pkg/gomason/languages.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Language interface {
CreateWorkDir(string) (string, error)
Checkout(workdir string, meta Metadata, branch string) error
Prep(workdir string, meta Metadata) error
Test(workdir string, module string) error
Test(workdir string, module string, timeout string) error
Build(workdir string, meta Metadata, skipTargets string) error
}

Expand All @@ -37,7 +37,7 @@ func (NoLanguage) Prep(workdir string, meta Metadata) error {
}

// Test Stub for the Test action
func (NoLanguage) Test(workdir string, module string) error {
func (NoLanguage) Test(workdir string, module string, timeout string) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/gomason/languages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestNoLanguage(t *testing.T) {
err = nl.Prep("", Metadata{})
assert.True(t, err == nil, "Prep returned an error")

err = nl.Test("", "")
err = nl.Test("", "", "")
assert.True(t, err == nil, "Test returned an error")

err = nl.Build("", Metadata{}, "")
Expand Down

0 comments on commit fe7447f

Please sign in to comment.