From f80d50adbddf55a043dfcab5b47d7c1e22749b7d Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 16 Aug 2017 17:23:38 -0500 Subject: PLT-7407: Back-end plugin mechanism (#7177) * begin backend plugin wip * flesh out rpcplugin. everything done except for minor supervisor stubs * done with basic plugin infrastructure * simplify tests * remove unused test lines --- plugin/rpcplugin/api_test.go | 57 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 plugin/rpcplugin/api_test.go (limited to 'plugin/rpcplugin/api_test.go') diff --git a/plugin/rpcplugin/api_test.go b/plugin/rpcplugin/api_test.go new file mode 100644 index 000000000..e55433556 --- /dev/null +++ b/plugin/rpcplugin/api_test.go @@ -0,0 +1,57 @@ +package rpcplugin + +import ( + "encoding/json" + "io" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" + + "github.com/mattermost/platform/plugin" + "github.com/mattermost/platform/plugin/plugintest" +) + +func testAPIRPC(api plugin.API, f func(plugin.API)) { + r1, w1 := io.Pipe() + r2, w2 := io.Pipe() + + c1 := NewMuxer(NewReadWriteCloser(r1, w2), false) + defer c1.Close() + + c2 := NewMuxer(NewReadWriteCloser(r2, w1), true) + defer c2.Close() + + id, server := c1.Serve() + go ServeAPI(api, server, c1) + + remote := ConnectAPI(c2.Connect(id), c2) + defer remote.Close() + + f(remote) +} + +func TestAPI(t *testing.T) { + var api plugintest.API + defer api.AssertExpectations(t) + + type Config struct { + Foo string + Bar struct { + Baz string + } + } + + api.On("LoadPluginConfiguration", mock.MatchedBy(func(x interface{}) bool { return true })).Run(func(args mock.Arguments) { + dest := args.Get(0).(interface{}) + json.Unmarshal([]byte(`{"Foo": "foo", "Bar": {"Baz": "baz"}}`), dest) + }).Return(nil) + + testAPIRPC(&api, func(remote plugin.API) { + var config Config + assert.NoError(t, remote.LoadPluginConfiguration(&config)) + + assert.Equal(t, "foo", config.Foo) + assert.Equal(t, "baz", config.Bar.Baz) + }) +} -- cgit v1.2.3-1-g7c22