coveragecalculator

package
v0.0.0-...-62801f1 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

README

Coverage Calculator

coveragecalculator package contains types and helper methods pertaining to coverage calculation.

TypeCoverage is a type to represent coverage data for a particular API object type. This is the wire contract between the webhook server running inside the K8s cluster and any client using the API-Coverage tool. All API calls into the webhook-server would return response containing this object to represent coverage data.

IgnoredFields type provides ability for individual repos to specify fields that they would like the API Coverage tool to ignore for coverage calculation. Individual repos are expected to provide a .yaml file providing fields that they would like to ignore and use helper method ReadFromFile(filePath) to read and intialize this type. FieldIgnored() can then be called by providing packageName, typeName and FieldName to check if the field needs to be ignored.

CalculateCoverage method provides a capability to calculate coverage values. This method takes an array of TypeCoverage and iterates over them to aggreage coverage values. The aggregate result is encapsulated inside CoverageValues and returned.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CoveragePercentages

type CoveragePercentages struct {

	// ResourceCoverages maps percentage coverage per resource.
	ResourceCoverages map[string]float64
}

CoveragePercentages encapsulate percentage coverage for resources.

func (*CoveragePercentages) GetAndRemoveResourceValue

func (c *CoveragePercentages) GetAndRemoveResourceValue(resource string) float64

GetAndRemoveResourceValue utility method to implement "get and delete" semantics. This makes templating operations easy.

func (*CoveragePercentages) IsFailedBuild

func (c *CoveragePercentages) IsFailedBuild() bool

IsFailedBuild utility method to indicate if CoveragePercentages indicate values of a failed build.

type CoverageValues

type CoverageValues struct {
	TotalFields   int
	CoveredFields int
	IgnoredFields int

	PercentCoverage float64
}

CoverageValues encapsulates all the coverage related values.

func CalculateTypeCoverage

func CalculateTypeCoverage(typeCoverage []TypeCoverage) *CoverageValues

CalculateTypeCoverage calculates aggregate coverage values based on provided []TypeCoverage

func (*CoverageValues) CalculatePercentageValue

func (c *CoverageValues) CalculatePercentageValue()

CalculatePercentageValue calculates percentage value based on other fields.

type FieldCoverage

type FieldCoverage struct {
	Field    string      `json:"Field"`
	Values   sets.String `json:"Values"`
	Coverage bool        `json:"Covered"`
	Ignored  bool        `json:"Ignored"`
}

FieldCoverage represents coverage data for a field.

func (*FieldCoverage) GetValues

func (f *FieldCoverage) GetValues() []string

GetValues returns Values as slice

func (*FieldCoverage) GetValuesForDisplay

func (f *FieldCoverage) GetValuesForDisplay() string

GetValuesForDisplay returns value strings as comma separated string.

func (*FieldCoverage) Merge

func (f *FieldCoverage) Merge(coverage bool, values sets.String)

Merge operation merges the field coverage data when multiple nodes represent the same type. (e.g. ConnectedNodes traversal)

type IgnoredFields

type IgnoredFields struct {
	// contains filtered or unexported fields
}

IgnoredFields encapsulates fields to be ignored in a package for API coverage calculation.

func (*IgnoredFields) FieldIgnored

func (ig *IgnoredFields) FieldIgnored(packageName string, typeName string, fieldName string) bool

FieldIgnored method given a package, type and field returns true if the field is marked ignored.

func (*IgnoredFields) ReadFromFile

func (ig *IgnoredFields) ReadFromFile(filePath string) error

ReadFromFile is a utility method that can be used by repos to read .yaml input file into IgnoredFields type.

type TypeCoverage

type TypeCoverage struct {
	Package string                    `json:"Package"`
	Type    string                    `json:"Type"`
	Fields  map[string]*FieldCoverage `json:"Fields"`
}

TypeCoverage encapsulates type information and field coverage.

Jump to

Keyboard shortcuts

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