Add "go-version" flag

Makes it so that the value of the "go.version" property in
the output XML can be customized by the caller using the
"go-version" flag. If the flag is unspecified, falls back to
the previous behavior of using runtime.Version() as the value.

Fixes #48
This commit is contained in:
Nick Miyake
2017-03-26 14:20:21 -07:00
parent 6aeed679b6
commit 22792ea55c
3 changed files with 26 additions and 7 deletions

View File

@ -556,15 +556,23 @@ func TestParser(t *testing.T) {
}
func TestJUnitFormatter(t *testing.T) {
testJUnitFormatter(t, "")
}
func TestVersionFlag(t *testing.T) {
testJUnitFormatter(t, "custom-version")
}
func testJUnitFormatter(t *testing.T, goVersion string) {
for _, testCase := range testCases {
report, err := loadTestReport(testCase.reportName)
report, err := loadTestReport(testCase.reportName, goVersion)
if err != nil {
t.Fatal(err)
}
var junitReport bytes.Buffer
if err = JUnitReportXML(testCase.report, testCase.noXMLHeader, &junitReport); err != nil {
if err = JUnitReportXML(testCase.report, testCase.noXMLHeader, goVersion, &junitReport); err != nil {
t.Fatal(err)
}
@ -574,14 +582,19 @@ func TestJUnitFormatter(t *testing.T) {
}
}
func loadTestReport(name string) (string, error) {
func loadTestReport(name, goVersion string) (string, error) {
contents, err := ioutil.ReadFile("tests/" + name)
if err != nil {
return "", err
}
if goVersion == "" {
// if goVersion is not specified, default to runtime version
goVersion = runtime.Version()
}
// replace value="1.0" With actual version
report := strings.Replace(string(contents), `value="1.0"`, fmt.Sprintf(`value="%s"`, runtime.Version()), -1)
report := strings.Replace(string(contents), `value="1.0"`, fmt.Sprintf(`value="%s"`, goVersion), -1)
return report, nil
}