2022-04-25 20:58:08 +02:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
// See LICENSE.txt for license information.
|
|
|
|
|
2021-05-24 19:06:11 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"testing"
|
|
|
|
|
2022-04-20 17:01:40 +02:00
|
|
|
"github.com/mattermost/mattermost-server/v6/model"
|
2022-04-25 20:58:08 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
2021-05-24 19:06:11 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestServeHTTP(t *testing.T) {
|
2022-04-20 17:01:40 +02:00
|
|
|
th, tearDown := SetupTestHelper(t)
|
|
|
|
defer tearDown()
|
|
|
|
|
2021-05-24 19:06:11 +02:00
|
|
|
assert := assert.New(t)
|
2022-04-20 17:01:40 +02:00
|
|
|
plugin := Plugin{
|
|
|
|
server: th.Server,
|
|
|
|
}
|
2021-05-24 19:06:11 +02:00
|
|
|
w := httptest.NewRecorder()
|
2022-04-20 17:01:40 +02:00
|
|
|
r := httptest.NewRequest(http.MethodGet, "/hello", nil)
|
2021-05-24 19:06:11 +02:00
|
|
|
|
|
|
|
plugin.ServeHTTP(nil, w, r)
|
|
|
|
|
|
|
|
result := w.Result()
|
|
|
|
assert.NotNil(result)
|
|
|
|
defer result.Body.Close()
|
|
|
|
bodyBytes, err := ioutil.ReadAll(result.Body)
|
|
|
|
assert.Nil(err)
|
|
|
|
bodyString := string(bodyBytes)
|
|
|
|
|
2022-04-20 17:01:40 +02:00
|
|
|
assert.Equal("Hello", bodyString)
|
2021-05-24 19:06:11 +02:00
|
|
|
}
|
2021-11-02 02:12:43 +01:00
|
|
|
|
|
|
|
func TestSetConfiguration(t *testing.T) {
|
2022-04-20 17:01:40 +02:00
|
|
|
th, tearDown := SetupTestHelper(t)
|
|
|
|
defer tearDown()
|
|
|
|
|
|
|
|
plugin := Plugin{
|
|
|
|
server: th.Server,
|
|
|
|
}
|
2021-11-02 02:12:43 +01:00
|
|
|
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 02:12:43 +01: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 02:12:43 +01: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 02:12:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("test enable telemetry", func(t *testing.T) {
|
|
|
|
logSettings := &model.LogSettings{
|
|
|
|
EnableDiagnostics: &boolTrue,
|
|
|
|
}
|
|
|
|
mmConfig := baseConfig
|
|
|
|
mmConfig.LogSettings = *logSettings
|
|
|
|
|
|
|
|
config := plugin.createBoardsConfig(*mmConfig, "", "testId")
|
|
|
|
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{})
|
|
|
|
mmConfig.PluginSettings.Plugins[pluginName] = make(map[string]interface{})
|
|
|
|
mmConfig.PluginSettings.Plugins[pluginName][sharedBoardsName] = true
|
|
|
|
config := plugin.createBoardsConfig(*mmConfig, "", "")
|
|
|
|
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
|
|
|
|
|
|
|
|
config := plugin.createBoardsConfig(*mmConfig, "", "")
|
|
|
|
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"])
|
|
|
|
})
|
|
|
|
}
|