Skip to content

Commit

Permalink
Improve initialization of TCR events
Browse files Browse the repository at this point in the history
  • Loading branch information
mengdaming committed Jun 7, 2022
1 parent a1827a0 commit 8ad769f
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 43 deletions.
21 changes: 13 additions & 8 deletions tcr-engine/engine/tcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,19 @@ func (tcr *TcrEngine) createTcrEvent(testResults toolchain.TestResults) (event e
report.PostWarning(err)
}
return events.NewTcrEvent(
computeSrcLinesChanged(tcr.language, changedFiles),
computeTestLinesChanged(tcr.language, changedFiles),
testResults.TotalRun,
testResults.Passed,
testResults.Failed,
testResults.Skipped,
testResults.WithErrors,
testResults.Duration)
events.NewChangedLines(
computeSrcLinesChanged(tcr.language, changedFiles),
computeTestLinesChanged(tcr.language, changedFiles),
),
events.NewTestStats(
testResults.TotalRun,
testResults.Passed,
testResults.Failed,
testResults.Skipped,
testResults.WithErrors,
testResults.Duration,
),
)
}

func (tcr *TcrEngine) build() error {
Expand Down
78 changes: 44 additions & 34 deletions tcr-engine/events/tcr_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,45 +24,55 @@ package events

import "time"

// ChangedLines is the structure containing info related to the lines changes in src and test
type ChangedLines struct {
Src int
Test int
}
type (
// ChangedLines is the structure containing info related to the lines changes in src and test
ChangedLines struct {
Src int
Test int
}

// TestStats is the structure containing info related to the tests execution
TestStats struct {
Run int
Passed int
Failed int
Skipped int
Error int
Duration time.Duration
}

// TcrEvent is the structure containing information related to a TCR event
TcrEvent struct {
Changes ChangedLines
Tests TestStats
}
)

// TestStats is the structure containing info related to the tests execution
type TestStats struct {
Run int
Passed int
Failed int
Skipped int
Error int
Duration time.Duration
// NewTcrEvent creates a new TcrEvent instance
func NewTcrEvent(changes ChangedLines, stats TestStats) TcrEvent {
return TcrEvent{
Changes: changes,
Tests: stats,
}
}

// TcrEvent is the structure containing information related to a TCR event
type TcrEvent struct {
Changes ChangedLines
Tests TestStats
// NewTestStats creates a new TestStats instance
func NewTestStats(run int, passed int, failed int, skipped int, errors int, duration time.Duration) TestStats {
return TestStats{
Run: run,
Passed: passed,
Failed: failed,
Skipped: skipped,
Error: errors,
Duration: duration,
}
}

// NewTcrEvent create a new TCREvent instance
func NewTcrEvent(
modifiedSrcLines, modifiedTestLines, totalTestsRun, testsPassed, testsFailed, testsSkipped, testsWithErrors int,
testsDuration time.Duration) TcrEvent {
return TcrEvent{
Changes: ChangedLines{
Src: modifiedSrcLines,
Test: modifiedTestLines,
},
Tests: TestStats{
Run: totalTestsRun,
Passed: testsPassed,
Failed: testsFailed,
Skipped: testsSkipped,
Error: testsWithErrors,
Duration: testsDuration,
},
// NewChangedLines creates a new ChangedLines instance
func NewChangedLines(srcLines, testLines int) ChangedLines {
return ChangedLines{
Src: srcLines,
Test: testLines,
}
}

Expand Down
5 changes: 4 additions & 1 deletion tcr-engine/events/tcr_event_test_data_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ import "time"

// ATcrEvent is a test data builder for a TCR event
func ATcrEvent(builders ...func(tcrEvent *TcrEvent)) *TcrEvent {
tcrEvent := NewTcrEvent(0, 0, 0, 0, 0, 0, 0, 0)
tcrEvent := NewTcrEvent(
NewChangedLines(0, 0),
NewTestStats(0, 0, 0, 0, 0, 0),
)

for _, build := range builders {
build(&tcrEvent)
Expand Down

0 comments on commit 8ad769f

Please sign in to comment.