Documentation
¶
Overview ¶
Package sample provides functionality for generating sample values of the types contained in the internal package.
Index ¶
- Variables
- func AddLicense(m *internal.Module, lic *licenses.License)
- func AddPackage(m *internal.Module, pkg *internal.Unit) *internal.Module
- func AddUnit(m *internal.Module, u *internal.Unit)
- func DefaultModule() *internal.Module
- func DefaultVersionMap() *internal.VersionMap
- func Documentation(goos, goarch, fileContents string) *internal.Documentation
- func Imports() []string
- func LicenseMetadata() []*licenses.Metadata
- func Licenses() []*licenses.License
- func Module(modulePath, version string, suffixes ...string) *internal.Module
- func ModuleInfo(modulePath, versionString string) *internal.ModuleInfo
- func NowTruncated() time.Time
- func PackageMeta(fullPath string) *internal.PackageMeta
- func ReplaceLicense(m *internal.Module, lic *licenses.License)
- func UnitEmpty(path, modulePath, version string) *internal.Unit
- func UnitForModuleRoot(m *internal.ModuleInfo) *internal.Unit
- func UnitForPackage(path, modulePath, version, name string, isRedistributable bool) *internal.Unit
- func UnitMeta(path, modulePath, version, name string, moduleIsRedistributable bool) *internal.UnitMeta
Constants ¶
This section is empty.
Variables ¶
var ( ModulePath = "github.com/valid/module_name" RepositoryURL = "https://github.com/valid/module_name" VersionString = "v1.0.0" CommitTime = NowTruncated() LicenseType = "MIT" LicenseFilePath = "LICENSE" NonRedistributableLicense = &licenses.License{ Metadata: &licenses.Metadata{ FilePath: "NONREDIST_LICENSE", Types: []string{"UNKNOWN"}, }, Contents: []byte(`unknown`), } PackageName = "foo" Suffix = "foo" PackagePath = path.Join(ModulePath, Suffix) V1Path = PackagePath ReadmeFilePath = "README.md" ReadmeContents = "readme" GOOS = internal.All GOARCH = internal.All Doc = Documentation(GOOS, GOARCH, DocContents) API = []*internal.Symbol{ Constant, Variable, Function, Type, } DocContents = ` // Package p is a package. // // // Links // // - pkg.go.dev, https://pkg.go.dev package p var V int ` Constant = &internal.Symbol{ SymbolMeta: internal.SymbolMeta{ Name: "Constant", Synopsis: "const Constant", Section: internal.SymbolSectionConstants, Kind: internal.SymbolKindConstant, }, GOOS: internal.All, GOARCH: internal.All, } Variable = &internal.Symbol{ SymbolMeta: internal.SymbolMeta{ Name: "Variable", Synopsis: "var Variable", Section: internal.SymbolSectionVariables, Kind: internal.SymbolKindVariable, }, GOOS: internal.All, GOARCH: internal.All, } Function = &internal.Symbol{ SymbolMeta: internal.SymbolMeta{ Name: "Function", Synopsis: "func Function() error", Section: internal.SymbolSectionFunctions, Kind: internal.SymbolKindFunction, }, GOOS: internal.All, GOARCH: internal.All, } FunctionNew = &internal.Symbol{ SymbolMeta: internal.SymbolMeta{ Name: "New", Synopsis: "func New() *Type", Section: internal.SymbolSectionTypes, Kind: internal.SymbolKindFunction, ParentName: "Type", }, GOOS: internal.All, GOARCH: internal.All, } Type = &internal.Symbol{ SymbolMeta: internal.SymbolMeta{ Name: "Type", Synopsis: "type Type struct", Section: internal.SymbolSectionTypes, Kind: internal.SymbolKindType, }, GOOS: internal.All, GOARCH: internal.All, Children: []*internal.SymbolMeta{ &FunctionNew.SymbolMeta, &Field, &Method, }, } Field = internal.SymbolMeta{ Name: "Type.Field", Synopsis: "field", Section: internal.SymbolSectionTypes, Kind: internal.SymbolKindField, ParentName: "Type", } Method = internal.SymbolMeta{ Name: "Type.Method", Synopsis: "method", Section: internal.SymbolSectionTypes, Kind: internal.SymbolKindMethod, ParentName: "Type", } )
These sample values can be used to construct test cases.
var LicenseCmpOpts = []cmp.Option{ cmp.Comparer(coveragePercentEqual), cmpopts.IgnoreFields(licensecheck.Match{}, "Start", "End"), }
LicenseCmpOpts are options to use when comparing licenses with the cmp package.
Functions ¶
func DefaultModule ¶
func DefaultVersionMap ¶
func DefaultVersionMap() *internal.VersionMap
func Documentation ¶
func Documentation(goos, goarch, fileContents string) *internal.Documentation
Documentation returns a Documentation value for the given Go source. It panics if there are errors parsing or encoding the source.
func LicenseMetadata ¶
func Module ¶
Module creates a Module with the given path and version. The list of suffixes is used to create Units within the module.
func ModuleInfo ¶
func ModuleInfo(modulePath, versionString string) *internal.ModuleInfo
func NowTruncated ¶
NowTruncated returns time.Now() truncated to Microsecond precision.
This makes it easier to work with timestamps in PostgreSQL, which have Microsecond precision:
https://www.postgresql.org/docs/9.1/datatype-datetime.html
func PackageMeta ¶
func PackageMeta(fullPath string) *internal.PackageMeta
func ReplaceLicense ¶
ReplaceLicense replaces all licenses having the same file path as lic with lic.
func UnitForModuleRoot ¶
func UnitForModuleRoot(m *internal.ModuleInfo) *internal.Unit
func UnitForPackage ¶
UnitForPackage constructs a unit with the given module path and suffix.
If modulePath is the standard library, the package path is the suffix, which must not be empty. Otherwise, the package path is the concatenation of modulePath and suffix.
The package name is last component of the package path.
Types ¶
This section is empty.