github.com/verrazzano/verrazzano@v1.7.1/tests/e2e/pkg/testdata.go (about) 1 // Copyright (c) 2021, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 package pkg 5 6 import ( 7 "fmt" 8 "os" 9 "path/filepath" 10 ) 11 12 // FindTestDataFile finds a test data file by searching up from the working directory looking for a relative file. 13 // This is done to simplify the execution of tests in both local and remote environments. 14 func FindTestDataFile(file string) (string, error) { 15 find := file 16 _, err := os.Stat(file) 17 if err != nil { 18 dir, err := os.Getwd() 19 if err != nil { 20 return find, err 21 } 22 for dir != "/" { 23 dir = filepath.Dir(dir) 24 find = filepath.Join(dir, file) 25 _, err = os.Stat(find) 26 if err == nil { 27 return find, nil 28 } 29 } 30 return find, fmt.Errorf("failed to find test data file: %s", file) 31 } 32 return file, nil 33 }