MCPcopy
hub / github.com/grafana/tempo / setupTestDir

Function setupTestDir

tools/chloggen/cmd/cmd_test.go:122–149  ·  view source on GitHub ↗
(t *testing.T, entries []*chlog.Entry)

Source from the content-addressed store, hash-verified

120}
121
122func setupTestDir(t *testing.T, entries []*chlog.Entry) {
123 require.NotNil(t, globalCfg, "test should instantiate globalCfg before calling setupTestDir")
124
125 // Create dummy changelogs which may be updated by the test
126 changelogBytes, err := readBytes(filepath.Join("testdata", config.DefaultChangeLogFilename))
127 require.NoError(t, err)
128 for _, filename := range globalCfg.ChangeLogs {
129 require.NoError(t, os.MkdirAll(filepath.Dir(filename), os.FileMode(0o755)))
130 require.NoError(t, os.WriteFile(filename, changelogBytes, os.FileMode(0o755)))
131 }
132
133 // Create the entries directory
134 require.NoError(t, os.MkdirAll(globalCfg.EntriesDir, os.FileMode(0o755)))
135
136 // Copy the entry template, for tests that ensure it is not deleted
137 templateInRootDir := config.New("testdata").TemplateYAML
138 templateBytes, err := readBytes(filepath.Clean(templateInRootDir))
139 require.NoError(t, err)
140 require.NoError(t, os.WriteFile(globalCfg.TemplateYAML, templateBytes, os.FileMode(0o755)))
141
142 // Write the entries to the entries directory
143 for i, entry := range entries {
144 entryBytes, err := yaml.Marshal(entry)
145 require.NoError(t, err)
146 path := filepath.Join(globalCfg.EntriesDir, fmt.Sprintf("%d.yaml", i))
147 require.NoError(t, os.WriteFile(path, entryBytes, os.FileMode(0o755)))
148 }
149}
150
151func runCobra(t *testing.T, args ...string) (string, error) {
152 cmd := rootCmd()

Callers 8

TestNewFunction · 0.85
TestUpdateErrFunction · 0.85
TestUpdateFunction · 0.85
TestValidateFunction · 0.85

Calls 4

NewFunction · 0.92
readBytesFunction · 0.85
JoinMethod · 0.65
MarshalMethod · 0.65

Tested by

no test coverage detected