1
0
mirror of https://github.com/mattermost/focalboard.git synced 2024-12-21 13:38:56 +02:00
focalboard/server/web/webserver_test.go
Rajat Dabade c8e729b6fe
[Refactor]: updated dependency for focalboard server (#5009)
* refactor: updated dependency for focalboard server

* chore: more dependency fixes

* refactor: removed the unless code

* refactor: added ctx for login and removed unnessary code

* refactor: bump up go version

* refactor: removed the commented code

* chore: upgraded golinter version

* fix: linter issue

* refactor: removed feature flg fix golinter

* refactor: removed feature flag from code

* revert: statistic and it's function

* refactor: removed ProductLimit related code

* refactor: removed isWithinViewsLimit implementation

* refactor: moved function GetUsedCardsCount to statistics.go from cloud.go

* refactor: removed insight code board

* refactor: removed limit dialog

* refactor: updated dependencies for linux

* chore: golinter fix

* chore: updated helper test function to use newLogger

* fix: go test

* refactor: db ping attempts from config

* revert: feature in action

* revert: feature flag in action

* revert: boardsEditor setting

---------

Co-authored-by: Rajat Dabade <rajat@Rajats-MacBook-Pro.local>
2024-06-07 23:30:08 +05:30

100 lines
3.2 KiB
Go

package web
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost/server/public/shared/mlog"
)
func Test_NewServer(t *testing.T) {
tests := []struct {
name string
rootPath string
serverRoot string
ssl bool
port int
localOnly bool
logger mlog.LoggerIFace
expectedBaseURL string
expectedServerAddr string
}{
{
name: "should return server with given properties",
rootPath: "./test/path/to/root",
serverRoot: "https://some-fake-server.com/fake-url",
ssl: false,
port: 9999, // fake port number
localOnly: false,
logger: &mlog.Logger{},
expectedBaseURL: "/fake-url",
expectedServerAddr: ":9999",
},
{
name: "should return local server with given properties",
rootPath: "./test/path/to/root",
serverRoot: "https://some-fake-server.com/fake-url",
ssl: false,
port: 3000, // fake port number
localOnly: true,
logger: &mlog.Logger{},
expectedBaseURL: "/fake-url",
expectedServerAddr: "localhost:3000",
},
{
name: "should match Server properties when ssl true",
rootPath: "./test/path/to/root",
serverRoot: "https://some-fake-server.com/fake-url",
ssl: true,
port: 8000, // fake port number
localOnly: false,
logger: &mlog.Logger{},
expectedBaseURL: "/fake-url",
expectedServerAddr: ":8000",
},
{
name: "should return local server when ssl true",
rootPath: "./test/path/to/root",
serverRoot: "https://localhost:8080/fake-url",
ssl: true,
port: 9999, // fake port number
localOnly: true,
logger: &mlog.Logger{},
expectedBaseURL: "/fake-url",
expectedServerAddr: "localhost:9999",
},
{
name: "should return '/' as base url is not good!",
rootPath: "",
serverRoot: "https://localhost:8080/#!@$@#@",
ssl: true,
port: 9999, // fake port number
localOnly: true,
logger: &mlog.Logger{},
expectedBaseURL: "/",
expectedServerAddr: "localhost:9999",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
ws := NewServer(test.rootPath, test.serverRoot, test.port, test.ssl, test.localOnly, test.logger)
require.NotNil(t, ws, "The webserver object is nil!")
require.Equal(t, test.expectedBaseURL, ws.baseURL, "baseURL does not match")
require.Equal(t, test.rootPath, ws.rootPath, "rootPath does not match")
require.Equal(t, test.port, ws.port, "rootPath does not match")
require.Equal(t, test.ssl, ws.ssl, "logger pointer does not match")
require.Equal(t, test.logger, ws.logger, "logger pointer does not match")
if test.localOnly == true {
require.Equal(t, test.expectedServerAddr, ws.Server.Addr, "localhost address not as matching!")
} else {
require.Equal(t, test.expectedServerAddr, ws.Server.Addr, "server address not matching!")
}
})
}
}