Skip to content

Commit

Permalink
Merge branch 'main' into fix-duration
Browse files Browse the repository at this point in the history
  • Loading branch information
asherf authored Sep 11, 2024
2 parents cdd40cb + 3f53062 commit 96df85e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
test:
strategy:
matrix:
go-version: [ 1.19.x, 1.20.x, 1.21.x ]
go-version: [ 1.19.x, 1.20.x, 1.21.x, 1.22.x, 1.23.x ]
lint-and-coverage: [ false ]
include:
- go-version: 1.22.x
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ The test object in the report includes the following [CTRF properties](https://c

| Name | Type | Required | Details |
| ---------- | ------ | -------- | ----------------------------------------------------------------------------------- |
| `suite` | String | Required | The name of go package containing the test. |
| `name` | String | Required | The name of the test. |
| `status` | String | Required | The outcome of the test. One of: `passed`, `failed`, `skipped`, `pending`, `other`. |
| `duration` | Number | Required | The time taken for the test execution, in milliseconds. |
Expand Down
17 changes: 7 additions & 10 deletions reporter/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ func ParseTestResults(r io.Reader, verbose bool, env *ctrf.Environment) (*ctrf.R
report.Results.Summary.Stop = endTime
}
}

if event.Action == "pass" {
report.Results.Summary.Tests++
report.Results.Summary.Passed++
report.Results.Tests = append(report.Results.Tests, &ctrf.TestResult{
Suite: event.Package,
Name: event.Test,
Status: ctrf.TestPassed,
Duration: duration,
Expand All @@ -72,6 +72,7 @@ func ParseTestResults(r io.Reader, verbose bool, env *ctrf.Environment) (*ctrf.R
report.Results.Summary.Tests++
report.Results.Summary.Failed++
report.Results.Tests = append(report.Results.Tests, &ctrf.TestResult{
Suite: event.Package,
Name: event.Test,
Status: ctrf.TestFailed,
Duration: duration,
Expand All @@ -80,11 +81,13 @@ func ParseTestResults(r io.Reader, verbose bool, env *ctrf.Environment) (*ctrf.R
report.Results.Summary.Tests++
report.Results.Summary.Skipped++
report.Results.Tests = append(report.Results.Tests, &ctrf.TestResult{
Suite: event.Package,
Name: event.Test,
Status: ctrf.TestSkipped,
Duration: duration,
})
}

}
return report, nil
}
Expand All @@ -94,25 +97,19 @@ func WriteReportToFile(filename string, report *ctrf.Report) error {
if err != nil {
return err
}

fmt.Println("go-ctrf-json-reporter: successfully written ctrf json to", filename)
return nil
}

func secondsToMillis(seconds float64) int64 {
return int64(seconds * 1000)
}
func parseTimeString(timeString string) (int64, error) {
// Define the layout for parsing the time string
layout := time.RFC3339Nano

// Parse the time string
func parseTimeString(timeString string) (int64, error) {
layout := time.RFC3339Nano
t, err := time.Parse(layout, timeString)
if err != nil {
return 0, err
}

// Convert the time to Unix timestamp in milliseconds
timestamp := t.UnixNano() / int64(time.Millisecond)
return timestamp, nil
return t.UnixNano() / int64(time.Millisecond), nil
}

0 comments on commit 96df85e

Please sign in to comment.