test for plugin path builder

This commit is contained in:
Carl Bergquist 2017-12-20 16:33:53 +01:00
parent 20284f7745
commit d2ea5415da
2 changed files with 17 additions and 1 deletions

View File

@ -64,10 +64,14 @@ var handshakeConfig = plugin.HandshakeConfig{
MagicCookieValue: "55d2200a-6492-493a-9353-73b728d468aa",
}
func buildExecutablePath(pluginDir, executable, os, arch string) string {
return path.Join(pluginDir, fmt.Sprintf("%s_%s_%s", executable, strings.ToLower(os), strings.ToLower(arch)))
}
func (p *DataSourcePlugin) initBackendPlugin(log log.Logger) error {
p.log = log.New("plugin-id", p.Id)
cmd := path.Join(p.PluginDir, fmt.Sprintf("%s_%s_%s", p.Executable, strings.ToLower(runtime.GOOS), strings.ToLower(runtime.GOARCH)))
cmd := buildExecutablePath(p.PluginDir, p.Executable, runtime.GOOS, runtime.GOARCH)
p.client = plugin.NewClient(&plugin.ClientConfig{
HandshakeConfig: handshakeConfig,

View File

@ -0,0 +1,12 @@
package plugins
import "testing"
func TestExecutablePathBuilder(t *testing.T) {
have := buildExecutablePath("/var/grafana/plugins/grafana-simple-json-datasource", "simple-json", "linux", "amd64")
want := `/var/grafana/plugins/grafana-simple-json-datasource/simple-json_linux_amd64`
if have != want {
t.Errorf("expected %s got %s", want, have)
}
}