2015-02-27 13:45:00 +01:00
|
|
|
package plugins
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"testing"
|
|
|
|
|
|
2015-11-27 17:04:43 +08:00
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
2015-02-27 13:45:00 +01:00
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
2015-11-27 17:17:27 +08:00
|
|
|
"gopkg.in/ini.v1"
|
2015-02-27 13:45:00 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestPluginScans(t *testing.T) {
|
|
|
|
|
|
2018-04-13 18:40:14 +02:00
|
|
|
Convey("When scanning for plugins", t, func() {
|
2015-11-27 17:17:27 +08:00
|
|
|
setting.StaticRootPath, _ = filepath.Abs("../../public/")
|
2018-04-30 16:21:04 +02:00
|
|
|
setting.Raw = ini.Empty()
|
2018-04-27 15:11:55 +02:00
|
|
|
|
|
|
|
|
pm := &PluginManager{}
|
|
|
|
|
err := pm.Init()
|
2015-02-27 13:45:00 +01:00
|
|
|
|
|
|
|
|
So(err, ShouldBeNil)
|
2015-02-28 11:38:44 +01:00
|
|
|
So(len(DataSources), ShouldBeGreaterThan, 1)
|
2016-01-08 20:57:58 +01:00
|
|
|
So(len(Panels), ShouldBeGreaterThan, 1)
|
2016-01-09 23:34:20 +01:00
|
|
|
|
|
|
|
|
Convey("Should set module automatically", func() {
|
|
|
|
|
So(DataSources["graphite"].Module, ShouldEqual, "app/plugins/datasource/graphite/module")
|
|
|
|
|
})
|
2015-02-27 13:45:00 +01:00
|
|
|
})
|
2016-01-08 20:57:58 +01:00
|
|
|
|
|
|
|
|
Convey("When reading app plugin definition", t, func() {
|
2018-04-30 16:21:04 +02:00
|
|
|
setting.Raw = ini.Empty()
|
2019-10-11 21:02:15 +02:00
|
|
|
sec, err := setting.Raw.NewSection("plugin.nginx-app")
|
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
_, err = sec.NewKey("path", "testdata/test-app")
|
|
|
|
|
So(err, ShouldBeNil)
|
2018-04-27 15:11:55 +02:00
|
|
|
|
|
|
|
|
pm := &PluginManager{}
|
2019-10-11 21:02:15 +02:00
|
|
|
err = pm.Init()
|
2016-01-08 20:57:58 +01:00
|
|
|
So(err, ShouldBeNil)
|
2016-03-10 19:57:48 +01:00
|
|
|
|
2019-10-11 21:02:15 +02:00
|
|
|
So(len(Apps), ShouldBeGreaterThan, 0)
|
2016-03-11 12:39:10 +01:00
|
|
|
So(Apps["test-app"].Info.Logos.Large, ShouldEqual, "public/plugins/test-app/img/logo_large.png")
|
|
|
|
|
So(Apps["test-app"].Info.Screenshots[1].Path, ShouldEqual, "public/plugins/test-app/img/screenshot2.png")
|
2016-01-08 20:57:58 +01:00
|
|
|
})
|
|
|
|
|
|
2019-09-23 22:54:28 -07:00
|
|
|
Convey("When checking if renderer is backend only plugin", t, func() {
|
|
|
|
|
pluginScanner := &PluginScanner{}
|
|
|
|
|
result := pluginScanner.IsBackendOnlyPlugin("renderer")
|
|
|
|
|
|
|
|
|
|
So(result, ShouldEqual, true)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
Convey("When checking if app is backend only plugin", t, func() {
|
|
|
|
|
pluginScanner := &PluginScanner{}
|
|
|
|
|
result := pluginScanner.IsBackendOnlyPlugin("app")
|
|
|
|
|
|
|
|
|
|
So(result, ShouldEqual, false)
|
|
|
|
|
})
|
|
|
|
|
|
2015-02-27 13:45:00 +01:00
|
|
|
}
|