lib

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2016 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package lib contains all types and functions for db-checker

Index

Constants

This section is empty.

Variables

View Source
var Error = log.New(os.Stderr,
	"ERROR: ",
	log.Ldate|log.Ltime|log.Lshortfile)

Error is our error log

Functions

func DiffPretty

func DiffPretty(a, b string) string

DiffPretty returns string with pretty diff between two strings

func FindCheckInCheckResults

func FindCheckInCheckResults(needle Check, list []CheckResult) int

FindCheckInCheckResults returns position of CheckResult with given Check in []CheckResult

func ReportProblems

func ReportProblems(results []CheckResult) (int, string)

ReportProblems counts and pretty print problems

func ResultInSlice

func ResultInSlice(needle CheckResult, list []CheckResult) bool

ResultInSlice checks if we have CheckResult in slice of CheckResults

func ToTabString

func ToTabString(values []string) string

ToTabString returns keys and values in CSV format

func WriteReport

func WriteReport(results []CheckResult, f io.Writer) error

WriteReport writes report in CSV format to some io.Writer.

func WriteReportFile

func WriteReportFile(results []CheckResult, filePath string) error

WriteReportFile writes report to file at filePath.

Types

type Check

type Check struct {
	Description string `yaml:"description"`
	Query       string `yaml:"query"`
	Assert      string `yaml:"assert"`
}

Check is a description of check

func GetChecks

func GetChecks(searchDir string) ([]*Check, error)

GetChecks scans filesystem under searchDir and returns list of checks

func ReadCheck

func ReadCheck(f io.Reader) (*Check, error)

ReadCheck reads check from io.Reader

func ReadCheckFile

func ReadCheckFile(filePath string) (*Check, error)

ReadCheckFile reads check from file at filePath.

type CheckFunc added in v0.3.0

type CheckFunc func(*sql.DB, Check) (*CheckResult, error)

CheckFunc is a function we use for checks

type CheckResult

type CheckResult struct {
	Check    Check `json:"check"`
	Problems []Row `json:"problems"`
	Columns  Row   `json:"columns"`
}

CheckResult is a result of performed checks

func CheckQueryAbsent

func CheckQueryAbsent(db *sql.DB, check Check) (*CheckResult, error)

CheckQueryAbsent is a checker function that considers any output row a problem

func CheckQueryBool added in v0.3.0

func CheckQueryBool(db *sql.DB, check Check, waitFor bool) (*CheckResult, error)

CheckQueryBool is a checker function that checks boolean output

func CheckQueryPresent

func CheckQueryPresent(db *sql.DB, check Check) (*CheckResult, error)

CheckQueryPresent is a checker function that considers missing output a problem

func DiffResults

func DiffResults(first, second []CheckResult) []CheckResult

DiffResults returns diff (in form of slice of CheckResult) between two slices of CheckResult

func FailedCheck

func FailedCheck(c *Check, message string) *CheckResult

FailedCheck provides easy way to create failed CheckResult

func ReadReport

func ReadReport(f io.Reader) ([]CheckResult, error)

ReadReport reads previous report in CSV format from some io.Reader.

func ReadReportFile

func ReadReportFile(filePath string) ([]CheckResult, error)

ReadReportFile reads report from file at filePath.

func RunChecks

func RunChecks(dbType, dbConnString string, checks []*Check, concurrency int) ([]CheckResult, error)

RunChecks runs all check, uses dbConnString for db connection

func (CheckResult) HasProblems

func (c CheckResult) HasProblems() bool

HasProblems indicates that CheckResult has problems

func (CheckResult) String

func (c CheckResult) String() string

String represents CheckResult as string

type Row

type Row []string

Row is a row of values from DB query

func DiffRows

func DiffRows(first, second []Row) []Row

DiffRows calculates diff (in form of slice of Row) between two slices of Row

func NewRow

func NewRow(fields []interface{}) Row

NewRow is a row constructor

func (Row) String

func (r Row) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL