golden

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package golden hosts the M9 unified golden-file workflow: Compare / CompareSVG / CompareJSON sharing the `-update` flag declared in tests/integration/output_json_test.go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare

func Compare(t *testing.T, got []byte, goldenPath string)

Compare diffs `got` against the golden file at tests/golden/<goldenPath>. On the `-update` flag (declared in tests/integration/output_json_test.go and shared by all callers), rewrites the golden file and passes. Without -update, fails the test on byte mismatch with a first-divergent-offset diff window.

func CompareJSON

func CompareJSON(t *testing.T, got []byte, goldenPath string)

CompareJSON re-marshals both sides through json.MarshalIndent with the standard 2-space indent so per-key whitespace drift between encoders does not break the comparison.

func CompareSVG

func CompareSVG(t *testing.T, got []byte, goldenPath string)

CompareSVG applies NormalizeSVG to both sides before byte-diffing. Used for SVG goldens that must tolerate Go-runtime / chromedp drift in non-semantic bytes (attribute order, whitespace inside text nodes, dynamic footer fragments).

func NormalizeSVG

func NormalizeSVG(raw []byte) ([]byte, error)

NormalizeSVG produces a byte-stable representation of an SVG document by:

  1. Replacing the dynamic footer fragments ("Last updated <time>" and "<repo>/github-metrics@<version>") with __MASKED__ so test runs don't fluctuate with timestamps or version strings.
  2. Re-emitting elements with their attributes sorted alphabetically.
  3. Collapsing whitespace inside text nodes to a single space.
  4. Dropping XML comments.

The output is suitable for MD5-comparison golden files. Used internally by CompareSVG; exported so callers that need raw normalization (e.g., diffing two in-flight SVGs without a golden file) can reuse the helper.

Types

This section is empty.

Jump to

Keyboard shortcuts

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