Skip to content

Commit

Permalink
Add input flag for reading from file instead of reading from pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkDrim committed Jan 21, 2024
1 parent 7dfed48 commit c76ae94
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#FROM alpine
FROM golang:1.14-alpine
ARG GO_VERSION=1.21.5

FROM golang:${GO_VERSION}-alpine

# installs GCC, libc-dev, etc
RUN apk add build-base
Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ LIN_DIR := release_builds/linux-amd64/
MAC_DIR := release_builds/darwin-amd64/
WIN_DIR := release_builds/windows-amd64/

GO_VERSION = 1.21.5

.PHONY: help
help: ## List of available commands
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

.PHONY: go-version
go-version: ## Print Golang version
@echo "$(GO_VERSION)"

genbuild:
go build

Expand Down Expand Up @@ -41,7 +47,7 @@ buildall: genbuild
echo "...Done!"

dockertest: genbuild
docker build . -t go-test-report-test-runner:$(VERSION)
docker build --build-arg GO_VERSION=$(GO_VERSION) . -t go-test-report-test-runner:$(VERSION)

.PHONY: lint
lint: ## Run linter (https://github.com/golangci/golangci-lint/releases)
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
The original version of the library has not been supported for more than three years.

This version has some improvements:
- support for the latest version of Golang
- ability to split groups by package (instead of splitting by number of tests)
- support latest version of Golang (using embed feature)
- ability to split groups by package (instead of splitting by number of tests) (-p option)
- ability to read test results from file (-i option)

## Installation

Expand Down Expand Up @@ -103,6 +104,7 @@ Available Commands:
Flags:
-g, --groupSize int the number of tests per test group indicator (default 20)
-h, --help help for go-test-report
-i, --input string the JSON input file
-o, --output string the HTML output file (default "test_report.html")
-s, --size string the size (in pixels) of the clickable indicator for test result groups (default "24")
-t, --title string the title text shown in the test report (default "go-test-report")
Expand Down
21 changes: 18 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ type (
groupPackage bool
nosortFlag bool
listFlag string
inputFlag string
outputFlag string
verbose bool
}
Expand Down Expand Up @@ -141,10 +142,19 @@ func initRootCommand() (*cobra.Command, *templateData, *cmdFlags) {
tmplData.sortTestsByName = !flags.nosortFlag
tmplData.ReportTitle = flags.titleFlag
tmplData.OutputFilename = flags.outputFlag
if err := checkIfStdinIsPiped(); err != nil {
return err
var stdin *os.File
if flags.inputFlag != "" {
file, err := os.Open(flags.inputFlag)
if err != nil {
return err
}
stdin = file
} else {
if err := checkIfStdinIsPiped(); err != nil {
return err
}
stdin = os.Stdin
}
stdin := os.Stdin
stdinScanner := bufio.NewScanner(stdin)
testReportHTMLTemplateFile, _ := os.Create(tmplData.OutputFilename)
reportFileWriter := bufio.NewWriter(testReportHTMLTemplateFile)
Expand Down Expand Up @@ -227,6 +237,11 @@ func initRootCommand() (*cobra.Command, *templateData, *cmdFlags) {
"l",
"",
"the JSON module list")
rootCmd.PersistentFlags().StringVarP(&flags.inputFlag,
"input",
"i",
"",
"the JSON input file")
rootCmd.PersistentFlags().StringVarP(&flags.outputFlag,
"output",
"o",
Expand Down

0 comments on commit c76ae94

Please sign in to comment.