MCPcopy Create free account
hub / github.com/rilldata/rill / TestModelChangeModes

Function TestModelChangeModes

runtime/server/controller_test.go:105–276  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

103}
104
105func 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": `
114version: 1
115type: model
116sql: SELECT 'US' AS country
117change_mode: reset
118incremental: false
119`,
120 "mv1.yaml": `
121type: metrics_view
122version: 1
123model: m1
124dimensions:
125- column: country
126measures:
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": `
142version: 1
143type: model
144sql: SELECT 'CA' AS country
145change_mode: reset
146incremental: 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

Callers

nothing calls this directly

Calls 9

NewInstanceFunction · 0.92
PutFilesFunction · 0.92
ReconcileParserAndWaitFunction · 0.92
RequireReconcileStateFunction · 0.92
RefreshModelAndWaitFunction · 0.92
createTableAsSelectFunction · 0.85
ControllerMethod · 0.80
GetMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected