(t *testing.T)
| 22 | } |
| 23 | |
| 24 | func 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 | |
| 81 | func getMetadataForTest(_ context.Context, _, databaseName string) (string, *model.DatabaseMetadata, error) { |
nothing calls this directly
no test coverage detected