Documentation
¶
Overview ¶
Package selfupdatetest holds test helpers for the self-upgrade code: a fake GitHub release server, a fake signature verifier, an in-memory archive builder, and a small fake gskill binary built on demand.
Index ¶
- Variables
- func Archive(tb testing.TB, entries ...Entry) []byte
- func BuildFake(tb testing.TB, version, mode string) string
- func BuildFakeFor(tb testing.TB, goos, goarch, version string) string
- func Checksums(files map[string][]byte) []byte
- func Cleanup()
- func Copy(tb testing.TB, src, dst string, mode os.FileMode)
- func Env(tb testing.TB, exe string, build selfupdate.BuildInfo, src selfupdate.Source, ...) selfupdate.Env
- func TempDir(tb testing.TB) string
- type Entry
- type ReleaseSpec
- type Server
- type ServerOptions
- type Verifier
Constants ¶
This section is empty.
Variables ¶
var ErrFake = errors.New("fake failure")
ErrFake is a ready error for fake verifiers and sources.
Functions ¶
func BuildFake ¶
BuildFake returns a fake gskill for this platform that reports version and behaves according to mode ("ok", "badjson", "hang", or "fail"). Each (version, mode) pair is built once per test process.
func BuildFakeFor ¶
BuildFakeFor cross-compiles the fake for another platform, for header checks.
func Cleanup ¶
func Cleanup()
Cleanup removes the binaries BuildFake cached. Call it from TestMain after m.Run; without it the cache stays in the system temp directory.
func Env ¶
func Env(tb testing.TB, exe string, build selfupdate.BuildInfo, src selfupdate.Source, v selfupdate.Verifier) selfupdate.Env
Env returns an Env for exe with the given build, source, and verifier. PATH lookups find nothing, so a gskill installed on the test machine never shows up as a shadow executable.
Types ¶
type Entry ¶
type Entry struct {
Name string
Body []byte
Mode int64
// Type defaults to tar.TypeReg.
Type byte
// Size overrides the header size, to describe oversized entries without
// writing their bytes.
Size int64
}
Entry is one file in an archive built by Archive.
type ReleaseSpec ¶
ReleaseSpec is one release the fake server publishes.
type Server ¶
Server is a fake GitHub API and release download host over TLS.
func NewServer ¶
func NewServer(tb testing.TB, opts ServerOptions) *Server
NewServer starts a fake server that is closed when the test ends.
func (*Server) AnyAssetRequested ¶
AnyAssetRequested reports whether any asset was downloaded.
func (*Server) AssetRequested ¶
AssetRequested reports whether any request downloaded the named asset.
func (*Server) Authorization ¶
Authorization returns the Authorization header of the last request for path.
type ServerOptions ¶
type ServerOptions struct {
Releases []ReleaseSpec
// Status forces a status code for a request path.
Status map[string]int
// RateLimited answers every API request with 403 and
// X-RateLimit-Remaining: 0.
RateLimited bool
// DropAfter cuts the connection after this many bytes of the named asset.
DropAfter map[string]int
// Block holds the named asset's response until the channel is closed.
Block map[string]chan struct{}
// Override serves this raw body for a request path.
Override map[string]string
}
ServerOptions configure the fake GitHub server.