2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-27 15:26:37 +00:00
restic/internal/test/vars.go

58 lines
1.8 KiB
Go
Raw Normal View History

2016-09-04 12:29:04 +00:00
package test
2015-04-26 12:46:15 +00:00
import (
2015-06-13 10:35:19 +00:00
"fmt"
"os"
"strings"
"testing"
2015-04-26 12:46:15 +00:00
)
var (
TestPassword = getStringVar("RESTIC_TEST_PASSWORD", "geheim")
TestCleanupTempDirs = getBoolVar("RESTIC_TEST_CLEANUP", true)
TestTempDir = getStringVar("RESTIC_TEST_TMPDIR", "")
RunIntegrationTest = getBoolVar("RESTIC_TEST_INTEGRATION", true)
RunFuseTest = getBoolVar("RESTIC_TEST_FUSE", true)
TestSFTPPath = getStringVar("RESTIC_TEST_SFTPPATH", "/usr/lib/ssh:/usr/lib/openssh:/usr/libexec")
TestWalkerPath = getStringVar("RESTIC_TEST_PATH", ".")
BenchArchiveDirectory = getStringVar("RESTIC_BENCH_DIR", ".")
TestS3Server = getStringVar("RESTIC_TEST_S3_SERVER", "")
TestRESTServer = getStringVar("RESTIC_TEST_REST_SERVER", "")
TestIntegrationDisallowSkip = getStringVar("RESTIC_TEST_DISALLOW_SKIP", "")
)
2015-04-26 12:46:15 +00:00
2015-06-13 10:35:19 +00:00
func getStringVar(name, defaultValue string) string {
if e := os.Getenv(name); e != "" {
return e
}
return defaultValue
}
func getBoolVar(name string, defaultValue bool) bool {
if e := os.Getenv(name); e != "" {
switch e {
2019-11-18 20:16:47 +00:00
case "1", "true":
2015-06-13 10:35:19 +00:00
return true
2019-11-18 20:16:47 +00:00
case "0", "false":
2015-06-13 10:35:19 +00:00
return false
default:
fmt.Fprintf(os.Stderr, "invalid value for variable %q, using default\n", name)
}
}
return defaultValue
}
// SkipDisallowed fails the test if it needs to run. The environment
// variable RESTIC_TEST_DISALLOW_SKIP contains a comma-separated list of test
// names that must be run. If name is in this list, the test is marked as
// failed.
func SkipDisallowed(t testing.TB, name string) {
for _, s := range strings.Split(TestIntegrationDisallowSkip, ",") {
if s == name {
t.Fatalf("test %v is in list of tests that need to run ($RESTIC_TEST_DISALLOW_SKIP)", name)
}
}
}