github.com/gigforks/mattermost-server@v4.9.1-0.20180619094218-800d97fa55d0+incompatible/app/server_test.go (about)

     1  // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package app
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/mattermost/mattermost-server/model"
    10  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  func TestStartServerSuccess(t *testing.T) {
    14  	a, err := New()
    15  	require.NoError(t, err)
    16  
    17  	a.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ListenAddress = ":0" })
    18  	serverErr := a.StartServer()
    19  	a.Shutdown()
    20  	require.NoError(t, serverErr)
    21  }
    22  
    23  func TestStartServerRateLimiterCriticalError(t *testing.T) {
    24  	a, err := New()
    25  	require.NoError(t, err)
    26  
    27  	// Attempt to use Rate Limiter with an invalid config
    28  	a.UpdateConfig(func(cfg *model.Config) {
    29  		*cfg.RateLimitSettings.Enable = true
    30  		*cfg.RateLimitSettings.MaxBurst = -100
    31  	})
    32  
    33  	serverErr := a.StartServer()
    34  	a.Shutdown()
    35  	require.Error(t, serverErr)
    36  }
    37  
    38  func TestStartServerPortUnavailable(t *testing.T) {
    39  	a, err := New()
    40  	require.NoError(t, err)
    41  
    42  	// Attempt to listen on a system-reserved port
    43  	a.UpdateConfig(func(cfg *model.Config) {
    44  		*cfg.ServiceSettings.ListenAddress = ":21"
    45  	})
    46  
    47  	serverErr := a.StartServer()
    48  	a.Shutdown()
    49  	require.Error(t, serverErr)
    50  }