Exemplo n.º 1
0
func FormatTable(table *gauge.Table) string {
	columnToWidthMap := make(map[int]int)
	for i, header := range table.Headers {
		//table.get(header) returns a list of cells in that particular column
		cells := table.Get(header)
		columnToWidthMap[i] = findLongestCellWidth(cells, len(header))
	}

	var tableStringBuffer bytes.Buffer
	tableStringBuffer.WriteString(fmt.Sprintf("%s|", getRepeatedChars(" ", tableLeftSpacing)))
	for i, header := range table.Headers {
		width := columnToWidthMap[i]
		tableStringBuffer.WriteString(fmt.Sprintf("%s|", addPaddingToCell(header, width)))
	}

	tableStringBuffer.WriteString("\n")
	tableStringBuffer.WriteString(fmt.Sprintf("%s|", getRepeatedChars(" ", tableLeftSpacing)))
	for i := range table.Headers {
		width := columnToWidthMap[i]
		cell := getRepeatedChars("-", width)
		tableStringBuffer.WriteString(fmt.Sprintf("%s|", addPaddingToCell(cell, width)))
	}

	tableStringBuffer.WriteString("\n")
	for _, row := range table.Rows() {
		tableStringBuffer.WriteString(fmt.Sprintf("%s|", getRepeatedChars(" ", tableLeftSpacing)))
		for i, cell := range row {
			width := columnToWidthMap[i]
			tableStringBuffer.WriteString(fmt.Sprintf("%s|", addPaddingToCell(cell, width)))
		}
		tableStringBuffer.WriteString("\n")
	}

	return string(tableStringBuffer.Bytes())
}
Exemplo n.º 2
0
func (e *specExecutor) executeTableDrivenSpec() {
	var dataTableScenarioExecutionResult [][]*result.ScenarioResult
	for e.currentTableRow = e.dataTableIndex.start; e.currentTableRow <= e.dataTableIndex.end; e.currentTableRow++ {
		var dataTable gauge.Table
		dataTable.AddHeaders(e.specification.DataTable.Table.Headers)
		dataTable.AddRowValues(e.specification.DataTable.Table.Rows()[e.currentTableRow])
		e.consoleReporter.DataTable(formatter.FormatTable(&dataTable))
		dataTableScenarioExecutionResult = append(dataTableScenarioExecutionResult, e.executeScenarios())
	}
	e.specResult.AddTableDrivenScenarioResult(dataTableScenarioExecutionResult)
}
Exemplo n.º 3
0
func convertCsvToTable(csvContents string) (*gauge.Table, error) {
	r := csv.NewReader(strings.NewReader(csvContents))
	r.Comment = '#'
	lines, err := r.ReadAll()
	if err != nil {
		return nil, err
	}
	table := new(gauge.Table)
	for i, line := range lines {
		if i == 0 {
			table.AddHeaders(line)
		} else {
			table.AddRowValues(line)
		}
	}
	return table, nil
}
Exemplo n.º 4
0
func (resolver *ParamResolver) createProtoStepTable(table *gauge.Table, dataTableLookup *gauge.ArgLookup) *gauge_messages.ProtoTable {
	protoTable := new(gauge_messages.ProtoTable)
	protoTable.Headers = &gauge_messages.ProtoTableRow{Cells: table.Headers}
	tableRows := make([]*gauge_messages.ProtoTableRow, 0)
	if len(table.Columns) == 0 {
		protoTable.Rows = tableRows
		return protoTable
	}
	for i := 0; i < len(table.Columns[0]); i++ {
		row := make([]string, 0)
		for _, header := range table.Headers {
			tableCell := table.Get(header)[i]
			value := tableCell.Value
			if tableCell.CellType == gauge.Dynamic {
				//if concept has a table with dynamic cell, fetch from datatable
				value = dataTableLookup.GetArg(tableCell.Value).Value
			}
			row = append(row, value)
		}
		tableRows = append(tableRows, &gauge_messages.ProtoTableRow{Cells: row})
	}
	protoTable.Rows = tableRows
	return protoTable
}