agones.dev/agones@v1.54.0/test/e2e/extensions/main_test.go (about)

     1  // Copyright 2023 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 extensions
    16  
    17  import (
    18  	"os"
    19  	"testing"
    20  
    21  	e2eframework "agones.dev/agones/test/e2e/framework"
    22  	log "github.com/sirupsen/logrus"
    23  )
    24  
    25  const defaultNs = "default"
    26  
    27  var framework *e2eframework.Framework
    28  
    29  func TestMain(m *testing.M) {
    30  	log.SetFormatter(&log.TextFormatter{
    31  		EnvironmentOverrideColors: true,
    32  		FullTimestamp:             true,
    33  		TimestampFormat:           "2006-01-02 15:04:05.000",
    34  	})
    35  
    36  	var (
    37  		err      error
    38  		exitCode int
    39  	)
    40  
    41  	if err = e2eframework.ParseTestFlags(); err != nil {
    42  		log.WithError(err).Error("failed to parse go test flags")
    43  		os.Exit(1)
    44  	}
    45  
    46  	if framework, err = e2eframework.NewFromFlags(); err != nil {
    47  		log.WithError(err).Error("failed to setup framework")
    48  		os.Exit(1)
    49  	}
    50  
    51  	// run cleanup before tests, to ensure no resources from previous runs exist.
    52  	err = framework.CleanUp(defaultNs)
    53  	if err != nil {
    54  		log.WithError(err).Error("failed to cleanup resources")
    55  	}
    56  
    57  	defer func() {
    58  		err = framework.CleanUp(defaultNs)
    59  		if err != nil {
    60  			log.WithError(err).Error("failed to cleanup resources")
    61  		}
    62  		os.Exit(exitCode)
    63  	}()
    64  	exitCode = m.Run()
    65  }