csv

package
Version: v0.0.0-...-4aad30d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 3, 2021 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package csv provides methods for easily validating the rows and columns of a CSV file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Column

func Column(field string, validators ...validator) column

Column returns the field name of the column and a validator that will use a list of validators to validate all values in this CSV column. The return value is of the column type.

func ColumnWithDefault

func ColumnWithDefault(field, defaultValue string, validators ...validator) column

ColumnWithDefault returns the field name of the column and a validator that will use a list of validators to validate all values in this CSV column. If the field value is equal to |defaultValue|, the validators are not run.

func EqualToCrosConfigProp

func EqualToCrosConfigProp(ctx context.Context, path, prop string) validator

EqualToCrosConfigProp returns a function that uses crosconfig and its two arguments, |prop| and |path| to obtain a value that is compared with |actual|.

func EqualToFileContent

func EqualToFileContent(path string) validator

EqualToFileContent returns a function that checks whether |path| exists. If it does, it compares the value at that location wih |actual|. If it does not, an error is returned.

func EqualToFileIfCrosConfigProp

func EqualToFileIfCrosConfigProp(ctx context.Context, path, prop, filePath string) validator

EqualToFileIfCrosConfigProp returns a function that checks whether |filePath| should exist by using crosconfig and its two arguments, |prop| and |path|. If the crosconfig property does not exist, an error is returned. If the file exists, it attempts to read the value from the file. If it cannot, an error is reported. If it can, it compares the read value with |actual|.

func MatchRegex

func MatchRegex(regex *regexp.Regexp) validator

MatchRegex returns a function that checks whether |actual| matches the regex pattern specified by |regex|.

func MatchValue

func MatchValue(value string) validator

MatchValue returns a validator that checks whether |value| is equal to |actual|.

func Rows

func Rows(expectedRows int) int

Rows simply returns the number of rows (including header) that the csv must contain.

func UInt64

func UInt64() validator

UInt64 returns a validator that checks whether |actual| can be parsed into a uint64.

func ValidateCSV

func ValidateCSV(csv [][]string, rows int, columns ...column) error

ValidateCSV is responsible for validating headers and all values of the CSV output. An error is returned if the headers are invalid or if any of the CSV values are incorrect as determined by the validators provided to verify a particular CSV value.

Types

This section is empty.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto