github.com/sentienttechnologies/studio-go-runner@v0.0.0-20201118202441-6d21f2ced8ee/internal/runner/main_test.go (about) 1 // Copyright 2018-2020 (c) Cognizant Digital Business, Evolutionary AI. All rights reserved. Issued under the Apache 2.0 License. 2 3 package runner 4 5 import ( 6 "flag" 7 "fmt" 8 "os" 9 "path/filepath" 10 "testing" 11 12 "github.com/go-stack/stack" 13 "github.com/jjeffery/kv" 14 "github.com/karlmutch/envflag" 15 ) 16 17 var ( 18 useGPU = flag.Bool("no-gpu", false, "Used to skip test and other initialization GPU hardware code") //nolint 19 useK8s = flag.Bool("use-k8s", false, "Used to enable test and other initialization for the Kubernetes cluster support") 20 topDir = flag.String("top-dir", "../..", "The location of the top level source directory for locating test files") 21 22 // TestOptions are externally visible symbols that this package is asking the unit test suite to pickup and use 23 // when the testing is managed by an external entity, this allows build level variations that include or 24 // exclude GPUs for example to run their tests appropriately. It also allows the top level build logic 25 // to inspect source code for executables and run their testing without knowledge of how they work. 26 DuatTestOptions = [][]string{ //nolint 27 {""}, 28 } 29 30 // The location that the annotations downward API mounted kubernetes files will be found 31 k8sAnnotations = "/etc/podinfo/annotations" //nolint 32 ) 33 34 func TestMain(m *testing.M) { 35 // Allow the enclave for secrets to wipe things 36 defer StopSecret() 37 38 // Only perform this Parsed check inside the test framework. Do not be tempted 39 // to do this in the main of our production package 40 // 41 if !flag.Parsed() { 42 envflag.Parse() 43 } 44 45 if stat, err := os.Stat(*topDir); os.IsNotExist(err) { 46 fmt.Println(kv.Wrap(err).With("top-dir", *topDir).With("stack", stack.Trace().TrimRuntime())) 47 os.Exit(-1) 48 } else { 49 if !stat.Mode().IsDir() { 50 fmt.Println(kv.NewError("not a directory").With("top-dir", *topDir).With("stack", stack.Trace().TrimRuntime())) 51 os.Exit(-1) 52 } 53 54 } 55 if dir, err := filepath.Abs(*topDir); err != nil { 56 fmt.Println((kv.Wrap(err).With("top-dir", *topDir).With("stack", stack.Trace().TrimRuntime()))) 57 } else { 58 flag.Set("top-dir", dir) 59 } 60 m.Run() 61 }