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