Skip to content

Commit

Permalink
Plugins: Skips existence of module.js for renderer plugins (grafana#1…
Browse files Browse the repository at this point in the history
…9318)

* Fix: Skips test for module.js for plugins of renderer type
Fixes grafana#19130

* Refactor: Changes after PR comments

* Chore: Fixes go lint issue
  • Loading branch information
hugohaggmark authored Sep 24, 2019
1 parent 4c1bc59 commit 75dcaec
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/plugins/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func (scanner *PluginScanner) loadPluginJson(pluginJsonFilePath string) error {
loader = reflect.New(reflect.TypeOf(pluginGoType)).Interface().(PluginLoader)

// External plugins need a module.js file for SystemJS to load
if !strings.HasPrefix(pluginJsonFilePath, setting.StaticRootPath) {
if !strings.HasPrefix(pluginJsonFilePath, setting.StaticRootPath) && !scanner.IsBackendOnlyPlugin(pluginCommon.Type) {
module := filepath.Join(filepath.Dir(pluginJsonFilePath), "module.js")
if _, err := os.Stat(module); os.IsNotExist(err) {
plog.Warn("Plugin missing module.js",
Expand All @@ -231,6 +231,10 @@ func (scanner *PluginScanner) loadPluginJson(pluginJsonFilePath string) error {
return loader.Load(jsonParser, currentDir)
}

func (scanner *PluginScanner) IsBackendOnlyPlugin(pluginType string) bool {
return pluginType == "renderer"
}

func GetPluginMarkdown(pluginId string, name string) ([]byte, error) {
plug, exists := Plugins[pluginId]
if !exists {
Expand Down
14 changes: 14 additions & 0 deletions pkg/plugins/plugins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,18 @@ func TestPluginScans(t *testing.T) {
So(Apps["test-app"].Info.Screenshots[1].Path, ShouldEqual, "public/plugins/test-app/img/screenshot2.png")
})

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)
})

}

0 comments on commit 75dcaec

Please sign in to comment.