summaryrefslogtreecommitdiffstats
path: root/app/server_test.go
blob: de358b9767081aaa924df02db03fe66e41e127ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

package app

import (
	"testing"

	"github.com/mattermost/mattermost-server/model"
	"github.com/stretchr/testify/require"
)

func TestStartServerSuccess(t *testing.T) {
	a, err := New()
	require.NoError(t, err)

	a.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ListenAddress = ":0" })
	serverErr := a.StartServer()
	a.Shutdown()
	require.NoError(t, serverErr)
}

func TestStartServerRateLimiterCriticalError(t *testing.T) {
	a, err := New()
	require.NoError(t, err)

	// Attempt to use Rate Limiter with an invalid config
	a.UpdateConfig(func(cfg *model.Config) {
		*cfg.RateLimitSettings.Enable   = true
		*cfg.RateLimitSettings.MaxBurst = -100
	})

	serverErr := a.StartServer()
	a.Shutdown()
	require.Error(t, serverErr)
}

func TestStartServerPortUnavailable(t *testing.T) {
	a, err := New()
	require.NoError(t, err)

	// Attempt to listen on a system-reserved port
	a.UpdateConfig(func(cfg *model.Config) {
		*cfg.ServiceSettings.ListenAddress = ":21"
	})

	serverErr := a.StartServer()
	a.Shutdown()
	require.Error(t, serverErr)
}