MCPcopy Index your code
hub / github.com/bytebase/bytebase / TestCompletion

Function TestCompletion

backend/plugin/parser/mongodb/completion_test.go:24–79  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

22}
23
24func TestCompletion(t *testing.T) {
25 tests := []candidatesTest{}
26
27 const (
28 record = false
29 )
30 var (
31 filepath = "test-data/test_completion.yaml"
32 )
33
34 a := require.New(t)
35 yamlFile, err := os.Open(filepath)
36 a.NoError(err)
37
38 byteValue, err := io.ReadAll(yamlFile)
39 a.NoError(yamlFile.Close())
40 a.NoError(err)
41 a.NoError(yaml.Unmarshal(byteValue, &tests))
42
43 for i, tc := range tests {
44 text, caretLine, caretOffset := catchCaret(tc.Input)
45 result, err := base.Completion(context.Background(), storepb.Engine_MONGODB, base.CompletionContext{
46 Scene: base.SceneTypeAll,
47 DefaultDatabase: "test",
48 Metadata: getMetadataForTest,
49 }, text, caretLine, caretOffset)
50 a.NoError(err)
51
52 // Sort results for consistent comparison
53 slices.SortFunc(result, func(x, y base.Candidate) int {
54 if x.Type != y.Type {
55 if x.Type < y.Type {
56 return -1
57 }
58 return 1
59 }
60 if x.Text != y.Text {
61 if x.Text < y.Text {
62 return -1
63 }
64 return 1
65 }
66 return 0
67 })
68
69 if record {
70 tests[i].Want = result
71 } else {
72 a.Equal(tc.Want, result, tc.Input)
73 }
74 }
75
76 if record {
77 yamltest.Record(t, filepath, tests)
78 }
79}
80
81func getMetadataForTest(_ context.Context, _, databaseName string) (string, *model.DatabaseMetadata, error) {

Callers

nothing calls this directly

Calls 7

CompletionFunction · 0.92
RecordFunction · 0.92
UnmarshalMethod · 0.80
catchCaretFunction · 0.70
OpenMethod · 0.65
CloseMethod · 0.65
EqualMethod · 0.65

Tested by

no test coverage detected