(t *testing.T)
| 18 | ) |
| 19 | |
| 20 | func TestGetQuerySpan(t *testing.T) { |
| 21 | type testCase struct { |
| 22 | Description string `yaml:"description,omitempty"` |
| 23 | Statement string `yaml:"statement,omitempty"` |
| 24 | DefaultDatabase string `yaml:"defaultDatabase,omitempty"` |
| 25 | // Metadata is the protojson encoded storepb.DatabaseSchemaMetadata, |
| 26 | // if it's empty, we will use the defaultDatabaseMetadata. |
| 27 | Metadata string `yaml:"metadata,omitempty"` |
| 28 | QuerySpan *base.YamlQuerySpan `yaml:"querySpan,omitempty"` |
| 29 | } |
| 30 | |
| 31 | const ( |
| 32 | record = false |
| 33 | ) |
| 34 | |
| 35 | var ( |
| 36 | testDataPaths = []string{ |
| 37 | "test-data/query_span.yaml", |
| 38 | "test-data/query_type.yaml", |
| 39 | } |
| 40 | ) |
| 41 | |
| 42 | a := require.New(t) |
| 43 | |
| 44 | for _, testDataPath := range testDataPaths { |
| 45 | yamlFile, err := os.Open(testDataPath) |
| 46 | a.NoError(err) |
| 47 | |
| 48 | var testCases []testCase |
| 49 | byteValue, err := io.ReadAll(yamlFile) |
| 50 | a.NoError(err) |
| 51 | a.NoError(yamlFile.Close()) |
| 52 | a.NoError(yaml.Unmarshal(byteValue, &testCases)) |
| 53 | |
| 54 | for i, tc := range testCases { |
| 55 | metadata := &storepb.DatabaseSchemaMetadata{} |
| 56 | a.NoError(common.ProtojsonUnmarshaler.Unmarshal([]byte(tc.Metadata), metadata)) |
| 57 | databaseMetadataGetter, databaseNamesLister := buildMockDatabaseMetadataGetter([]*storepb.DatabaseSchemaMetadata{metadata}) |
| 58 | result, err := GetQuerySpan(context.TODO(), base.GetQuerySpanContext{ |
| 59 | GetDatabaseMetadataFunc: databaseMetadataGetter, |
| 60 | ListDatabaseNamesFunc: databaseNamesLister, |
| 61 | }, base.Statement{Text: tc.Statement}, tc.DefaultDatabase, "", false) |
| 62 | a.NoError(err) |
| 63 | resultYaml := result.ToYaml() |
| 64 | if record { |
| 65 | testCases[i].QuerySpan = resultYaml |
| 66 | } else { |
| 67 | a.Equal(tc.QuerySpan, resultYaml, "statement: %s", tc.Statement) |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | if record { |
| 72 | yamltest.Record(t, testDataPath, testCases) |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | // When a referenced column is missing from cached metadata, the extractor must |
nothing calls this directly
no test coverage detected