Skip to content

Commit

Permalink
plugins: Add an echo plugin for testing the plugin mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
dlespiau committed Oct 27, 2019
1 parent 7b84539 commit 13698c6
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
41 changes: 41 additions & 0 deletions plugins/jk-plugin-echo/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package main

import (
"os"

"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-plugin"

"github.com/jkcfg/jk/pkg/plugin/renderer"
)

// Echo outputs its input.
type Echo struct {
log hclog.Logger
}

// Render implements renderer.Renderer.
func (h *Echo) Render(input []byte) ([]byte, error) {
h.log.Debug("debug message from echo plugin")
return input, nil
}

func main() {
logger := hclog.New(&hclog.LoggerOptions{
Level: hclog.Info,
Output: os.Stderr,
})

r := &Echo{
log: logger,
}
// pluginMap is the map of plugins we can dispense.
var pluginMap = map[string]plugin.Plugin{
"renderer": &renderer.Plugin{Impl: r},
}

plugin.Serve(&plugin.ServeConfig{
HandshakeConfig: renderer.RendererV1,
Plugins: pluginMap,
})
}
7 changes: 7 additions & 0 deletions tests/echo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "echo",
"version": "0.1.0",
"binaries": {
"linux-amd64": "jk-plugin-echo"
}
}
4 changes: 4 additions & 0 deletions tests/test-plugin-echo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import * as std from '@jkcfg/std';
import { render } from '@jkcfg/std/render';

render('echo.json', { message: 'success' }).then(r => std.log(r.message));
1 change: 1 addition & 0 deletions tests/test-plugin-echo.js.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
success

0 comments on commit 13698c6

Please sign in to comment.