(t *testing.T)
| 103 | } |
| 104 | |
| 105 | func TestModelChangeModes(t *testing.T) { |
| 106 | // --- RESET MODE --- |
| 107 | t.Run("reset", func(t *testing.T) { |
| 108 | rt, instanceID := testruntime.NewInstance(t) |
| 109 | createTableAsSelect(t, rt, instanceID, "duckdb", "foo", "SELECT 'US' AS country") |
| 110 | |
| 111 | // Create test resources m1, mv1 |
| 112 | testruntime.PutFiles(t, rt, instanceID, map[string]string{ |
| 113 | "m1.yaml": ` |
| 114 | version: 1 |
| 115 | type: model |
| 116 | sql: SELECT 'US' AS country |
| 117 | change_mode: reset |
| 118 | incremental: false |
| 119 | `, |
| 120 | "mv1.yaml": ` |
| 121 | type: metrics_view |
| 122 | version: 1 |
| 123 | model: m1 |
| 124 | dimensions: |
| 125 | - column: country |
| 126 | measures: |
| 127 | - expression: COUNT(*) |
| 128 | `, |
| 129 | }) |
| 130 | testruntime.ReconcileParserAndWait(t, rt, instanceID) |
| 131 | testruntime.RequireReconcileState(t, rt, instanceID, 3, 0, 0) // m1, mv1, project_settings |
| 132 | |
| 133 | ctrl, err := rt.Controller(context.Background(), instanceID) |
| 134 | require.NoError(t, err) |
| 135 | m1, err := ctrl.Get(context.Background(), &runtimev1.ResourceName{Kind: runtime.ResourceKindModel, Name: "m1"}, false) |
| 136 | require.NoError(t, err) |
| 137 | initialVersionM1 := int(m1.Meta.StateVersion) |
| 138 | |
| 139 | // Update m1.yaml with different SQL |
| 140 | testruntime.PutFiles(t, rt, instanceID, map[string]string{ |
| 141 | "m1.yaml": ` |
| 142 | version: 1 |
| 143 | type: model |
| 144 | sql: SELECT 'CA' AS country |
| 145 | change_mode: reset |
| 146 | incremental: false |
| 147 | `, |
| 148 | }) |
| 149 | testruntime.ReconcileParserAndWait(t, rt, instanceID) |
| 150 | testruntime.RequireReconcileState(t, rt, instanceID, 3, 0, 0) |
| 151 | |
| 152 | // Verify that the model m1 was refreshed |
| 153 | m1, err = ctrl.Get(context.Background(), &runtimev1.ResourceName{Kind: runtime.ResourceKindModel, Name: "m1"}, false) |
| 154 | require.NoError(t, err) |
| 155 | require.Greater(t, int(m1.Meta.StateVersion), initialVersionM1, "m1 was not refreshed in reset mode") |
| 156 | }) |
| 157 | |
| 158 | // --- MANUAL MODE --- |
| 159 | t.Run("manual", func(t *testing.T) { |
| 160 | rt, instanceID := testruntime.NewInstance(t) |
| 161 | createTableAsSelect(t, rt, instanceID, "duckdb", "foo", "SELECT 'US' AS country") |
| 162 |
nothing calls this directly
no test coverage detected