github.com/coincircle/mattermost-server@v4.8.1-0.20180321182714-9d701c704416+incompatible/app/config_test.go (about)

     1  // Copyright (c) 2015-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/stretchr/testify/assert"
    10  
    11  	"github.com/mattermost/mattermost-server/model"
    12  )
    13  
    14  func TestConfigListener(t *testing.T) {
    15  	th := Setup().InitBasic()
    16  	defer th.TearDown()
    17  
    18  	originalSiteName := th.App.Config().TeamSettings.SiteName
    19  	th.App.UpdateConfig(func(cfg *model.Config) {
    20  		cfg.TeamSettings.SiteName = "test123"
    21  	})
    22  
    23  	listenerCalled := false
    24  	listener := func(oldConfig *model.Config, newConfig *model.Config) {
    25  		if listenerCalled {
    26  			t.Fatal("listener called twice")
    27  		}
    28  
    29  		if oldConfig.TeamSettings.SiteName != "test123" {
    30  			t.Fatal("old config contains incorrect site name")
    31  		} else if newConfig.TeamSettings.SiteName != originalSiteName {
    32  			t.Fatal("new config contains incorrect site name")
    33  		}
    34  
    35  		listenerCalled = true
    36  	}
    37  	listenerId := th.App.AddConfigListener(listener)
    38  	defer th.App.RemoveConfigListener(listenerId)
    39  
    40  	listener2Called := false
    41  	listener2 := func(oldConfig *model.Config, newConfig *model.Config) {
    42  		if listener2Called {
    43  			t.Fatal("listener2 called twice")
    44  		}
    45  
    46  		listener2Called = true
    47  	}
    48  	listener2Id := th.App.AddConfigListener(listener2)
    49  	defer th.App.RemoveConfigListener(listener2Id)
    50  
    51  	th.App.ReloadConfig()
    52  
    53  	if !listenerCalled {
    54  		t.Fatal("listener should've been called")
    55  	} else if !listener2Called {
    56  		t.Fatal("listener 2 should've been called")
    57  	}
    58  }
    59  
    60  func TestAsymmetricSigningKey(t *testing.T) {
    61  	th := Setup().InitBasic()
    62  	defer th.TearDown()
    63  	assert.NotNil(t, th.App.AsymmetricSigningKey())
    64  	assert.NotEmpty(t, th.App.ClientConfig()["AsymmetricSigningPublicKey"])
    65  }
    66  
    67  func TestClientConfigWithNoAccounts(t *testing.T) {
    68  	th := Setup().InitBasic()
    69  	defer th.TearDown()
    70  
    71  	config := th.App.ClientConfigWithNoAccounts()
    72  	if _, ok := config["NoAccounts"]; !ok {
    73  		t.Fatal("expected NoAccounts in returned config")
    74  	}
    75  }