Skip to content

Commit

Permalink
added test cover {{ .URL }} after grafana#80858 (review)
Browse files Browse the repository at this point in the history
  • Loading branch information
Slach committed Feb 1, 2024
1 parent e701b71 commit 43eea5a
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions pkg/api/pluginproxy/ds_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,36 @@ func TestDataSourceProxy_routeRule(t *testing.T) {
assert.Equal(t, "http://localhost/asd", req.URL.String())
})

t.Run("When matching route path and has setting url", func(t *testing.T) {
ctx, req := setUp()
proxy, err := setupDSProxyTest(t, ctx, ds, routes, "api/common/some/method")
require.NoError(t, err)
proxy.matchedRoute = &plugins.Route{
Path: "api/common",
URL: "{{.URL}}",
Headers: []plugins.Header{
{Name: "x-header", Content: "my secret {{.SecureJsonData.key}}"},
},
URLParams: []plugins.URLParam{
{Name: "{{.JsonData.queryParam}}", Content: "{{.SecureJsonData.key}}"},
},
}

dsInfo := DSInfo{
ID: ds.ID,
Updated: ds.Updated,
JSONData: jd,
DecryptedSecureJSONData: map[string]string{
"key": "123",
},
URL: "https://dynamic.grafana.com",
}
ApplyRoute(proxy.ctx.Req.Context(), req, proxy.proxyPath, proxy.matchedRoute, dsInfo, proxy.cfg)

assert.Equal(t, "https://dynamic.grafana.com/some/method?apiKey=123", req.URL.String())
assert.Equal(t, "my secret 123", req.Header.Get("x-header"))
})

t.Run("When matching route path and has dynamic body", func(t *testing.T) {
ctx, req := setUp()
proxy, err := setupDSProxyTest(t, ctx, ds, routes, "api/body")
Expand Down

0 comments on commit 43eea5a

Please sign in to comment.