2022-04-25 20:58:08 +02:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
// See LICENSE.txt for license information.
|
|
|
|
|
2022-07-18 19:21:57 +02:00
|
|
|
package boards
|
2021-05-24 19:06:11 +02:00
|
|
|
|
|
|
|
import (
|
2022-09-13 12:18:40 +02:00
|
|
|
"io"
|
2021-05-24 19:06:11 +02:00
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"testing"
|
|
|
|
|
2022-07-15 08:04:35 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
2022-07-18 19:21:57 +02:00
|
|
|
"github.com/mattermost/mattermost-server/v6/model"
|
|
|
|
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
|
|
|
)
|
2022-07-15 08:04:35 +02:00
|
|
|
|
2021-11-02 03:12:43 +02:00
|
|
|
func TestSetConfiguration(t *testing.T) {
|
|
|
|
boolTrue := true
|
|
|
|
stringRef := ""
|
|
|
|
|
|
|
|
baseFeatureFlags := &model.FeatureFlags{}
|
|
|
|
basePluginSettings := &model.PluginSettings{
|
|
|
|
Directory: &stringRef,
|
|
|
|
}
|
|
|
|
driverName := "testDriver"
|
|
|
|
dataSource := "testDirectory"
|
|
|
|
baseSQLSettings := &model.SqlSettings{
|
|
|
|
DriverName: &driverName,
|
|
|
|
DataSource: &dataSource,
|
|
|
|
}
|
|
|
|
|
|
|
|
directory := "testDirectory"
|
|
|
|
baseFileSettings := &model.FileSettings{
|
2022-04-20 17:01:40 +02:00
|
|
|
DriverName: &driverName,
|
|
|
|
Directory: &directory,
|
|
|
|
MaxFileSize: model.NewInt64(1024 * 1024),
|
2021-11-02 03:12:43 +02:00
|
|
|
}
|
|
|
|
|
2022-04-25 20:58:08 +02:00
|
|
|
days := 365
|
|
|
|
baseDataRetentionSettings := &model.DataRetentionSettings{
|
|
|
|
BoardsRetentionDays: &days,
|
|
|
|
}
|
2022-07-08 16:43:43 +02:00
|
|
|
usernameRef := "username"
|
|
|
|
baseTeamSettings := &model.TeamSettings{
|
|
|
|
TeammateNameDisplay: &usernameRef,
|
|
|
|
}
|
2022-04-25 20:58:08 +02:00
|
|
|
|
2021-11-02 03:12:43 +02:00
|
|
|
baseConfig := &model.Config{
|
2022-04-25 20:58:08 +02:00
|
|
|
FeatureFlags: baseFeatureFlags,
|
|
|
|
PluginSettings: *basePluginSettings,
|
|
|
|
SqlSettings: *baseSQLSettings,
|
|
|
|
FileSettings: *baseFileSettings,
|
|
|
|
DataRetentionSettings: *baseDataRetentionSettings,
|
2022-07-08 16:43:43 +02:00
|
|
|
TeamSettings: *baseTeamSettings,
|
2021-11-02 03:12:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("test enable telemetry", func(t *testing.T) {
|
|
|
|
logSettings := &model.LogSettings{
|
|
|
|
EnableDiagnostics: &boolTrue,
|
|
|
|
}
|
|
|
|
mmConfig := baseConfig
|
|
|
|
mmConfig.LogSettings = *logSettings
|
|
|
|
|
2022-07-18 19:21:57 +02:00
|
|
|
config := createBoardsConfig(*mmConfig, "", "testId")
|
2021-11-02 03:12:43 +02:00
|
|
|
assert.Equal(t, true, config.Telemetry)
|
|
|
|
assert.Equal(t, "testId", config.TelemetryID)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test enable shared boards", func(t *testing.T) {
|
|
|
|
mmConfig := baseConfig
|
|
|
|
mmConfig.PluginSettings.Plugins = make(map[string]map[string]interface{})
|
2022-07-18 19:21:57 +02:00
|
|
|
mmConfig.PluginSettings.Plugins[PluginName] = make(map[string]interface{})
|
|
|
|
mmConfig.PluginSettings.Plugins[PluginName][SharedBoardsName] = true
|
|
|
|
config := createBoardsConfig(*mmConfig, "", "")
|
2021-11-02 03:12:43 +02:00
|
|
|
assert.Equal(t, true, config.EnablePublicSharedBoards)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test boards feature flags", func(t *testing.T) {
|
|
|
|
featureFlags := &model.FeatureFlags{
|
|
|
|
TestFeature: "test",
|
|
|
|
TestBoolFeature: boolTrue,
|
|
|
|
BoardsFeatureFlags: "hello_world-myTest",
|
|
|
|
}
|
|
|
|
|
|
|
|
mmConfig := baseConfig
|
|
|
|
mmConfig.FeatureFlags = featureFlags
|
|
|
|
|
2022-07-18 19:21:57 +02:00
|
|
|
config := createBoardsConfig(*mmConfig, "", "")
|
2021-11-02 03:12:43 +02:00
|
|
|
assert.Equal(t, "true", config.FeatureFlags["TestBoolFeature"])
|
|
|
|
assert.Equal(t, "test", config.FeatureFlags["TestFeature"])
|
|
|
|
|
|
|
|
assert.Equal(t, "true", config.FeatureFlags["hello_world"])
|
|
|
|
assert.Equal(t, "true", config.FeatureFlags["myTest"])
|
|
|
|
})
|
|
|
|
}
|
2022-07-18 19:21:57 +02:00
|
|
|
|
|
|
|
func TestServeHTTP(t *testing.T) {
|
|
|
|
th, tearDown := SetupTestHelper(t)
|
|
|
|
defer tearDown()
|
|
|
|
|
|
|
|
b := &BoardsApp{
|
|
|
|
server: th.Server,
|
|
|
|
logger: mlog.CreateConsoleTestLogger(true, mlog.LvlError),
|
|
|
|
}
|
|
|
|
|
|
|
|
assert := assert.New(t)
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
r := httptest.NewRequest(http.MethodGet, "/hello", nil)
|
|
|
|
|
|
|
|
b.ServeHTTP(nil, w, r)
|
|
|
|
|
|
|
|
result := w.Result()
|
|
|
|
assert.NotNil(result)
|
|
|
|
defer result.Body.Close()
|
2022-09-13 12:18:40 +02:00
|
|
|
bodyBytes, err := io.ReadAll(result.Body)
|
2022-07-18 19:21:57 +02:00
|
|
|
assert.Nil(err)
|
|
|
|
bodyString := string(bodyBytes)
|
|
|
|
|
|
|
|
assert.Equal("Hello", bodyString)
|
|
|
|
}
|