Skip to content

Commit

Permalink
internal/civisibility: addressing review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyredondo committed Oct 28, 2024
1 parent 12df8a8 commit 396f778
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func ensureAdditionalFeaturesInitialization(serviceName string) {

// GetSettings gets the settings from the backend settings endpoint
func GetSettings() *net.SettingsResponseData {
// call to ensure the additional features initialization is completed (service name can be null here)
// call to ensure the settings features initialization is completed (service name can be null here)
ensureSettingsInitialization("")
return &ciVisibilitySettings
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,16 @@ func InitializeCoverage(m *testing.M) {
}

// initializing runtime coverage
mode, tearDown, _ = testDep.InitRuntimeCoverage()
tMode, tDown, _ := testDep.InitRuntimeCoverage()
mode = tMode
tearDown = func(coverprofile string, gocoverdir string) (string, error) {
// redirecting stdout to a temp file to avoid printing coverage messages to stdout
stdout := os.Stdout
os.Stdout = tempFile
defer func() { os.Stdout = stdout }()
// writing the coverage counters to the file
return tDown(coverprofile, gocoverdir)
}

// if we cannot collect we bailout early
if !CanCollect() {
Expand Down Expand Up @@ -141,10 +150,8 @@ func GetCoverage() float64 {
return 0
}

restore := setStdOutToTemp()
coverageFile := filepath.Join(temporaryDir, "global_coverage.out")
_, err := tearDown(coverageFile, "")
restore()
if err != nil {
log.Debug("civisibility.coverage: error getting coverage file: %v", err)
}
Expand Down Expand Up @@ -186,10 +193,8 @@ func (t *testCoverage) CollectCoverageBeforeTestExecution() {
return
}

restore := setStdOutToTemp()
t.preCoverageFilename = filepath.Join(temporaryDir, fmt.Sprintf("%d-%d-%d-pre.out", t.moduleID, t.suiteID, t.testID))
_, err := tearDown(t.preCoverageFilename, "")
restore()
if err != nil {
log.Debug("civisibility.coverage: error getting coverage file: %v", err)
}
Expand All @@ -201,10 +206,8 @@ func (t *testCoverage) CollectCoverageAfterTestExecution() {
return
}

restore := setStdOutToTemp()
t.postCoverageFilename = filepath.Join(temporaryDir, fmt.Sprintf("%d-%d-%d-post.out", t.moduleID, t.suiteID, t.testID))
_, err := tearDown(t.postCoverageFilename, "")
restore()
if err != nil {
log.Debug("civisibility.coverage: error getting coverage file: %v", err)
}
Expand Down Expand Up @@ -252,13 +255,6 @@ func (t *testCoverage) processCoverageData() {
}
}

// setStdOutToTemp sets the stdout to a temp file.
func setStdOutToTemp() (restore func()) {
stdout := os.Stdout
os.Stdout = tempFile
return func() { os.Stdout = stdout }
}

// parseCoverProfile parses the coverage profile data and returns the coverage data for each file
func parseCoverProfile(filename string) (map[string][]coverageBlock, error) {
file, err := os.Open(filename)
Expand Down

0 comments on commit 396f778

Please sign in to comment.