MCPcopy Index your code
hub / github.com/rilldata/rill / TestTemplateSQLApi

Function TestTemplateSQLApi

runtime/resolvers/sql_test.go:122–152  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

120}
121
122func TestTemplateSQLApi(t *testing.T) {
123 rt, instanceID := testruntime.NewInstanceForProject(t, "ad_bids")
124
125 api, err := rt.APIForName(context.Background(), instanceID, "templated_sql_api")
126 require.NoError(t, err)
127
128 res, _, err := rt.Resolve(context.Background(), &runtime.ResolveOptions{
129 InstanceID: instanceID,
130 Resolver: api.Spec.Resolver,
131 ResolverProperties: api.Spec.ResolverProperties.AsMap(),
132 Args: map[string]any{"domain": "sports.yahoo.com"},
133 Claims: &runtime.SecurityClaims{},
134 })
135 require.NoError(t, err)
136 defer res.Close()
137
138 require.NotNil(t, res)
139
140 var rows []map[string]interface{}
141 require.NoError(t, json.Unmarshal(must(res.MarshalJSON()), &rows))
142 require.Equal(t, 5, len(rows))
143 require.Equal(t, 5, len(rows[0]))
144 require.Equal(t, 1.81, rows[0]["bid_price"])
145 require.Equal(t, "sports.yahoo.com", rows[0]["domain"])
146 require.Equal(t, float64(9000), rows[0]["id"])
147 require.Equal(t, "Yahoo", rows[0]["publisher"])
148 require.Equal(t, "2022-02-09T11:58:12.475Z", rows[0]["timestamp"])
149 for _, row := range rows {
150 require.Equal(t, "sports.yahoo.com", row["domain"])
151 }
152}
153
154func TestTemplateSQLApi2(t *testing.T) {
155 rt, instanceID := testruntime.NewInstanceForProject(t, "ad_bids")

Callers

nothing calls this directly

Calls 7

NewInstanceForProjectFunction · 0.92
APIForNameMethod · 0.80
mustFunction · 0.70
ResolveMethod · 0.65
CloseMethod · 0.65
MarshalJSONMethod · 0.65
AsMapMethod · 0.45

Tested by

no test coverage detected