Documentation ¶
Index ¶
- Constants
- Variables
- func Delta(new Coverage, base Coverage) float32
- func Execute(coverInfo *CoverInfo) error
- func InjectCacheCounters(covers map[string][]*PackageCover, cache map[string]*PackageCover) []error
- func InjectCountersHandlers(tc TestCover, dest string) error
- func ListPackages(dir string, args string, newgopath string) (map[string]*Package, error)
- func NewFileBasedServer(persistenceFile string) (*server, error)
- func NewMemoryBasedServer() *server
- func PercentStr(f float32) string
- func TotalDelta(new CoverageList, base CoverageList) float32
- type Action
- type CoverInfo
- type Coverage
- type CoverageList
- type DeltaCov
- type DeltaCovList
- type FileVar
- type ModuleError
- type ModulePublic
- type Package
- type PackageCover
- type PackageError
- type ProfileParam
- type ServiceUnderTest
- type Store
- type TestCover
Constants ¶
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" //CoverServicesRemoveAPI remove one services from the service center CoverServicesRemoveAPI = "/v1/cover/remove" )
const LogFile = "goc.log"
LogFile a file to save log.
Variables ¶
var ( // ErrCoverPkgFailed represents the error that fails to inject the package ErrCoverPkgFailed = errors.New("fail to inject code to project") // ErrCoverListFailed represents the error that fails to list package dependencies ErrCoverListFailed = errors.New("fail to list package dependencies") )
var ErrServiceAlreadyRegistered = errors.New("service already registered")
Functions ¶
func InjectCacheCounters ¶
func InjectCacheCounters(covers map[string][]*PackageCover, cache map[string]*PackageCover) []error
func InjectCountersHandlers ¶
InjectCountersHandlers generate a file _cover_http_apis.go besides the main.go file
func ListPackages ¶
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 NewFileBasedServer ¶
NewFileBasedServer new a file based server with persistenceFile
func NewMemoryBasedServer ¶
func NewMemoryBasedServer() *server
NewMemoryBasedServer new a memory based server without persistenceFile
func PercentStr ¶
PercentStr converts a fraction number to percentage string representation
func TotalDelta ¶
func TotalDelta(new CoverageList, base CoverageList) float32
TotalDelta calculate two coverage delta
Types ¶
type Action ¶
type Action interface { Profile(param ProfileParam) ([]byte, error) Clear(param ProfileParam) ([]byte, error) Remove(param ProfileParam) ([]byte, error) InitSystem() ([]byte, error) ListServices() ([]byte, error) RegisterService(svr ServiceUnderTest) ([]byte, error) }
Action provides methods to contact with the covered service under test
type CoverInfo ¶
type CoverInfo struct { Target string GoPath string IsMod bool ModRootPath string GlobalCoverVarImportPath string // path for the injected global cover var file OneMainPackage bool Args string Mode string AgentPort string Center string Singleton bool }
CoverBuildInfo retreives some info from build
type Coverage ¶
Coverage stores test coverage summary data for one file
func (*Coverage) Percentage ¶
Percentage returns the percentage of statements covered
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)
CovList converts profile to CoverageList struct
func NewCoverageList ¶
func NewCoverageList() CoverageList
NewCoverageList return empty CoverageList
func ReadFileToCoverList ¶
func ReadFileToCoverList(path string) (g CoverageList, err error)
ReadFileToCoverList coverts 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) TotalPercentage ¶
func (g CoverageList) TotalPercentage() string
TotalPercentage returns the total percentage of coverage
func (CoverageList) TotalRatio ¶
func (g CoverageList) TotalRatio() (ratio float32, err error)
TotalRatio returns the total ratio of covered statements
type DeltaCov ¶
type DeltaCov struct { FileName string BasePer string NewPer string DeltaPer string LineCovLink string }
DeltaCov contains the info of a delta coverage
func (*DeltaCov) GetLineCovLink ¶
GetLineCovLink get the LineCovLink of the DeltaCov
func (*DeltaCov) SetLineCovLink ¶
SetLineCovLink set LineCovLink of the DeltaCov
type DeltaCovList ¶
type DeltaCovList []DeltaCov
DeltaCovList is the list of DeltaCov
func GetChFileDeltaCov ¶
func GetChFileDeltaCov(newList CoverageList, baseList CoverageList, changedFiles []string) (list DeltaCovList)
GetChFileDeltaCov get two profile diff cov of changed files
func GetDeltaCov ¶
func GetDeltaCov(newList CoverageList, baseList CoverageList) (delta DeltaCovList)
GetDeltaCov get two profile diff cov
func GetFullDeltaCov ¶
func GetFullDeltaCov(newList CoverageList, baseList CoverageList) (delta DeltaCovList)
GetFullDeltaCov 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
type ModuleError ¶
type ModuleError struct {
Err string // error text
}
ModuleError represents the error loading module
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 }
ModulePublic represents the package info of a 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 ¶
PackageCover holds all the generate coverage variables of a package
func AddCounters ¶
func AddCounters(pkg *Package, mode string, globalCoverVarImportPath string) (*PackageCover, string)
AddCounters is different from official go tool cover 1. only inject covervar++ into source file 2. no declarartions for these covervars 3. return the declarations as string
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 ProfileParam ¶
type ProfileParam struct { Force bool `form:"force" json:"force"` Service []string `form:"service" json:"service"` Address []string `form:"address" json:"address"` CoverFilePatterns []string `form:"coverfile" json:"coverfile"` SkipFilePatterns []string `form:"skipfile" json:"skipfile"` }
ProfileParam is param of profile API
type ServiceUnderTest ¶
type ServiceUnderTest struct { Name string `form:"name" json:"name" binding:"required"` Address string `form:"address" json:"address" binding:"required"` }
ServiceUnderTest is a entry under being tested
type Store ¶
type Store interface { // Add adds the given service to store Add(s ServiceUnderTest) 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) error // Remove the service from the store by address Remove(addr string) error }
Store persistents the registered service information
func NewFileStore ¶
NewFileStore creates a store using local file
type TestCover ¶
type TestCover struct { Mode string AgentPort string Center string // cover profile host center Singleton bool MainPkgCover *PackageCover DepsCover []*PackageCover CacheCover map[string]*PackageCover GlobalCoverVarImportPath string }
TestCover is a collection of all counters