MCPcopy Create free account
hub / github.com/dagger/dagger / TestNamespaceSourceMap

Function TestNamespaceSourceMap

core/module_test.go:12–71  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestNamespaceSourceMap(t *testing.T) {
13 mod := &Module{NameField: "mymod"}
14
15 t.Run("synthesizes module-name-only source map when SDK provides none", func(t *testing.T) {
16 ctx := t.Context()
17
18 cache, err := dagql.NewCache(ctx, "", nil, nil)
19 require.NoError(t, err)
20 ctx = dagql.ContextWithCache(ctx, cache)
21
22 root := &Query{}
23 testSrv := &moduleObjectTestServer{
24 mockServer: &mockServer{},
25 cache: cache,
26 root: root,
27 }
28 root.Server = testSrv
29 dag := newCoreDagqlServerForTest(t, root)
30 testSrv.dag = dag
31
32 dag.InstallObject(dagql.NewClass(dag, dagql.ClassOpts[*SourceMap]{Typed: &SourceMap{}}))
33 dagql.Fields[*Query]{
34 dagql.Func("sourceMap", func(_ context.Context, _ *Query, args struct {
35 Module dagql.Optional[dagql.String] `internal:"true"`
36 Filename string
37 Line int
38 Column int
39 URL dagql.Optional[dagql.String] `internal:"true"`
40 }) (*SourceMap, error) {
41 var module string
42 if args.Module.Valid {
43 module = string(args.Module.Value)
44 }
45 var url string
46 if args.URL.Valid {
47 url = string(args.URL.Value)
48 }
49 return &SourceMap{
50 Module: module,
51 Filename: args.Filename,
52 Line: args.Line,
53 Column: args.Column,
54 URL: url,
55 }, nil
56 }),
57 }.Install(dag)
58
59 ctx = ContextWithQuery(ctx, root)
60 ctx = engine.ContextWithClientMetadata(ctx, &engine.ClientMetadata{
61 ClientID: "namespace-source-map-test-client",
62 SessionID: "namespace-source-map-test-session",
63 })
64
65 result, err := mod.namespaceSourceMap(ctx, "sub", dagql.Null[dagql.ObjectResult[*SourceMap]]())
66 require.NoError(t, err)
67 require.True(t, result.Valid)
68 require.NotNil(t, result.Value.Self())
69 require.Equal(t, "mymod", result.Value.Self().Module)

Callers

nothing calls this directly

Calls 15

namespaceSourceMapMethod · 0.95
NewCacheFunction · 0.92
ContextWithCacheFunction · 0.92
NewClassFunction · 0.92
FuncFunction · 0.92
NullFunction · 0.92
ContextWithQueryFunction · 0.85
SelfMethod · 0.80
RunMethod · 0.65
ContextMethod · 0.65

Tested by

no test coverage detected