Documentation ¶
Index ¶
- Constants
- Variables
- func Delta(new Coverage, base Coverage) float32
- func Execute(args, newGopath, target, mode, center string) error
- func GocServer(w io.Writer) *gin.Engine
- 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 PercentStr(f float32) string
- func Run(port string)
- func TotalDelta(new CoverageList, base CoverageList) float32
- type Action
- type Coverage
- type CoverageList
- type DeltaCov
- type DeltaCovList
- type FileVar
- type ModuleError
- type ModulePublic
- type Package
- type PackageCover
- type PackageError
- type Service
- 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" )
const LogFile = "goc.log"
LogFile a file to save log.
const PersistenceFile = "_svrs_address.txt"
PersistenceFile is the file to save services address information
Variables ¶
var ( ErrCoverPkgFailed = errors.New("fail to inject code to project") ErrCoverListFailed = errors.New("fail to list package dependencies") )
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 PercentStr ¶
PercentStr converts a fraction number to percentage string representation
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
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)
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) 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 (*DeltaCov) GetLineCovLink ¶
func (*DeltaCov) SetLineCovLink ¶
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
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 ¶
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
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