(t *testing.T)
| 819 | } |
| 820 | |
| 821 | func TestMetricsView(t *testing.T) { |
| 822 | // Create source and model |
| 823 | rt, id := testruntime.NewInstance(t) |
| 824 | testruntime.PutFiles(t, rt, id, map[string]string{ |
| 825 | "/data/foo.csv": `a,b,c,d,e |
| 826 | 1,2,3,4,5 |
| 827 | 1,2,3,4,5 |
| 828 | 1,2,3,4,5 |
| 829 | `, |
| 830 | "/sources/foo.yaml": ` |
| 831 | connector: local_file |
| 832 | path: data/foo.csv |
| 833 | `, |
| 834 | "/models/bar.sql": `SELECT * FROM foo`, |
| 835 | "/metrics/dash.yaml": ` |
| 836 | version: 1 |
| 837 | type: metrics_view |
| 838 | display_name: Dash |
| 839 | model: bar |
| 840 | dimensions: |
| 841 | - column: b |
| 842 | - column: c |
| 843 | measures: |
| 844 | - expression: count(*) |
| 845 | - expression: avg(a) |
| 846 | `, |
| 847 | }) |
| 848 | |
| 849 | _, metricsRes := newMetricsView("dash", "bar", "", []any{"count(*)", runtimev1.Type_CODE_INT64, "avg(a)", runtimev1.Type_CODE_FLOAT64}, []any{"b", runtimev1.Type_CODE_INT64, "c", runtimev1.Type_CODE_INT64}) |
| 850 | testruntime.ReconcileParserAndWait(t, rt, id) |
| 851 | testruntime.RequireReconcileState(t, rt, id, 4, 0, 0) |
| 852 | testruntime.RequireResource(t, rt, id, metricsRes) |
| 853 | |
| 854 | // ignore invalid measure and dimension |
| 855 | testruntime.PutFiles(t, rt, id, map[string]string{ |
| 856 | "/metrics/dash.yaml": ` |
| 857 | version: 1 |
| 858 | type: metrics_view |
| 859 | display_name: Dash |
| 860 | model: bar |
| 861 | dimensions: |
| 862 | - column: b |
| 863 | - column: f |
| 864 | ignore: true |
| 865 | measures: |
| 866 | - expression: count(*) |
| 867 | - expression: avg(g) |
| 868 | ignore: true |
| 869 | `, |
| 870 | }) |
| 871 | _, metricsRes = newMetricsView("dash", "bar", "", []any{"count(*)", runtimev1.Type_CODE_INT64}, []any{"b", runtimev1.Type_CODE_INT64}) |
| 872 | testruntime.ReconcileParserAndWait(t, rt, id) |
| 873 | testruntime.RequireReconcileState(t, rt, id, 4, 0, 0) |
| 874 | testruntime.RequireResource(t, rt, id, metricsRes) |
| 875 | |
| 876 | // no measure, invalid dashboard |
| 877 | testruntime.PutFiles(t, rt, id, map[string]string{ |
| 878 | "/metrics/dash.yaml": ` |
nothing calls this directly
no test coverage detected