Ejemplo n.º 1
0
func getTrimmedStepName(stepRunResult models.StepRunResultsModel) string {
	iconBoxWidth := len("    ")
	timeBoxWidth := len(" time (s) ")
	titleBoxWidth := stepRunSummaryBoxWidthInChars - 4 - iconBoxWidth - timeBoxWidth - 1

	stepInfo := stepRunResult.StepInfo

	title := stepInfo.Title

	titleBox := ""
	switch stepRunResult.Status {
	case models.StepRunStatusCodeSuccess, models.StepRunStatusCodeSkipped, models.StepRunStatusCodeSkippedWithRunIf:
		titleBox = fmt.Sprintf("%s", title)
		if len(titleBox) > titleBoxWidth {
			dif := len(titleBox) - titleBoxWidth
			title = stringutil.MaxFirstCharsWithDots(title, len(title)-dif)
			titleBox = fmt.Sprintf("%s", title)
		}
		break
	case models.StepRunStatusCodeFailed, models.StepRunStatusCodeFailedSkippable:
		titleBox = fmt.Sprintf("%s (exit code: %d)", title, stepRunResult.ExitCode)
		if len(titleBox) > titleBoxWidth {
			dif := len(titleBox) - titleBoxWidth
			title = stringutil.MaxFirstCharsWithDots(title, len(title)-dif)
			titleBox = fmt.Sprintf("%s (exit code: %d)", title, stepRunResult.ExitCode)
		}
		break
	default:
		log.Error("Unkown result code")
		return ""
	}
	return titleBox
}
Ejemplo n.º 2
0
func getRunningStepHeaderMainSection(stepInfo stepmanModels.StepInfoModel, idx int) string {
	title := stepInfo.Title

	content := fmt.Sprintf("| (%d) %s |", idx, title)
	charDiff := len(content) - stepRunSummaryBoxWidthInChars

	if charDiff < 0 {
		// shorter than desired - fill with space
		content = fmt.Sprintf("| (%d) %s%s |", idx, title, strings.Repeat(" ", -charDiff))
	} else if charDiff > 0 {
		// longer than desired - trim title
		trimmedTitleWidth := len(title) - charDiff
		if trimmedTitleWidth < 4 {
			log.Errorf("Step title too long, can't present title at all! : %s", title)
		} else {
			content = fmt.Sprintf("| (%d) %s |", idx, stringutil.MaxFirstCharsWithDots(title, trimmedTitleWidth))
		}
	}
	return content
}
Ejemplo n.º 3
0
func getRunningStepHeaderSubSection(stepInfo stepmanModels.StepInfoModel) string {
	id := stepInfo.ID
	version := stepInfo.Version
	collection := stepInfo.StepLib
	logTime := time.Now().Format(time.RFC3339)

	idRow := fmt.Sprintf("| id: %s |", id)
	charDiff := len(idRow) - stepRunSummaryBoxWidthInChars
	if charDiff < 0 {
		// shorter than desired - fill with space
		idRow = fmt.Sprintf("| id: %s%s |", id, strings.Repeat(" ", -charDiff))
	} else if charDiff > 0 {
		// longer than desired - trim title
		trimmedWidth := len(id) - charDiff
		if trimmedWidth < 4 {
			log.Errorf("Step id too long, can't present id at all! : %s", id)
		} else {
			idRow = fmt.Sprintf("| id: %s |", stringutil.MaxFirstCharsWithDots(id, trimmedWidth))
		}
	}

	versionRow := fmt.Sprintf("| version: %s |", version)
	charDiff = len(versionRow) - stepRunSummaryBoxWidthInChars
	if charDiff < 0 {
		// shorter than desired - fill with space
		versionRow = fmt.Sprintf("| version: %s%s |", version, strings.Repeat(" ", -charDiff))
	} else if charDiff > 0 {
		// longer than desired - trim title
		trimmedWidth := len(version) - charDiff
		if trimmedWidth < 4 {
			log.Errorf("Step version too long, can't present version at all! : %s", version)
		} else {
			versionRow = fmt.Sprintf("| id: %s |", stringutil.MaxFirstCharsWithDots(version, trimmedWidth))
		}
	}

	collectionRow := fmt.Sprintf("| collection: %s |", collection)
	charDiff = len(collectionRow) - stepRunSummaryBoxWidthInChars
	if charDiff < 0 {
		// shorter than desired - fill with space
		collectionRow = fmt.Sprintf("| collection: %s%s |", collection, strings.Repeat(" ", -charDiff))
	} else if charDiff > 0 {
		// longer than desired - trim title
		trimmedWidth := len(collection) - charDiff
		if trimmedWidth < 4 {
			log.Errorf("Step collection too long, can't present collection at all! : %s", version)
		} else {
			collectionRow = fmt.Sprintf("| collection: %s |", stringutil.MaxLastCharsWithDots(collection, trimmedWidth))
		}
	}

	timeRow := fmt.Sprintf("| time: %s |", logTime)
	charDiff = len(timeRow) - stepRunSummaryBoxWidthInChars
	if charDiff < 0 {
		// shorter than desired - fill with space
		timeRow = fmt.Sprintf("| time: %s%s |", logTime, strings.Repeat(" ", -charDiff))
	} else if charDiff > 0 {
		// longer than desired - trim title
		trimmedWidth := len(logTime) - charDiff
		if trimmedWidth < 4 {
			log.Errorf("Time too long, can't present time at all! : %s", version)
		} else {
			timeRow = fmt.Sprintf("| time: %s |", stringutil.MaxFirstCharsWithDots(logTime, trimmedWidth))
		}
	}

	return fmt.Sprintf("%s\n%s\n%s\n%s", idRow, versionRow, collectionRow, timeRow)
}