PLT-7407: Back-end plugins (#7409)
* 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
Этот коммит содержится в:
@@ -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
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user