Skip to content

Commit

Permalink
Merge pull request #14 from dnephin/use-filewatcher-env-vars
Browse files Browse the repository at this point in the history
Support env vars for some flags
  • Loading branch information
dnephin committed May 5, 2018
2 parents 3943c8a + b8b8283 commit 3733c90
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
5 changes: 3 additions & 2 deletions dobi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ job=watch:
use: builder
mounts: [source]
interactive: true
command: scripts/watch
env: ['TESTFLAGS={env.TESTFLAGS:}']
command: |
filewatcher -x vendor ./dist/gotestsum -- -test.timeout 10s
env: ['GOTESTSUM_FORMAT=short-verbose']

job=test-unit:
use: builder
Expand Down
2 changes: 1 addition & 1 deletion dobifiles/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ENV PS1="# "


FROM golang as tools
ARG FILEWATCHER=v0.2.1
ARG FILEWATCHER=v0.3.0
RUN go get -d github.com/dnephin/filewatcher && \
cd /go/src/github.com/dnephin/filewatcher && \
git checkout -q "$FILEWATCHER" && \
Expand Down
25 changes: 21 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,30 @@ Formats:
`)
}
flags.BoolVar(&opts.debug, "debug", false, "enabled debug")
flags.StringVar(&opts.format, "format", "short",
flags.StringVar(&opts.format, "format",
lookEnvWithDefault("GOTESTSUM_FORMAT", "short"),
"print format of test input")
flags.BoolVar(&opts.rawCommand, "raw-command", false,
"don't prepend 'go test -json' to the 'go test' command")
flags.StringVar(&opts.jsonFile, "jsonfile", "",
flags.StringVar(&opts.jsonFile, "jsonfile",
lookEnvWithDefault("GOTESTSUM_JSONFILE", ""),
"write all TestEvents to file")
flags.StringVar(&opts.junitFile, "junitfile", "",
flags.StringVar(&opts.junitFile, "junitfile",
lookEnvWithDefault("GOTESTSUM_JUNITFILE", ""),
"write a JUnit XML file")
flags.BoolVar(&opts.noColor, "no-color", false, "disable color output")
flags.StringSliceVar(&opts.noSummary, "no-summary", nil,
"do not print summary of: failed, skipped, errors")
return flags, opts
}

func lookEnvWithDefault(key, defValue string) string {
if value, ok := os.LookupEnv(key); ok {
return value
}
return defValue
}

type options struct {
args []string
format string
Expand Down Expand Up @@ -132,13 +142,20 @@ func goTestCmdArgs(opts *options) []string {
case opts.rawCommand:
return args
case len(args) == 0:
return append(defaultArgs, "-json", "./...")
return append(defaultArgs, "-json", pathFromEnv("./..."))
case !hasJSONArg(args):
defaultArgs = append(defaultArgs, "-json")
}
if testPath := pathFromEnv(""); testPath != "" {
args = append(args, testPath)
}
return append(defaultArgs, args...)
}

func pathFromEnv(defaultPath string) string {
return lookEnvWithDefault("TEST_DIRECTORY", defaultPath)
}

func hasJSONArg(args []string) bool {
for _, arg := range args {
if arg == "-json" || arg == "--json" {
Expand Down
8 changes: 0 additions & 8 deletions scripts/watch

This file was deleted.

0 comments on commit 3733c90

Please sign in to comment.