Beispiel #1
0
func (fd FailureDetails) toBasicTestLog(fdType string) *model.TestLog {
	log := model.TestLog{
		Lines: []string{fmt.Sprintf("%v: %v (%v)", fdType, fd.Message, fd.Type)},
	}
	logLines := strings.Split(strings.TrimSpace(fd.Content), "\n")
	log.Lines = append(log.Lines, logLines...)
	return &log
}
Beispiel #2
0
// ToModelTestResultAndLog converts an xunit test case into an
// mci task.TestResult and model.TestLog. Logs are only
// generated if the test case did not succeed (this is part of
// the xunit xml file design)
func (tc TestCase) ToModelTestResultAndLog(t *task.Task) (task.TestResult, *model.TestLog) {

	res := task.TestResult{}
	var log *model.TestLog

	if tc.ClassName != "" {
		res.TestFile = fmt.Sprintf("%v.%v", tc.ClassName, tc.Name)
	} else {
		res.TestFile = tc.Name
	}
	// replace spaces, dashes, etc. with underscores
	res.TestFile = util.CleanForPath(res.TestFile)

	res.StartTime = float64(time.Now().Unix())
	res.EndTime = float64(res.StartTime + tc.Time)

	// the presence of the Failure, Error, or Skipped fields
	// is used to indicate an unsuccessful test case. Logs
	// can only be generated in failure cases, because xunit
	// results only include messages if they did *not* succeed.
	switch {
	case tc.Failure != nil:
		res.Status = evergreen.TestFailedStatus
		log = tc.Failure.toBasicTestLog("FAILURE")
	case tc.Error != nil:
		res.Status = evergreen.TestFailedStatus
		log = tc.Error.toBasicTestLog("ERROR")
	case tc.Skipped != nil:
		res.Status = evergreen.TestSkippedStatus
		log = tc.Skipped.toBasicTestLog("SKIPPED")
	default:
		res.Status = evergreen.TestSucceededStatus
	}

	if log != nil {
		log.Name = res.TestFile
		log.Task = t.Id
		log.TaskExecution = t.Execution

		// update the URL of the result to the expected log URL
		res.URL = log.URL()
	}

	return res, log
}