agones.dev/agones@v1.54.0/test/e2e/controller/main_test.go (about) 1 // Copyright 2020 Google LLC All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package controller 16 17 import ( 18 "os" 19 "testing" 20 21 e2eframework "agones.dev/agones/test/e2e/framework" 22 "github.com/sirupsen/logrus" 23 log "github.com/sirupsen/logrus" 24 ) 25 26 const defaultNs = "default" 27 28 var framework *e2eframework.Framework 29 30 func TestMain(m *testing.M) { 31 logrus.SetFormatter(&logrus.TextFormatter{ 32 EnvironmentOverrideColors: true, 33 FullTimestamp: true, 34 TimestampFormat: "2006-01-02 15:04:05.000", 35 }) 36 37 var ( 38 err error 39 exitCode int 40 ) 41 42 if err = e2eframework.ParseTestFlags(); err != nil { 43 log.WithError(err).Error("failed to parse go test flags") 44 os.Exit(1) 45 } 46 47 if framework, err = e2eframework.NewFromFlags(); err != nil { 48 log.WithError(err).Error("failed to setup framework") 49 os.Exit(1) 50 } 51 52 // run cleanup before tests, to ensure no resources from previous runs exist. 53 err = framework.CleanUp(defaultNs) 54 if err != nil { 55 log.WithError(err).Error("failed to cleanup resources") 56 } 57 58 defer func() { 59 err = framework.CleanUp(defaultNs) 60 if err != nil { 61 log.WithError(err).Error("failed to cleanup resources") 62 } 63 os.Exit(exitCode) 64 }() 65 exitCode = m.Run() 66 }