selfupdatetest

package
v0.11.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 21 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var ErrFake = errors.New("fake failure")

ErrFake is a ready error for fake verifiers and sources.

Functions

func Archive

func Archive(tb testing.TB, entries ...Entry) []byte

Archive returns a tar.gz holding entries, in order.

func BuildFake

func BuildFake(tb testing.TB, version, mode string) string

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

func BuildFakeFor(tb testing.TB, goos, goarch, version string) string

BuildFakeFor cross-compiles the fake for another platform, for header checks.

func Checksums

func Checksums(files map[string][]byte) []byte

Checksums returns a checksums.txt body for the given name to content map.

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 Copy

func Copy(tb testing.TB, src, dst string, mode os.FileMode)

Copy copies the file at src to dst with mode, creating dst's directory.

func 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.

func TempDir

func TempDir(tb testing.TB) string

TempDir is tb.TempDir with symlinks resolved. self upgrade reports the resolved path of the executable, and on macOS the temp dir is under /var, a symlink to /private/var.

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

type ReleaseSpec struct {
	Tag        string
	Prerelease bool
	Draft      bool
	Assets     map[string][]byte
}

ReleaseSpec is one release the fake server publishes.

func Release

func Release(tb testing.TB, version string) ReleaseSpec

Release returns a release spec for version whose archive holds a fake gskill for this platform reporting that version, with a matching checksums.txt and a placeholder signature bundle for a fake verifier.

type Server

type Server struct {
	*httptest.Server
	// contains filtered or unexported fields
}

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) APIBase

func (s *Server) APIBase() string

APIBase is the repository API base the GitHub source should use.

func (*Server) AnyAssetRequested

func (s *Server) AnyAssetRequested() bool

AnyAssetRequested reports whether any asset was downloaded.

func (*Server) AssetRequested

func (s *Server) AssetRequested(name string) bool

AssetRequested reports whether any request downloaded the named asset.

func (*Server) Authorization

func (s *Server) Authorization(path string) string

Authorization returns the Authorization header of the last request for path.

func (*Server) Requests

func (s *Server) Requests() []string

Requests returns every request path the server has seen, in order.

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.

type Verifier

type Verifier struct{ Err error }

Verifier is a selfupdate.Verifier that returns Err.

func (Verifier) VerifyManifest

func (v Verifier) VerifyManifest(context.Context, []byte, []byte, string) error

VerifyManifest returns v.Err.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL