1
0
mirror of https://github.com/mattermost/focalboard.git synced 2024-11-27 08:31:20 +02:00

Include plugin unit tests in CI via makefile; fix unit tests (#2848)

* include plugin unit tests in CI via makefile; fix unit tests

* include hello endpoint for unit test and web service up check
This commit is contained in:
Doug Lauder 2022-04-20 11:01:40 -04:00 committed by GitHub
parent 979807a3b6
commit 99882bf197
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 65 additions and 24 deletions

View File

@ -134,6 +134,7 @@ server-test-mysql: templates-archive ## Run server tests using mysql
docker-compose -f ./docker-testing/docker-compose-mysql.yml down -v --remove-orphans
docker-compose -f ./docker-testing/docker-compose-mysql.yml run start_dependencies
cd server; go test -tags '$(BUILD_TAGS)' -race -v -count=1 -timeout=30m ./...
cd mattermost-plugin/server; go test -tags '$(BUILD_TAGS)' -race -v -count=1 -timeout=30m ./...
docker-compose -f ./docker-testing/docker-compose-mysql.yml down -v --remove-orphans
server-test-postgres: export FB_UNIT_TESTING=1
@ -145,6 +146,7 @@ server-test-postgres: templates-archive ## Run server tests using postgres
docker-compose -f ./docker-testing/docker-compose-postgres.yml down -v --remove-orphans
docker-compose -f ./docker-testing/docker-compose-postgres.yml run start_dependencies
cd server; go test -tags '$(BUILD_TAGS)' -race -v -count=1 -timeout=30m ./...
cd mattermost-plugin/server; go test -tags '$(BUILD_TAGS)' -race -v -count=1 -timeout=30m ./...
docker-compose -f ./docker-testing/docker-compose-postgres.yml down -v --remove-orphans
webapp: ## Build webapp.

View File

@ -3,35 +3,38 @@ package main
import (
"testing"
"github.com/mattermost/focalboard/server/integrationtests"
"github.com/mattermost/focalboard/server/model"
"github.com/mattermost/focalboard/server/server"
"github.com/mattermost/focalboard/server/services/config"
"github.com/mattermost/focalboard/server/ws"
serverModel "github.com/mattermost/mattermost-server/v6/model"
"github.com/mattermost/mattermost-server/v6/plugin/plugintest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
type TestHelper struct {
Server *server.Server
}
func SetupTestHelper() *TestHelper {
func SetupTestHelper(t *testing.T) (*TestHelper, func()) {
th := &TestHelper{}
th.Server = newTestServer()
return th
err := th.Server.Start()
require.NoError(t, err, "Server start should not error")
tearDown := func() {
err := th.Server.Shutdown()
require.NoError(t, err, "Server shutdown should not error")
}
return th, tearDown
}
func newTestServer() *server.Server {
srv, err := server.New(server.Params{
Cfg: &config.Configuration{},
})
if err != nil {
panic(err)
}
return srv
return integrationtests.NewTestServerPluginMode()
}
func TestConfigurationNullConfiguration(t *testing.T) {
@ -60,9 +63,11 @@ func TestOnConfigurationChange(t *testing.T) {
}
t.Run("Test Load Plugin Success", func(t *testing.T) {
th := SetupTestHelper()
th, tearDown := SetupTestHelper(t)
defer tearDown()
api := &plugintest.API{}
api.On("GetUnsanitizedConfig").Return(baseConfig)
api.On("GetConfig").Return(baseConfig)
p := Plugin{}
p.SetAPI(api)

View File

@ -6,15 +6,21 @@ import (
"net/http/httptest"
"testing"
"github.com/mattermost/mattermost-server/v6/model"
"github.com/stretchr/testify/assert"
"github.com/mattermost/mattermost-server/v6/model"
)
func TestServeHTTP(t *testing.T) {
th, tearDown := SetupTestHelper(t)
defer tearDown()
assert := assert.New(t)
plugin := Plugin{}
plugin := Plugin{
server: th.Server,
}
w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodGet, "/", nil)
r := httptest.NewRequest(http.MethodGet, "/hello", nil)
plugin.ServeHTTP(nil, w, r)
@ -25,11 +31,16 @@ func TestServeHTTP(t *testing.T) {
assert.Nil(err)
bodyString := string(bodyBytes)
assert.Equal("Hello, world!", bodyString)
assert.Equal("Hello", bodyString)
}
func TestSetConfiguration(t *testing.T) {
plugin := Plugin{}
th, tearDown := SetupTestHelper(t)
defer tearDown()
plugin := Plugin{
server: th.Server,
}
boolTrue := true
stringRef := ""
@ -46,8 +57,9 @@ func TestSetConfiguration(t *testing.T) {
directory := "testDirectory"
baseFileSettings := &model.FileSettings{
DriverName: &driverName,
Directory: &directory,
DriverName: &driverName,
Directory: &directory,
MaxFileSize: model.NewInt64(1024 * 1024),
}
baseConfig := &model.Config{

View File

@ -141,17 +141,20 @@ func (a *API) RegisterRoutes(r *mux.Router) {
// Get Files API
apiv2.HandleFunc("/files/teams/{teamID}/{boardID}/{filename}", a.attachSession(a.handleServeFile, false)).Methods("GET")
// Subscriptions
// Subscription APIs
apiv2.HandleFunc("/subscriptions", a.sessionRequired(a.handleCreateSubscription)).Methods("POST")
apiv2.HandleFunc("/subscriptions/{blockID}/{subscriberID}", a.sessionRequired(a.handleDeleteSubscription)).Methods("DELETE")
apiv2.HandleFunc("/subscriptions/{subscriberID}", a.sessionRequired(a.handleGetSubscriptions)).Methods("GET")
// onboarding tour endpoints
// Onboarding tour endpoints APIs
apiv2.HandleFunc("/teams/{teamID}/onboard", a.sessionRequired(a.handleOnboard)).Methods(http.MethodPost)
// archives
// Archive APIs
apiv2.HandleFunc("/boards/{boardID}/archive/export", a.sessionRequired(a.handleArchiveExportBoard)).Methods("GET")
apiv2.HandleFunc("/teams/{teamID}/archive/import", a.sessionRequired(a.handleArchiveImport)).Methods("POST")
// System APIs
r.HandleFunc("/hello", a.handleHello).Methods("GET")
}
func (a *API) RegisterAdminRoutes(r *mux.Router) {
@ -4111,6 +4114,20 @@ func (a *API) handleDeleteBoardsAndBlocks(w http.ResponseWriter, r *http.Request
auditRec.Success()
}
func (a *API) handleHello(w http.ResponseWriter, r *http.Request) {
// swagger:operation GET /hello hello
//
// Responds with `Hello` if the web service is running.
//
// ---
// produces:
// - text/plain
// responses:
// '200':
// description: success
stringResponse(w, "Hello")
}
// Response helpers
func (a *API) errorResponse(w http.ResponseWriter, api string, code int, message string, sourceError error) {
@ -4139,6 +4156,11 @@ func (a *API) errorResponse(w http.ResponseWriter, api string, code int, message
_, _ = w.Write(data)
}
func stringResponse(w http.ResponseWriter, message string) {
w.Header().Set("Content-Type", "text/plain")
_, _ = fmt.Fprint(w, message)
}
func jsonStringResponse(w http.ResponseWriter, code int, message string) { //nolint:unparam
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(code)

View File

@ -171,7 +171,7 @@ func newTestServerWithLicense(singleUserToken string, licenseType LicenseType) *
return srv
}
func newTestServerPluginMode() *server.Server {
func NewTestServerPluginMode() *server.Server {
cfg, err := getTestConfig()
if err != nil {
panic(err)
@ -259,7 +259,7 @@ func SetupTestHelper(t *testing.T) *TestHelper {
func SetupTestHelperPluginMode(t *testing.T) *TestHelper {
th := &TestHelper{T: t}
th.Server = newTestServerPluginMode()
th.Server = NewTestServerPluginMode()
th.Start()
return th
}