MCPcopy
hub / github.com/go-task/task / writeFixture

Method writeFixture

task_test.go:69–102  ·  view source on GitHub ↗

writeFixture writes a fixture file for the test. The fixture file is created using the [goldie.Goldie] package. The fixture file is created with the output of the task, after any post-process functions have been applied.

(
	t *testing.T,
	g *goldie.Goldie,
	goldenFileSuffix string,
	b []byte,
)

Source from the content-addressed store, hash-verified

67// using the [goldie.Goldie] package. The fixture file is created with the
68// output of the task, after any post-process functions have been applied.
69func (tt *TaskTest) writeFixture(
70 t *testing.T,
71 g *goldie.Goldie,
72 goldenFileSuffix string,
73 b []byte,
74) {
75 t.Helper()
76 // Apply any post-process functions
77 for _, fn := range tt.postProcessFns {
78 b = fn(t, b)
79 }
80 // Write the fixture file
81 goldenFileName := goldenFileName(t)
82 if goldenFileSuffix != "" {
83 goldenFileName += "-" + goldenFileSuffix
84 }
85 // Create a set of data to be made available to every test fixture
86 wd, err := os.Getwd()
87 require.NoError(t, err)
88 if tt.fixtureTemplatingEnabled {
89 fixtureTemplateData := map[string]any{
90 "TEST_NAME": t.Name(),
91 "TEST_DIR": filepath.ToSlash(wd),
92 }
93 // If the test has additional template data, copy it into the map
94 if tt.fixtureTemplateData != nil {
95 maps.Copy(fixtureTemplateData, tt.fixtureTemplateData)
96 }
97 // Normalize output before comparison (CRLF→LF, backslash→forward slash)
98 g.AssertWithTemplate(t, goldenFileName, fixtureTemplateData, normalizeOutput(b))
99 } else {
100 g.Assert(t, goldenFileName, b)
101 }
102}
103
104// writeFixtureBuffer is a wrapper for writing the main output of the task to a
105// fixture file.

Callers 5

writeFixtureBufferMethod · 0.95
writeFixtureErrSetupMethod · 0.95
writeFixtureErrListMethod · 0.80
writeFixtureErrRunMethod · 0.80
writeFixtureStatusMethod · 0.80

Calls 3

goldenFileNameFunction · 0.85
normalizeOutputFunction · 0.85
NameMethod · 0.80

Tested by

no test coverage detected