77
88 "github.com/grafana/grafana-plugin-sdk-go/backend"
99 "github.com/grafana/grafana-plugin-sdk-go/backend/instancemgmt"
10+ "github.com/grafana/grafana-plugin-sdk-go/backend/proxy"
1011 "github.com/stretchr/testify/require"
1112)
1213
@@ -30,7 +31,43 @@ func TestInstanceProvider(t *testing.T) {
3031 },
3132 })
3233 require .NoError (t , err )
33- require .Equal (t , int64 (4 ), key )
34+ require .Equal (t , "4##" , key )
35+ })
36+
37+ t .Run ("When PDC is configured, datasource cache key should include its (so-called) hash" , func (t * testing.T ) {
38+ cfg := backend .NewGrafanaCfg (map [string ]string {
39+ proxy .PluginSecureSocksProxyClientKeyContents : "This should work" ,
40+ })
41+ key , err := ip .GetKey (context .Background (), backend.PluginContext {
42+ DataSourceInstanceSettings : & backend.DataSourceInstanceSettings {ID : 5 },
43+ GrafanaConfig : cfg ,
44+ })
45+ require .NoError (t , err )
46+ require .Equal (t , "5##work" , key )
47+ })
48+
49+ t .Run ("When PDC is configured but the key is empty, no problem" , func (t * testing.T ) {
50+ cfg := backend .NewGrafanaCfg (map [string ]string {
51+ proxy .PluginSecureSocksProxyClientKeyContents : "" ,
52+ })
53+ key , err := ip .GetKey (context .Background (), backend.PluginContext {
54+ DataSourceInstanceSettings : & backend.DataSourceInstanceSettings {ID : 6 },
55+ GrafanaConfig : cfg ,
56+ })
57+ require .NoError (t , err )
58+ require .Equal (t , "6##" , key )
59+ })
60+
61+ t .Run ("When PDC is configured, a too-short key doesn't cause an error" , func (t * testing.T ) {
62+ cfg := backend .NewGrafanaCfg (map [string ]string {
63+ proxy .PluginSecureSocksProxyClientKeyContents : "doh" ,
64+ })
65+ key , err := ip .GetKey (context .Background (), backend.PluginContext {
66+ DataSourceInstanceSettings : & backend.DataSourceInstanceSettings {ID : 7 },
67+ GrafanaConfig : cfg ,
68+ })
69+ require .NoError (t , err )
70+ require .Equal (t , "7##doh" , key )
3471 })
3572
3673 t .Run ("When both the configuration and updated field of current data source instance settings are equal to the cache, should return false" , func (t * testing.T ) {
0 commit comments