MCPcopy Index your code
hub / github.com/jetify-com/devbox / generateTestscript

Function generateTestscript

testscripts/testrunner/examplesrunner.go:145–172  ·  view source on GitHub ↗

generateTestscript will create a temp-directory and place the generic testscript file (.test.txt) for all devbox-projects in the dir. It returns the directory containing the testscript file.

(t *testing.T, dir, projectDir string)

Source from the content-addressed store, hash-verified

143// testscript file (.test.txt) for all devbox-projects in the dir.
144// It returns the directory containing the testscript file.
145func generateTestscript(t *testing.T, dir, projectDir string) (string, error) {
146 testPath, err := filepath.Rel(dir, projectDir)
147 if err != nil {
148 return "", errors.WithStack(err)
149 }
150
151 // scriptName is the generic script file used for all devbox projects
152 const scriptName = "run_test.test.txt"
153
154 // scriptNameForProject prefixes the project's path (with underscores) to the scriptName
155 // so that the golang testing.T provides nice readable names for the test run
156 // for each Example devbox-project.
157 scriptNameForProject := fmt.Sprintf(
158 "%s_%s",
159 strings.ReplaceAll(testPath, "/", "_"),
160 scriptName,
161 )
162
163 // create a temp-dir to place the testscript file
164 testscriptDir := t.TempDir()
165
166 // Copy the testscript file to the temp-dir
167 runTestScriptPath := filepath.Join("testrunner", scriptName)
168 slog.Debug("copying run_test.test.txt from %s to %s\n", runTestScriptPath, testscriptDir)
169 // Using os's cp command for expediency.
170 err = exec.Command("cp", runTestScriptPath, testscriptDir+"/"+scriptNameForProject).Run()
171 return testscriptDir, errors.WithStack(err)
172}

Callers 1

Calls 2

CommandMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected