MCPcopy Index your code
hub / github.com/dosco/graphjin / TestMetadataGraphPopulatesAndLinksCodeSQLRefs

Function TestMetadataGraphPopulatesAndLinksCodeSQLRefs

serv/metadata_test.go:16–125  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestMetadataGraphPopulatesAndLinksCodeSQLRefs(t *testing.T) {
17 appPath := createMetadataAppDB(t)
18 source := t.TempDir()
19 writeTestFile(t, filepath.Join(source, "main.go"), `package main
20
21func LookupUser() {
22 query := "SELECT users.email FROM users WHERE users.id = ?"
23 _ = query
24}
25`)
26
27 conf := &Config{
28 Core: Core{
29 DisableAllowList: true,
30 Sources: []core.SourceConfig{
31 {Name: "app", Kind: "database", Type: "sqlite", Path: appPath, Default: true},
32 {Name: "code", Kind: "code", Path: source},
33 {Name: defaultMetadataDBName, Kind: "graphjin"},
34 },
35 },
36 Serv: Serv{
37 ConfigPath: filepath.Join(t.TempDir(), "config"),
38 MCP: MCPConfig{Disable: true},
39 },
40 }
41
42 s, err := newGraphJinService(conf, nil)
43 if err != nil {
44 t.Fatal(err)
45 }
46 defer closeTestService(s)
47
48 if s.metadataDB != defaultMetadataDBName {
49 t.Fatalf("metadata database = %q, want %q", s.metadataDB, defaultMetadataDBName)
50 }
51 runtime := s.runtimeCore.Databases[defaultMetadataDBName]
52 if runtime.Type != "nanodb" || !runtime.ReadOnly {
53 t.Fatalf("metadata runtime = %+v, want read-only nanodb", runtime)
54 }
55 assertGraphJinTable(t, s, defaultMetadataDBName, "gj_catalog")
56 assertGraphJinTable(t, s, defaultMetadataDBName, "gj_workflow")
57 assertServiceCount(t, s, "code", `SELECT count(*) FROM gj_code WHERE kind = 'db_reference' AND db_object_id = 'app:main.users.email'`, 1)
58 res, err := s.gj.GraphQL(sourceModeUserTestContext(), `query {
59 gj_catalog(where: { kind: { eq: "column" }, database_name: { eq: "app" }, table_name: { eq: "users" }, column_name: { eq: "email" } }, limit: 1) {
60 id
61 kind
62 database_name
63 table_name
64 column_name
65 code_refs_id
66 gj_code {
67 kind
68 path
69 db_object_id
70 }
71 }
72 directives: gj_catalog(where: { kind: { eq: "directive" }, title: { eq: "@running" } }, limit: 1) {
73 id

Callers

nothing calls this directly

Calls 9

createMetadataAppDBFunction · 0.85
writeTestFileFunction · 0.85
newGraphJinServiceFunction · 0.85
closeTestServiceFunction · 0.85
assertGraphJinTableFunction · 0.85
assertServiceCountFunction · 0.85
hasRuntimeRelationshipFunction · 0.85
GraphQLMethod · 0.45

Tested by

no test coverage detected