(t *testing.T, dir, projectDir string)
| 98 | } |
| 99 | |
| 100 | func runSingleDevboxTestscript(t *testing.T, dir, projectDir string) { |
| 101 | testscriptDir, err := generateTestscript(t, dir, projectDir) |
| 102 | if err != nil { |
| 103 | t.Error(err) |
| 104 | } |
| 105 | |
| 106 | params := getTestscriptParams(testscriptDir) |
| 107 | |
| 108 | // save a reference to the original params.Setup so that we can wrap it below |
| 109 | setup := params.Setup |
| 110 | params.Setup = func(envs *testscript.Env) error { |
| 111 | // We set a custom XDG_STATE_HOME to an intentionally short path. |
| 112 | // Reason: devbox plugins like postgres store unix socket files in their state dir. |
| 113 | envs.Setenv(envir.XDGStateHome, xdgStateHomeDir) |
| 114 | |
| 115 | // setup the devbox testscript environment |
| 116 | if err := setup(envs); err != nil { |
| 117 | return errors.WithStack(err) |
| 118 | } |
| 119 | |
| 120 | // copy all the files and folders of the devbox-project being tested to the workdir |
| 121 | slog.Debug("copying projectDir: %s to env.WorkDir: %s\n", projectDir, envs.WorkDir) |
| 122 | // implementation detail: the period at the end of the projectDir/. |
| 123 | // is important to ensure this works for both mac and linux. |
| 124 | // Ref.https://dev.to/ackshaey/macos-vs-linux-the-cp-command-will-trip-you-up-2p00 |
| 125 | |
| 126 | cmd := exec.Command("rm", "-rf", projectDir+"/.devbox") |
| 127 | err = cmd.Run() |
| 128 | if err != nil { |
| 129 | slog.Error("failed %s before doing cp", "cmd", cmd, "err", err) |
| 130 | return errors.WithStack(err) |
| 131 | } |
| 132 | |
| 133 | cmd = exec.Command("cp", "-r", projectDir+"/.", envs.WorkDir) |
| 134 | slog.Debug("running cmd", "cmd", cmd) |
| 135 | err = cmd.Run() |
| 136 | return errors.WithStack(err) |
| 137 | } |
| 138 | |
| 139 | testscript.Run(t, params) |
| 140 | } |
| 141 | |
| 142 | // generateTestscript will create a temp-directory and place the generic |
| 143 | // testscript file (.test.txt) for all devbox-projects in the dir. |
no test coverage detected