updatetest

package
v0.2.24 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package updatetest provides HTTP mocks and fake binaries for testing code that uses blit's auto-update system. It lets consumer apps write end-to-end update tests that do not hit the real GitHub API and do not touch the user's filesystem.

Typical usage in a consumer test:

srv := updatetest.NewMockServer(updatetest.Release{
    Tag: "v2.0.0", BinaryName: "mytool", Body: "# What's new",
})
defer srv.Close()

cfg := blit.UpdateConfig{
    Owner: "owner", Repo: "repo",
    BinaryName: "mytool", Version: "v1.0.0",
    APIBaseURL: srv.URL, CacheDir: t.TempDir(),
}
res, _ := blit.CheckForUpdate(cfg)
if !res.Available { t.Fatal("expected available update") }

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMockBinary

func NewMockBinary(version string) []byte

NewMockBinary returns a tiny fake binary payload tagged with the given version string. It is NOT a real executable — consumers that actually exec the returned bytes should instead use go build against a TestMain fixture. For checksum and extract-flow tests this is sufficient.

func NewMockServer

func NewMockServer(releases ...Release) *httptest.Server

NewMockServer returns an httptest.Server that serves GitHub-shaped release JSON for the given releases. The latest release (by tag order) is exposed at /repos/{owner}/{repo}/releases/latest. All releases are available at /repos/{owner}/{repo}/releases. Asset download URLs are served from the same server.

Multi-release callers: pass releases in priority order; the FIRST release is treated as the "latest".

Types

type Asset

type Asset struct {
	Name        string `json:"name"`
	DownloadURL string `json:"browser_download_url"`
	ContentType string `json:"content_type"`
}

Asset mirrors blit's ReleaseAsset shape for mock server responses.

type Release

type Release struct {
	// Tag is the release tag name, e.g. "v2.0.0". Required.
	Tag string
	// BinaryName is the name of the binary bundled inside the archive.
	// Required when Assets is empty.
	BinaryName string
	// Body is the release notes Markdown (shown in UpdateResult.ReleaseNotes).
	Body string
	// HTMLURL overrides the release page URL. Optional.
	HTMLURL string
	// Assets lets callers supply custom assets. If nil, defaults are
	// generated for the current GOOS/GOARCH.
	Assets []Asset
	// MinimumVersion, if non-empty, is prepended to Body as a
	// "minimum_version: <v>" marker so tests can exercise forced updates.
	MinimumVersion string
}

Release describes a single fake GitHub release for the mock server. BinaryName is the logical name of the binary inside the tar.gz asset. If Assets is empty, NewMockServer auto-generates a tar.gz asset for the current GOOS/GOARCH and a matching SHA256SUMS file.

Jump to

Keyboard shortcuts

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