github.com/mckael/restic@v0.8.3/internal/test/vars.go (about) 1 package test 2 3 import ( 4 "fmt" 5 "os" 6 "strings" 7 "testing" 8 ) 9 10 var ( 11 TestPassword = getStringVar("RESTIC_TEST_PASSWORD", "geheim") 12 TestCleanupTempDirs = getBoolVar("RESTIC_TEST_CLEANUP", true) 13 TestTempDir = getStringVar("RESTIC_TEST_TMPDIR", "") 14 RunIntegrationTest = getBoolVar("RESTIC_TEST_INTEGRATION", true) 15 RunFuseTest = getBoolVar("RESTIC_TEST_FUSE", true) 16 TestSFTPPath = getStringVar("RESTIC_TEST_SFTPPATH", "/usr/lib/ssh:/usr/lib/openssh:/usr/libexec") 17 TestWalkerPath = getStringVar("RESTIC_TEST_PATH", ".") 18 BenchArchiveDirectory = getStringVar("RESTIC_BENCH_DIR", ".") 19 TestS3Server = getStringVar("RESTIC_TEST_S3_SERVER", "") 20 TestRESTServer = getStringVar("RESTIC_TEST_REST_SERVER", "") 21 TestIntegrationDisallowSkip = getStringVar("RESTIC_TEST_DISALLOW_SKIP", "") 22 ) 23 24 func getStringVar(name, defaultValue string) string { 25 if e := os.Getenv(name); e != "" { 26 return e 27 } 28 29 return defaultValue 30 } 31 32 func getBoolVar(name string, defaultValue bool) bool { 33 if e := os.Getenv(name); e != "" { 34 switch e { 35 case "1": 36 return true 37 case "0": 38 return false 39 default: 40 fmt.Fprintf(os.Stderr, "invalid value for variable %q, using default\n", name) 41 } 42 } 43 44 return defaultValue 45 } 46 47 // SkipDisallowed fails the test if it needs to run. The environment 48 // variable RESTIC_TEST_DISALLOW_SKIP contains a comma-separated list of test 49 // names that must be run. If name is in this list, the test is marked as 50 // failed. 51 func SkipDisallowed(t testing.TB, name string) { 52 for _, s := range strings.Split(TestIntegrationDisallowSkip, ",") { 53 if s == name { 54 t.Fatalf("test %v is in list of tests that need to run ($RESTIC_TEST_DISALLOW_SKIP)", name) 55 } 56 } 57 }