diff --git a/run_integration_tests.go b/run_integration_tests.go index 00fe598fc..f820d49a9 100644 --- a/run_integration_tests.go +++ b/run_integration_tests.go @@ -150,6 +150,15 @@ func (env *TravisEnvironment) RunTests() error { env.env["GOPATH"] = cwd + ":" + filepath.Join(cwd, "vendor") + // ensure that the following tests cannot be silently skipped on Travis + ensureTests := []string{ + "restic/backend/rest.TestBackendREST", + "restic/backend/sftp.TestBackendSFTP", + "restic/backend/s3.TestBackendMinio", + "restic/backend/s3.TestBackendS3", + } + env.env["RESTIC_TEST_DISALLOW_SKIP"] = strings.Join(ensureTests, ",") + if *runCrossCompile { // compile for all target architectures with tags for _, tags := range []string{"release", "debug"} { diff --git a/src/restic/backend/rest/rest_test.go b/src/restic/backend/rest/rest_test.go index d378a364f..e8ed57646 100644 --- a/src/restic/backend/rest/rest_test.go +++ b/src/restic/backend/rest/rest_test.go @@ -60,7 +60,13 @@ func runRESTServer(ctx context.Context, t testing.TB, dir string) func() { } } -func TestBackend(t *testing.T) { +func TestBackendREST(t *testing.T) { + defer func() { + if t.Skipped() { + SkipDisallowed(t, "restic/backend/rest.TestBackendREST") + } + }() + ctx, cancel := context.WithCancel(context.Background()) defer cancel() diff --git a/src/restic/backend/s3/s3_test.go b/src/restic/backend/s3/s3_test.go index 22710f92e..b6859bcd4 100644 --- a/src/restic/backend/s3/s3_test.go +++ b/src/restic/backend/s3/s3_test.go @@ -97,6 +97,12 @@ func newCredentials(t testing.TB) (key, secret string) { } func TestBackendMinio(t *testing.T) { + defer func() { + if t.Skipped() { + SkipDisallowed(t, "restic/backend/s3.TestBackendMinio") + } + }() + // try to find a minio binary _, err := exec.LookPath("minio") if err != nil { @@ -179,6 +185,12 @@ func TestBackendMinio(t *testing.T) { } func TestBackendS3(t *testing.T) { + defer func() { + if t.Skipped() { + SkipDisallowed(t, "restic/backend/s3.TestBackendS3") + } + }() + vars := []string{ "RESTIC_TEST_S3_KEY", "RESTIC_TEST_S3_SECRET", diff --git a/src/restic/backend/sftp/sftp_test.go b/src/restic/backend/sftp/sftp_test.go index dd9728676..8fb46d2a1 100644 --- a/src/restic/backend/sftp/sftp_test.go +++ b/src/restic/backend/sftp/sftp_test.go @@ -29,7 +29,13 @@ func findSFTPServerBinary() string { var sftpServer = findSFTPServerBinary() -func TestBackend(t *testing.T) { +func TestBackendSFTP(t *testing.T) { + defer func() { + if t.Skipped() { + SkipDisallowed(t, "restic/backend/sftp.TestBackendSFTP") + } + }() + if sftpServer == "" { t.Skip("sftp server binary not found") } diff --git a/src/restic/test/vars.go b/src/restic/test/vars.go index 908e4bf6b..616f969f6 100644 --- a/src/restic/test/vars.go +++ b/src/restic/test/vars.go @@ -3,19 +3,22 @@ package test import ( "fmt" "os" + "strings" + "testing" ) 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", "") + 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", "") ) func getStringVar(name, defaultValue string) string { @@ -40,3 +43,15 @@ func getBoolVar(name string, defaultValue bool) bool { 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) + } + } +}