Skip to content

Commit

Permalink
test updates (vakenbolt#4)
Browse files Browse the repository at this point in the history
* Adding command line flags (still need to cleanup some of the code)

* adds error message for missing pipe

* Adds unit test for the go side of the code

* adds go test in dockerfile

* some code refactoring and adds more test

* adds support for running go test in the CI docker file.

* adds a default to the groupSize flag

* adds test for groupSize

* some minor test updates

* more refactorings and updated test

* updated tests and added more tests

* adds shorthand flag for the title flag

* removed shortand tests

* moved the stdin checker into the main processing block

* updates to documentation and test

* added minor code-refactoring and fixing some broken test

* adds a short hand for the --groupSize flag

* adds AST parsing code to retrieve the filenames associated with test function names

* added initial code to map test names to their associated go test files.

* Adds the test file with line and col position information

* code cleanup

* added embedded assets into the binary

* updated dockerfile to fix broken build

* removed unnecessary generated code

* added verbose flag

* add total time at the end of process

* removed unneeded code

* updated readme

* adds a build script for mac, linux and windows builds

* updates release build file to create the destination folders before performing builds.

* added a little more clarity to the -groupSize usage description

* updates template to support change the html window title in addition to the title on the page

* updated readme and removed unneeded code

* nomenclature update

* added the embedded_assets.go file

* updates to the default test report template

* added the generate_embedded_go_code bash script

* moved some files around. preparing for commit to master

* moved assets to the root project folder and added test duration to the test report

* tweaked the test report template

* changes default groupSize from 10 to 20.

* small teak to the test report ui

* updated broken test

* added an ellipsis to test names that are to long

* updates the test report ui to show 'n/a' if a test was not found in the package

* Adds test execution date to test report html

* fixes date formatted problem in test execution date

* deleted jeykll file

* adds a unit test for the TestGenerateReport function

* test updates

* updated readme

* updates to readme file

* moved some things around in the readme file

* removed unneeded image in readme

* removing old files

* replacing shell scripts with makefile

* updated Dockerfile to use Makefile for builds

* updates to the readme file

* Removed support for 32bit version of windows binary

* changed default make command

* adds compresion support in the buildall target in Makefile

* added getPackageDetails as parameter to the generateReport function and updated associated test

* added test coverage for the parseSizeFlag function
  • Loading branch information
vakenbolt authored Jul 11, 2020
1 parent 2b7d8b3 commit 00c3dc8
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 17 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
genbuild: gencode
go build

gencode:
(cd embed_assets/;set -e;go build;./embed_assets)

Expand All @@ -13,11 +13,15 @@ buildall: genbuild

echo "Linux 64bit"
GOOS=linux GOARCH=amd64 go build -o release_builds/linux-amd64/
(cd release_builds/linux-amd64/; tar -czf go-test-report-linux-amd64.tgz go-test-report)

echo "Darwin (MacOS) 64bit"
GOOS=darwin GOARCH=amd64 go build -o release_builds/darwin-amd64/
(cd release_builds/darwin-amd64/; tar -czf go-test-report-darwin-amd64.tgz go-test-report)
(cd release_builds/darwin-amd64/; tar -czf go-test-report-darwin-amd64.tgz go-test-report)

echo "Windows 64bit"
GOOS=windows GOARCH=amd64 go build -o release_builds/windows-amd64/
(cd release_builds/windows-amd64/; zip -r go-test-report-windows-amd64.zip go-test-report.exe)

echo "...Done!"
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func newRootCommand() (*cobra.Command, *TemplateData, *cmdFlags) {
e = err
}
}()
if err := generateReport(stdinScanner, flags, tmplData, reportFileWriter, cmd); err != nil {
if err := generateReport(getPackageDetails, stdinScanner, flags, tmplData, reportFileWriter, cmd); err != nil {
return errors.New(err.Error() + "\n")
}
elapsedTime := time.Since(startTime)
Expand Down Expand Up @@ -188,7 +188,8 @@ func newRootCommand() (*cobra.Command, *TemplateData, *cmdFlags) {
return rootCmd, tmplData, flags
}

func generateReport(stdinScanner *bufio.Scanner, flags *cmdFlags, tmplData *TemplateData, reportFileWriter *bufio.Writer, cmd *cobra.Command) (e error) {
func generateReport(getPackageDetails func(allPackageNames map[string]*types.Nil) (TestFileDetailsByPackage, error),
stdinScanner *bufio.Scanner, flags *cmdFlags, tmplData *TemplateData, reportFileWriter *bufio.Writer, cmd *cobra.Command) (e error) {
var err error
var allTests = map[string]*TestStatus{}
var allPackageNames = map[string]*types.Nil{}
Expand Down
93 changes: 79 additions & 14 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
"go/types"
"io/ioutil"
"strings"
"testing"
Expand Down Expand Up @@ -149,10 +150,10 @@ func TestGenerateReport(t *testing.T) {
{"Time":"2020-07-10T01:24:44.270071-05:00","Action":"output","Package":"go-test-report","Test":"TestFunc1","Output":"=== RUN TestFunc1\n"}
{"Time":"2020-07-10T01:24:44.270295-05:00","Action":"output","Package":"go-test-report","Test":"TestFunc1","Output":"--- PASS: TestFunc1 (1.25s)\n"}
{"Time":"2020-07-10T01:24:44.270311-05:00","Action":"pass","Package":"go-test-report","Test":"TestFunc1","Elapsed":1.25}
{"Time":"2020-07-10T01:24:44.269511-05:00","Action":"run","Package":"go-test-report","Test":"TestFunc2"}
{"Time":"2020-07-10T01:24:44.270071-05:00","Action":"output","Package":"go-test-report","Test":"TestFunc2","Output":"=== RUN TestFunc2\n"}
{"Time":"2020-07-10T01:24:44.270295-05:00","Action":"output","Package":"go-test-report","Test":"TestFunc2","Output":"--- PASS: TestFunc2 (0.25s)\n"}
{"Time":"2020-07-10T01:24:44.270311-05:00","Action":"pass","Package":"go-test-report","Test":"TestFunc2","Elapsed":0.25}
{"Time":"2020-07-10T01:24:44.269511-05:00","Action":"run","Package":"package2","Test":"TestFunc2"}
{"Time":"2020-07-10T01:24:44.270071-05:00","Action":"output","Package":"package2","Test":"TestFunc2","Output":"=== RUN TestFunc2\n"}
{"Time":"2020-07-10T01:24:44.270295-05:00","Action":"output","Package":"package2","Test":"TestFunc2","Output":"--- PASS: TestFunc2 (0.25s)\n"}
{"Time":"2020-07-10T01:24:44.270311-05:00","Action":"pass","Package":"package2","Test":"TestFunc2","Elapsed":0.25}
{"Time":"2020-07-10T01:24:44.269511-05:00","Action":"run","Package":"go-test-report","Test":"TestFunc3"}
{"Time":"2020-07-10T01:24:44.270071-05:00","Action":"output","Package":"go-test-report","Test":"TestFunc3","Output":"=== RUN TestFunc3\n"}
{"Time":"2020-07-10T01:24:44.270295-05:00","Action":"output","Package":"go-test-report","Test":"TestFunc3","Output":"--- FAIL: TestFunc3 (0.00s)\n"}
Expand All @@ -167,9 +168,28 @@ func TestGenerateReport(t *testing.T) {
OutputFilename: "test-output-report.html",
}
cmd := &cobra.Command{}
b := &bytes.Buffer{}
bb := bufio.NewWriter(b)
err := generateReport(stdinScanner, flags, tmplData, bb, cmd)
writer := bufio.NewWriter(&bytes.Buffer{})
getPackageDetails := func(allPackageNames map[string]*types.Nil) (TestFileDetailsByPackage, error) {
m := TestFileDetailsByPackage{}
m["go-test-report"] = map[string]*TestFileDetail{}
m["go-test-report"]["TestFunc1"] = &TestFileDetail{
FileName: "sample1.go",
TestFunctionFilePos: TestFunctionFilePos{
Line: 101,
Col: 1,
},
}
m["package2"] = map[string]*TestFileDetail{}
m["package2"]["TestFunc2"] = &TestFileDetail{
FileName: "sample2.go",
TestFunctionFilePos: TestFunctionFilePos{
Line: 784,
Col: 17,
},
}
return m, nil
}
err := generateReport(getPackageDetails, stdinScanner, flags, tmplData, writer, cmd)
assertions.Nil(err)
assertions.Equal(2, tmplData.NumOfTestPassed)
assertions.Equal(1, tmplData.NumOfTestFailed)
Expand All @@ -178,21 +198,66 @@ func TestGenerateReport(t *testing.T) {
assertions.Equal("TestFunc1", tmplData.TestResults[0].TestResults[0].TestName)
assertions.Equal("go-test-report", tmplData.TestResults[0].TestResults[0].Package)
assertions.Equal(true, tmplData.TestResults[0].TestResults[0].Passed)
assertions.Empty(tmplData.TestResults[0].TestResults[0].TestFileName)
assertions.Equal(0, tmplData.TestResults[0].TestResults[0].TestFunctionDetail.Col)
assertions.Equal(0, tmplData.TestResults[0].TestResults[0].TestFunctionDetail.Line)
assertions.Equal("sample1.go", tmplData.TestResults[0].TestResults[0].TestFileName)
assertions.Equal(1, tmplData.TestResults[0].TestResults[0].TestFunctionDetail.Col)
assertions.Equal(101, tmplData.TestResults[0].TestResults[0].TestFunctionDetail.Line)

assertions.Equal("TestFunc2", tmplData.TestResults[0].TestResults[1].TestName)
assertions.Equal("go-test-report", tmplData.TestResults[0].TestResults[1].Package)
assertions.Equal("package2", tmplData.TestResults[0].TestResults[1].Package)
assertions.Equal(true, tmplData.TestResults[0].TestResults[1].Passed)
assertions.Empty(tmplData.TestResults[0].TestResults[1].TestFileName)
assertions.Equal(0, tmplData.TestResults[0].TestResults[1].TestFunctionDetail.Col)
assertions.Equal(0, tmplData.TestResults[0].TestResults[1].TestFunctionDetail.Line)
assertions.Equal("sample2.go", tmplData.TestResults[0].TestResults[1].TestFileName)
assertions.Equal(17, tmplData.TestResults[0].TestResults[1].TestFunctionDetail.Col)
assertions.Equal(784, tmplData.TestResults[0].TestResults[1].TestFunctionDetail.Line)

assertions.Equal("TestFunc3", tmplData.TestResults[1].TestResults[0].TestName)
assertions.Equal("go-test-report", tmplData.TestResults[1].TestResults[0].Package)
assertions.Equal(false, tmplData.TestResults[1].TestResults[0].Passed)
assertions.Empty(tmplData.TestResults[1].TestResults[0].TestFileName)
assertions.Equal(0, tmplData.TestResults[1].TestResults[0].TestFunctionDetail.Col)
assertions.Equal(0, tmplData.TestResults[1].TestResults[0].TestFunctionDetail.Line)
}

func TestParseSizeFlagIfValueIsNotInteger(t *testing.T) {
assertions := assert.New(t)
tmplData := &TemplateData{}
flags := &cmdFlags{
sizeFlag: "x",
}
err := parseSizeFlag(tmplData, flags)
assertions.Error(err)
assertions.Equal(err.Error(), `strconv.Atoi: parsing "": invalid syntax`)

}

func TestParseSizeFlagIfWidthValueIsNotInteger(t *testing.T) {
assertions := assert.New(t)
tmplData := &TemplateData{}
flags := &cmdFlags{
sizeFlag: "Bx27",
}
err := parseSizeFlag(tmplData, flags)
assertions.Error(err)
assertions.Equal(err.Error(), `strconv.Atoi: parsing "b": invalid syntax`)
}

func TestParseSizeFlagIfHeightValueIsNotInteger(t *testing.T) {
assertions := assert.New(t)
tmplData := &TemplateData{}
flags := &cmdFlags{
sizeFlag: "10xA",
}
err := parseSizeFlag(tmplData, flags)
assertions.Error(err)
assertions.Equal(err.Error(), `strconv.Atoi: parsing "a": invalid syntax`)
}

func TestParseSizeFlagIfMalformedSize(t *testing.T) {
assertions := assert.New(t)
tmplData := &TemplateData{}
flags := &cmdFlags{
sizeFlag: "10xx19",
}
err := parseSizeFlag(tmplData, flags)
assertions.Error(err)
assertions.Equal(err.Error(), `malformed size value; only one x is allowed if specifying with and height`)
}

0 comments on commit 00c3dc8

Please sign in to comment.