diff --git a/pkg/allure/result.go b/pkg/allure/result.go index 19c42fc..a5f85ea 100644 --- a/pkg/allure/result.go +++ b/pkg/allure/result.go @@ -223,11 +223,12 @@ func (result *Result) SkipOnPrint() { } // Print If `Result.ToPrint` = `true` - the method terminates without creating any files. Otherwise: -// - Calls `Result.PrintAttachments()`. -// - Saves the file `uuid4-Result.json`. -// - Calls `Result.Container.Print()` -// - Returns error (if any) +// - Calls `Result.PrintAttachments()`. +// - Saves the file `uuid4-Result.json`. +// - Calls `Result.Container.Print()` +// - Returns error (if any) func (result *Result) Print() error { + overWriteStartAndEndTime(result) if !result.ToPrint { return nil } @@ -300,3 +301,28 @@ func getMD5Hash(text string) string { hash := md5.Sum([]byte(text)) return hex.EncodeToString(hash[:]) } + +// getTimeSumOfSteps gets first step start time and last step end time +func getTimeSumOfSteps(result *Result) (startTimeInt int64, endTimeInt int64) { + startTime := result.Steps[0].Start + endTime := result.Steps[0].Start + + for _, step := range result.Steps { + if step.Stop > endTime { + endTime = step.Stop + } + if step.Start < startTime { + startTime = step.Start + } + } + + return startTime, endTime +} + +func overWriteStartAndEndTime(result *Result) { + if result.Status == Skipped { + result.Stop = result.Start + } else { + result.Start, result.Stop = getTimeSumOfSteps(result) + } +} diff --git a/pkg/allure/result_test.go b/pkg/allure/result_test.go index 4784d95..f873730 100644 --- a/pkg/allure/result_test.go +++ b/pkg/allure/result_test.go @@ -280,6 +280,7 @@ func TestResult_WithLabels(t *testing.T) { func TestResult_PrintAttachments(t *testing.T) { attachmentText := `THIS IS A TEXT ATTACHMENT` result := new(Result) + result.Steps = append(result.Steps, NewStep(testName, "complete", 1, 1, []*Parameter{})) result.Attachments = append(result.Attachments, NewAttachment("Text Attachment if TestAttachment", Text, []byte(attachmentText))) result.PrintAttachments() defer os.RemoveAll(allureDir) @@ -298,6 +299,7 @@ func TestResult_PrintAttachments(t *testing.T) { func TestResult_Print_toPrintFalse(t *testing.T) { result := new(Result) + result.Steps = append(result.Steps, NewStep(testName, "complete", 1, 1, []*Parameter{})) err := result.Print() require.NoError(t, err) @@ -306,6 +308,7 @@ func TestResult_Print_toPrintFalse(t *testing.T) { func TestResult_Print(t *testing.T) { result := NewResult(testName, testFullName) + result.Steps = append(result.Steps, NewStep(testName, "complete", 1, 1, []*Parameter{})) err := result.Print() require.NoError(t, err) @@ -340,6 +343,7 @@ func TestResult_Print(t *testing.T) { func TestResult_Print_withAttachment(t *testing.T) { attachmentText := `THIS IS A TEXT ATTACHMENT` result := NewResult(testName, testFullName) + result.Steps = append(result.Steps, NewStep(testName, "complete", 1, 1, []*Parameter{})) result.Attachments = append(result.Attachments, NewAttachment("Text Attachment if TestAttachment", Text, []byte(attachmentText))) result.PrintAttachments() err := result.Print() @@ -396,10 +400,11 @@ func TestResult_Print_withAttachment(t *testing.T) { func TestResult_Done(t *testing.T) { attachmentText := `THIS IS A TEXT ATTACHMENT` + now := GetNow() result := NewResult(testName, testFullName) result.Attachments = append(result.Attachments, NewAttachment("Text Attachment if TestAttachment", Text, []byte(attachmentText))) + result.Steps = append(result.Steps, NewStep(testName, "complete", now, now, []*Parameter{})) result.PrintAttachments() - now := GetNow() result.Done() defer os.RemoveAll(allureDir)