MCPcopy Index your code
hub / github.com/dagger/dagger / TestModuleResolutionFromSubdirectory

Function TestModuleResolutionFromSubdirectory

engine/server/session_test.go:215–285  ·  view source on GitHub ↗

TestModuleResolutionFromSubdirectory verifies that module source paths from dagger.json are resolved relative to the config file location, not the client's working directory. When a client connects from sdk/go/, a module with source "modules/changelog" should resolve to /repo/modules/changelog, not

(t *testing.T)

Source from the content-addressed store, hash-verified

213// with source "modules/changelog" should resolve to /repo/modules/changelog,
214// not /repo/sdk/go/modules/changelog.
215func TestModuleResolutionFromSubdirectory(t *testing.T) {
216 t.Parallel()
217
218 // Filesystem layout:
219 // /repo/.git (git root)
220 // /repo/dagger.json (config declaring a module)
221 // /repo/sdk/go/ (client CWD)
222
223 existingFiles := map[string]bool{
224 "/repo/.git": true,
225 "/repo/dagger.json": true,
226 }
227
228 statFS := core.StatFSFunc(func(_ context.Context, path string) (string, *core.Stat, error) {
229 path = filepath.Clean(path)
230 if existingFiles[path] {
231 return filepath.Dir(path), &core.Stat{
232 Name: filepath.Base(path),
233 }, nil
234 }
235 return "", nil, os.ErrNotExist
236 })
237
238 // The "toolchains" field is the current config mechanism for declaring
239 // workspace modules in dagger.json.
240 daggerJSON := `{
241 "name": "myproject",
242 "toolchains": [
243 {"name": "changelog", "source": "modules/changelog"}
244 ]
245 }`
246
247 readFile := func(_ context.Context, path string) ([]byte, error) {
248 if filepath.Clean(path) == "/repo/dagger.json" {
249 return []byte(daggerJSON), nil
250 }
251 return nil, os.ErrNotExist
252 }
253
254 resolveLocalRef := func(ws *workspace.Workspace, relPath string) string {
255 return filepath.Join(ws.Root, ws.Path, relPath)
256 }
257
258 ctx := engine.ContextWithClientMetadata(context.Background(), &engine.ClientMetadata{
259 ClientID: "test-client",
260 })
261
262 client := &daggerClient{
263 pendingWorkspaceLoad: true,
264 clientMetadata: &engine.ClientMetadata{
265 LoadWorkspaceModules: true,
266 },
267 }
268
269 srv := &Server{}
270 err := srv.detectAndLoadWorkspace(ctx, client,
271 statFS,
272 readFile,

Callers

nothing calls this directly

Calls 8

StatFSFuncFuncType · 0.92
BackgroundMethod · 0.65
LenMethod · 0.65
EqualMethod · 0.65
DirMethod · 0.45
BaseMethod · 0.45

Tested by

no test coverage detected