github.com/databricks/cli@v0.203.0/internal/acc/helpers.go (about) 1 package acc 2 3 import ( 4 "fmt" 5 "math/rand" 6 "os" 7 "strings" 8 "testing" 9 "time" 10 ) 11 12 // GetEnvOrSkipTest proceeds with test only with that env variable. 13 func GetEnvOrSkipTest(t *testing.T, name string) string { 14 value := os.Getenv(name) 15 if value == "" { 16 t.Skipf("Environment variable %s is missing", name) 17 } 18 return value 19 } 20 21 const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" 22 23 // RandomName gives random name with optional prefix. e.g. qa.RandomName("tf-") 24 func RandomName(prefix ...string) string { 25 rand.Seed(time.Now().UnixNano()) 26 randLen := 12 27 b := make([]byte, randLen) 28 for i := range b { 29 b[i] = charset[rand.Intn(randLen)] 30 } 31 if len(prefix) > 0 { 32 return fmt.Sprintf("%s%s", strings.Join(prefix, ""), b) 33 } 34 return string(b) 35 }