Skip to content

[Feature Request]: ability to "label" snapshots #151

@G-Rath

Description

@G-Rath

🚀 Feature Proposal

In osv-scanner we have this:

func RunAndMatchSnapshots(t *testing.T, tc Case) {
	t.Helper()

	stdout, stderr := RunAndNormalize(t, tc)

	testutility.NewSnapshot().MatchText(t, stdout)
	testutility.NewSnapshot().WithWindowsReplacements(map[string]string{
		"CreateFile": "stat",
	}).MatchText(t, stderr)
}

which results in snapshots like this:

[TestCommand/no_lockfiles_without_recursion_but_with_allow_flag_are_fine - 1]
Scanning dir ./testdata/locks-none
No package sources found
No issues found

---

[TestCommand/no_lockfiles_without_recursion_but_with_allow_flag_are_fine - 2]

---

It would be cool if we could label snapshots, e.g.

	testutility.NewSnapshot().WithLabel("stdout").MatchText(t, stdout)
	testutility.NewSnapshot().WithLabel("stderr").WithWindowsReplacements(map[string]string{
		"CreateFile": "stat",
	}).MatchText(t, stderr)

which would result in:

[TestCommand/no_lockfiles_without_recursion_but_with_allow_flag_are_fine - 1 - stdout]
Scanning dir ./testdata/locks-none
No package sources found
No issues found

---

[TestCommand/no_lockfiles_without_recursion_but_with_allow_flag_are_fine - 2 - stderr]

---

Note, under the hood testutility.NewSnapshot translates to snaps.MatchSnapshot

Motivation

This would make it easier to review snapshots, while still allowing them to be ordered

Example

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions