github.com/gigforks/mattermost-server@v4.9.1-0.20180619094218-800d97fa55d0+incompatible/api/api_test.go (about) 1 // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package api 5 6 import ( 7 "flag" 8 "os" 9 "testing" 10 11 "github.com/mattermost/mattermost-server/mlog" 12 "github.com/mattermost/mattermost-server/store/storetest" 13 "github.com/mattermost/mattermost-server/utils" 14 ) 15 16 func TestMain(m *testing.M) { 17 flag.Parse() 18 19 // Setup a global logger to catch tests logging outside of app context 20 // The global logger will be stomped by apps initalizing but that's fine for testing. Ideally this won't happen. 21 mlog.InitGlobalLogger(mlog.NewLogger(&mlog.LoggerConfiguration{ 22 EnableConsole: true, 23 ConsoleJson: true, 24 ConsoleLevel: "error", 25 EnableFile: false, 26 })) 27 28 utils.TranslationsPreInit() 29 30 // In the case where a dev just wants to run a single test, it's faster to just use the default 31 // store. 32 if filter := flag.Lookup("test.run").Value.String(); filter != "" && filter != "." { 33 mlog.Info("-test.run used, not creating temporary containers") 34 os.Exit(m.Run()) 35 } 36 37 status := 0 38 39 container, settings, err := storetest.NewMySQLContainer() 40 if err != nil { 41 panic(err) 42 } 43 44 UseTestStore(container, settings) 45 46 defer func() { 47 StopTestStore() 48 os.Exit(status) 49 }() 50 51 status = m.Run() 52 }