github.com/coincircle/mattermost-server@v4.8.1-0.20180321182714-9d701c704416+incompatible/app/app_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 "flag" 8 "os" 9 "testing" 10 11 l4g "github.com/alecthomas/log4go" 12 13 "github.com/stretchr/testify/assert" 14 "github.com/stretchr/testify/require" 15 16 "github.com/mattermost/mattermost-server/model" 17 "github.com/mattermost/mattermost-server/store/storetest" 18 "github.com/mattermost/mattermost-server/utils" 19 ) 20 21 func TestMain(m *testing.M) { 22 flag.Parse() 23 utils.TranslationsPreInit() 24 25 // In the case where a dev just wants to run a single test, it's faster to just use the default 26 // store. 27 if filter := flag.Lookup("test.run").Value.String(); filter != "" && filter != "." { 28 l4g.Info("-test.run used, not creating temporary containers") 29 os.Exit(m.Run()) 30 } 31 32 status := 0 33 34 container, settings, err := storetest.NewMySQLContainer() 35 if err != nil { 36 panic(err) 37 } 38 39 UseTestStore(container, settings) 40 41 defer func() { 42 StopTestStore() 43 os.Exit(status) 44 }() 45 46 status = m.Run() 47 } 48 49 func TestAppRace(t *testing.T) { 50 for i := 0; i < 10; i++ { 51 a, err := New() 52 require.NoError(t, err) 53 a.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ListenAddress = ":0" }) 54 serverErr := a.StartServer() 55 require.NoError(t, serverErr) 56 a.Shutdown() 57 } 58 } 59 60 func TestUpdateConfig(t *testing.T) { 61 th := Setup() 62 defer th.TearDown() 63 64 prev := *th.App.Config().ServiceSettings.SiteURL 65 66 th.App.AddConfigListener(func(old, current *model.Config) { 67 assert.Equal(t, prev, *old.ServiceSettings.SiteURL) 68 assert.Equal(t, "foo", *current.ServiceSettings.SiteURL) 69 }) 70 71 th.App.UpdateConfig(func(cfg *model.Config) { 72 *cfg.ServiceSettings.SiteURL = "foo" 73 }) 74 }