cover

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2020 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//CoverInitSystemAPI prepare a new round of testing
	CoverInitSystemAPI = "/v1/cover/init"
	//CoverProfileAPI is provided by the covered service to get profiles
	CoverProfileAPI = "/v1/cover/profile"
	//CoverProfileClearAPI is provided by the covered service to clear profiles
	CoverProfileClearAPI = "/v1/cover/clear"
	//CoverServicesListAPI list all the registered services
	CoverServicesListAPI = "/v1/cover/list"
	//CoverRegisterServiceAPI register a service into service center
	CoverRegisterServiceAPI = "/v1/cover/register"
)
View Source
const LogFile = "goc.log"

LogFile a file to save log.

View Source
const PersistenceFile = "_svrs_address.txt"

PersistenceFile is the file to save services address information

Variables

View Source
var (
	ErrCoverPkgFailed  = errors.New("fail to inject code to project")
	ErrCoverListFailed = errors.New("fail to list package dependencies")
)

Functions

func Delta

func Delta(new Coverage, base Coverage) float32

calculate two coverage delta

func Execute

func Execute(args, newGopath, target, mode, center string) error

Execute execute go tool cover for all the .go files in the target folder

func GocServer

func GocServer(w io.Writer) *gin.Engine

GocServer init goc server engine

func InjectCacheCounters

func InjectCacheCounters(covers map[string][]*PackageCover, cache map[string]*PackageCover) []error

func InjectCountersHandlers

func InjectCountersHandlers(tc TestCover, dest string) error

InjectCountersHandlers generate a file _cover_http_apis.go besides the main.go file

func ListPackages

func ListPackages(dir string, args string, newgopath string) (map[string]*Package, error)

ListPackages list all packages under specific via go list command The argument newgopath is if you need to go list in a different GOPATH

func PercentStr

func PercentStr(f float32) string

PercentStr converts a fraction number to percentage string representation

func Run

func Run(port string)

Run starts coverage host center

func TotalDelta

func TotalDelta(new CoverageList, base CoverageList) float32

calculate two coverage delta

Types

type Action

type Action interface {
	Profile() ([]byte, error)
	Clear() ([]byte, error)
	InitSystem() ([]byte, error)
	ListServices() ([]byte, error)
	RegisterService(svr Service) ([]byte, error)
}

Action provides methods to contact with the covered service under test

func NewWorker

func NewWorker(host string) Action

NewWorker creates a worker to contact with service

type Coverage

type Coverage struct {
	FileName      string
	NCoveredStmts int
	NAllStmts     int
	LineCovLink   string
}

Coverage stores test coverage summary data for one file

func (*Coverage) Name

func (c *Coverage) Name() string

Name returns the file name

func (*Coverage) Percentage

func (c *Coverage) Percentage() string

Percentage returns the percentage of statements covered

func (*Coverage) Ratio

func (c *Coverage) Ratio() (ratio float32, err error)

type CoverageList

type CoverageList []Coverage

CoverageList is a collection and summary over multiple file Coverage objects

func CovList

func CovList(f io.Reader) (g CoverageList, err error)

convert profile to CoverageList struct

func NewCoverageList

func NewCoverageList() CoverageList

NewCoverageList return empty CoverageList

func ReadFileToCoverList

func ReadFileToCoverList(path string) (g CoverageList, err error)

covert profile file to CoverageList struct

func (CoverageList) Map

func (g CoverageList) Map() map[string]Coverage

Map returns maps the file name to its coverage for faster retrieval & membership check

func (CoverageList) Sort

func (g CoverageList) Sort()

sort CoverageList with filenames

func (CoverageList) TotalPercentage

func (g CoverageList) TotalPercentage() string

func (CoverageList) TotalRatio

func (g CoverageList) TotalRatio() (ratio float32, err error)

type DeltaCov

type DeltaCov struct {
	FileName    string
	BasePer     string
	NewPer      string
	DeltaPer    string
	LineCovLink string
}
func (c *DeltaCov) GetLineCovLink() string

func (*DeltaCov) Name

func (c *DeltaCov) Name() string

Name returns the file name

func (c *DeltaCov) SetLineCovLink(link string)

type DeltaCovList

type DeltaCovList []DeltaCov

func GetChFileDeltaCov

func GetChFileDeltaCov(newList CoverageList, baseList CoverageList, changedFiles []string) (list DeltaCovList)

get two profile diff cov of changed files

func GetDeltaCov

func GetDeltaCov(newList CoverageList, baseList CoverageList) (delta DeltaCovList)

get two profile diff cov

func GetFullDeltaCov

func GetFullDeltaCov(newList CoverageList, baseList CoverageList) (delta DeltaCovList)

get full delta coverage between new and base profile

func (DeltaCovList) Map

func (d DeltaCovList) Map() map[string]DeltaCov

Map returns maps the file name to its DeltaCov for faster retrieval & membership check

func (DeltaCovList) Sort

func (d DeltaCovList) Sort()

sort DeltaCovList with filenames

type FileVar

type FileVar struct {
	File string
	Var  string
}

FileVar holds the name of the generated coverage variables targeting the named file.

type ModuleError

type ModuleError struct {
	Err string // error text
}

type ModulePublic

type ModulePublic struct {
	Path      string        `json:",omitempty"` // module path
	Version   string        `json:",omitempty"` // module version
	Versions  []string      `json:",omitempty"` // available module versions
	Replace   *ModulePublic `json:",omitempty"` // replaced by this module
	Time      *time.Time    `json:",omitempty"` // time version was created
	Update    *ModulePublic `json:",omitempty"` // available update (with -u)
	Main      bool          `json:",omitempty"` // is this the main module?
	Indirect  bool          `json:",omitempty"` // module is only indirectly needed by main module
	Dir       string        `json:",omitempty"` // directory holding local copy of files, if any
	GoMod     string        `json:",omitempty"` // path to go.mod file describing module, if any
	GoVersion string        `json:",omitempty"` // go version used in module
	Error     *ModuleError  `json:",omitempty"` // error loading module
}

type Package

type Package struct {
	Dir        string `json:"Dir"`        // directory containing package sources
	ImportPath string `json:"ImportPath"` // import path of package in dir
	Name       string `json:"Name"`       // package name
	Target     string `json:",omitempty"` // installed target for this package (may be executable)
	Root       string `json:",omitempty"` // Go root, Go path dir, or module root dir containing this package

	Module   *ModulePublic `json:",omitempty"`         // info about package's module, if any
	Goroot   bool          `json:"Goroot,omitempty"`   // is this package in the Go root?
	Standard bool          `json:"Standard,omitempty"` // is this package part of the standard Go library?
	DepOnly  bool          `json:"DepOnly,omitempty"`  // package is only a dependency, not explicitly listed

	// Source files
	GoFiles  []string `json:"GoFiles,omitempty"`  // .go source files (excluding CgoFiles, TestGoFiles, XTestGoFiles)
	CgoFiles []string `json:"CgoFiles,omitempty"` // .go source files that import "C"

	// Dependency information
	Deps      []string          `json:"Deps,omitempty"` // all (recursively) imported dependencies
	Imports   []string          `json:",omitempty"`     // import paths used by this package
	ImportMap map[string]string `json:",omitempty"`     // map from source import to ImportPath (identity entries omitted)

	// Error information
	Incomplete bool            `json:"Incomplete,omitempty"` // this package or a dependency has an error
	Error      *PackageError   `json:"Error,omitempty"`      // error loading package
	DepsErrors []*PackageError `json:"DepsErrors,omitempty"` // errors loading dependencies
}

Package map a package output by go list this is subset of package struct in: https://github.com/golang/go/blob/master/src/cmd/go/internal/load/pkg.go#L58

type PackageCover

type PackageCover struct {
	Package *Package
	Vars    map[string]*FileVar
}

PackageCover holds all the generate coverage variables of a package

func AddCacheCover

func AddCacheCover(pkg *Package, in *PackageCover) *PackageCover

func AddCounters

func AddCounters(pkg *Package, mode, newgopath string) (*PackageCover, error)

AddCounters add counters for all go files under the package

func CacheInternalCover

func CacheInternalCover(in *PackageCover) *PackageCover

type PackageError

type PackageError struct {
	ImportStack []string // shortest path from package named on command line to this one
	Pos         string   // position of error (if present, file:line:col)
	Err         string   // the error itself
}

PackageError is the error info for a package when list failed

type Service

type Service struct {
	Name    string `form:"name" json:"name" binding:"required"`
	Address string `form:"address" json:"address" binding:"required"`
}

Service is a entry under being tested

type Store

type Store interface {
	// Add adds the given service to store
	Add(s Service) error

	// Get returns the registered service information with the given service's name
	Get(name string) []string

	// Get returns all the registered service information as a map
	GetAll() map[string][]string

	// Init cleanup all the registered service information
	Init() error

	// Set stores the services information into internal state
	Set(services map[string][]string)
}

Store persistents the registered service information

var DefaultStore Store

DefaultStore implements the IPersistence interface

func NewFileStore

func NewFileStore() Store

NewFileStore creates a store using local file

func NewMemoryStore

func NewMemoryStore() Store

NewMemoryStore creates a memory store

type TestCover

type TestCover struct {
	Mode         string
	Center       string // cover profile host center
	MainPkgCover *PackageCover
	DepsCover    []*PackageCover
	CacheCover   map[string]*PackageCover
}

TestCover is a collection of all counters

Jump to

Keyboard shortcuts

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