From 061ee62ada408ff437041a26b76f48be1fa4bbe8 Mon Sep 17 00:00:00 2001 From: Vistaar Juneja Date: Tue, 22 Dec 2020 01:52:03 +0530 Subject: [PATCH] Support for parsing time durations containing commas (#39) --- ingest.go | 4 ++++ ingest_test.go | 4 ++-- testdata/surefire.xml | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ingest.go b/ingest.go index ee12ea6..4472ebc 100644 --- a/ingest.go +++ b/ingest.go @@ -6,6 +6,7 @@ package junit import ( "strconv" + "strings" "time" ) @@ -103,6 +104,9 @@ func ingestError(root xmlNode) Error { } func duration(t string) time.Duration { + // Remove commas for larger durations + t = strings.ReplaceAll(t, ",", "") + // Check if there was a valid decimal value if s, err := strconv.ParseFloat(t, 64); err == nil { return time.Duration(s*1000000) * time.Microsecond diff --git a/ingest_test.go b/ingest_test.go index 5270d4d..457019b 100644 --- a/ingest_test.go +++ b/ingest_test.go @@ -113,7 +113,7 @@ func TestExamplesInTheWild(t *testing.T) { var testcase = Test{ Name: "testStdoutStderr", Classname: "com.example.FooTest", - Duration: 9 * time.Millisecond, + Duration: 1234560 * time.Millisecond, Status: StatusFailed, Error: Error{ Type: "java.lang.AssertionError", @@ -122,7 +122,7 @@ func TestExamplesInTheWild(t *testing.T) { Properties: map[string]string{ "classname": "com.example.FooTest", "name": "testStdoutStderr", - "time": "0.009", + "time": "1,234.56", }, SystemOut: "Hello, World\n", SystemErr: "I'm an error!\n", diff --git a/testdata/surefire.xml b/testdata/surefire.xml index c41dd45..13cf2f6 100644 --- a/testdata/surefire.xml +++ b/testdata/surefire.xml @@ -47,7 +47,7 @@ - + java.lang.AssertionError at com.example.FooTest.testStdoutStderr(FooTest.java:13)