pkgsite: golang.org/x/pkgsite/internal/testing/sample Index | Files

package sample

import "golang.org/x/pkgsite/internal/testing/sample"

Package sample provides functionality for generating sample values of the types contained in the internal package.

Index

Package Files

sample.go

Variables

var (
    ModulePath      = "github.com/valid/module_name"
    RepositoryURL   = "https://github.com/valid/module_name"
    VersionString   = "v1.0.0"
    CommitTime      = NowTruncated()
    LicenseMetadata = []*licenses.Metadata{
        {
            Types:    []string{"MIT"},
            FilePath: "LICENSE",
            Coverage: licensecheck.Coverage{
                Percent: 100,
                Match:   []licensecheck.Match{{Name: "MIT", Type: licensecheck.MIT, Percent: 100}},
            },
        },
    }
    Licenses = []*licenses.License{
        {Metadata: LicenseMetadata[0], Contents: []byte(`Lorem Ipsum`)},
    }
    DocumentationHTML = template.MustParseAndExecuteToHTML("This is the documentation HTML")
    PackageName       = "foo"
    Suffix            = "foo"
    PackagePath       = path.Join(ModulePath, Suffix)
    V1Path            = PackagePath
    Imports           = []string{"path/to/bar", "fmt"}
    Synopsis          = "This is a package synopsis"
    ReadmeFilePath    = "README.md"
    ReadmeContents    = "readme"
    GOOS              = "linux"
    GOARCH            = "amd64"
)

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.

func AddDirectory Uses

func AddDirectory(m *internal.Module, d *internal.Directory)

func AddPackage Uses

func AddPackage(m *internal.Module, p *internal.LegacyPackage) *internal.Module

func DefaultModule Uses

func DefaultModule() *internal.Module

func DefaultVersionMap Uses

func DefaultVersionMap() *internal.VersionMap

func DirectoryEmpty Uses

func DirectoryEmpty(path string) *internal.Directory

func DirectoryForModuleRoot Uses

func DirectoryForModuleRoot(m *internal.LegacyModuleInfo, licenses []*licenses.Metadata) *internal.Directory

func DirectoryForPackage Uses

func DirectoryForPackage(pkg *internal.LegacyPackage) *internal.Directory

func LegacyModuleInfo Uses

func LegacyModuleInfo(modulePath, versionString string) *internal.LegacyModuleInfo

func LegacyPackage Uses

func LegacyPackage(modulePath, suffix string) *internal.LegacyPackage

LegacyPackage constructs a package 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.

func Module Uses

func Module(modulePath, version string, suffixes ...string) *internal.Module

Module creates a Module with the given path and version. The list of suffixes is used to create LegacyPackages within the module.

func ModuleInfo Uses

func ModuleInfo(modulePath, versionString string) *internal.ModuleInfo

func ModuleInfoReleaseType Uses

func ModuleInfoReleaseType(modulePath, versionString string) *internal.ModuleInfo

We shouldn't need this, but some code (notably frontend/directory_test.go) creates ModuleInfos with "latest" for version, which should not be valid.

func NowTruncated Uses

func NowTruncated() time.Time

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 Uses

func PackageMeta(modulePath, suffix string) *internal.PackageMeta

Package sample imports 15 packages (graph) and is imported by 2 packages. Updated 2020-08-05. Refresh now. Tools for package owners.