mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
* WIP: Spawn backend plugins v2 * Add test for plugin version * Fix support for SDK plugins Co-authored-by: Kyle Brandt <kyle@kbrandt.com> Co-authored-by: Marcus Olsson <olsson.e.marcus@gmail.com> Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com> * WIP: Draft PR for fork of V2 sdk / bi-directional support (#19890) * temporary use export-datasource-plugin branch of grafana-plugin-sdk * fix failing test * remove debug (spew) lines * misc cleanup * add expressions feature toggle * use latest grafana-plugin-sdk-go
35 lines
1.2 KiB
Go
35 lines
1.2 KiB
Go
package plugins
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestLoadDatasourceVersion(t *testing.T) {
|
|
t.Run("If plugin version is not set, it should be treated as plugin version one", func(t *testing.T) {
|
|
pluginJSON, _ := json.Marshal(DataSourcePlugin{})
|
|
datasourcePlugin := DataSourcePlugin{}
|
|
(&datasourcePlugin).Load(json.NewDecoder(bytes.NewReader(pluginJSON)), "/tmp")
|
|
assert.True(t, datasourcePlugin.isVersionOne())
|
|
})
|
|
|
|
t.Run("If plugin version is set to one, it should be treated as plugin version one", func(t *testing.T) {
|
|
pluginJSON, _ := json.Marshal(DataSourcePlugin{SDK: false})
|
|
datasourcePlugin := DataSourcePlugin{}
|
|
(&datasourcePlugin).Load(json.NewDecoder(bytes.NewReader(pluginJSON)), "/tmp")
|
|
assert.True(t, datasourcePlugin.isVersionOne())
|
|
assert.False(t, datasourcePlugin.SDK)
|
|
})
|
|
|
|
t.Run("If plugin version is set to two, it should not be treated as plugin version one", func(t *testing.T) {
|
|
pluginJSON, _ := json.Marshal(DataSourcePlugin{SDK: true})
|
|
datasourcePlugin := DataSourcePlugin{}
|
|
(&datasourcePlugin).Load(json.NewDecoder(bytes.NewReader(pluginJSON)), "/tmp")
|
|
assert.False(t, datasourcePlugin.isVersionOne())
|
|
assert.True(t, datasourcePlugin.SDK)
|
|
})
|
|
}
|