* tie back-end plugins together

* fix comment typo

* add tests and a bit of polish

* tests and polish

* add test, don't let backend executable paths escape the plugin directory
Этот коммит содержится в:
Chris
2017-09-11 10:02:02 -05:00
коммит произвёл GitHub
родитель a69bed712d
Коммит 402491b7e5
19 изменённых файлов: 655 добавлений и 152 удалений

Просмотреть файл

@@ -6,10 +6,12 @@ import (
"net/http"
"net/http/httptest"
"strings"
"sync"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost-server/plugin"
"github.com/mattermost/mattermost-server/plugin/plugintest"
@@ -50,6 +52,9 @@ func TestHooks(t *testing.T) {
hooks.On("OnDeactivate").Return(nil)
assert.NoError(t, remote.OnDeactivate())
hooks.On("OnConfigurationChange").Return(nil)
assert.NoError(t, remote.OnConfigurationChange())
hooks.On("ServeHTTP", mock.AnythingOfType("*rpcplugin.RemoteHTTPResponseWriter"), mock.AnythingOfType("*http.Request")).Run(func(args mock.Arguments) {
w := args.Get(0).(http.ResponseWriter)
r := args.Get(1).(*http.Request)
@@ -77,6 +82,45 @@ func TestHooks(t *testing.T) {
}))
}
func TestHooks_Concurrency(t *testing.T) {
var hooks plugintest.Hooks
defer hooks.AssertExpectations(t)
assert.NoError(t, testHooksRPC(&hooks, func(remote *RemoteHooks) {
ch := make(chan bool)
hooks.On("ServeHTTP", mock.AnythingOfType("*rpcplugin.RemoteHTTPResponseWriter"), mock.AnythingOfType("*http.Request")).Run(func(args mock.Arguments) {
r := args.Get(1).(*http.Request)
if r.URL.Path == "/1" {
<-ch
} else {
ch <- true
}
})
rec := httptest.NewRecorder()
wg := sync.WaitGroup{}
wg.Add(2)
go func() {
req, err := http.NewRequest("GET", "/1", nil)
require.NoError(t, err)
remote.ServeHTTP(rec, req)
wg.Done()
}()
go func() {
req, err := http.NewRequest("GET", "/2", nil)
require.NoError(t, err)
remote.ServeHTTP(rec, req)
wg.Done()
}()
wg.Wait()
}))
}
type testHooks struct {
mock.Mock
}