2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-22 12:55:18 +00:00

tests: Ensure that backend tests cannot be skipped on Travis

This commit is contained in:
Alexander Neumann 2017-05-13 20:41:04 +02:00
parent 5c6ec78789
commit ee68f9298b
5 changed files with 60 additions and 12 deletions

View File

@ -150,6 +150,15 @@ func (env *TravisEnvironment) RunTests() error {
env.env["GOPATH"] = cwd + ":" + filepath.Join(cwd, "vendor") 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 { if *runCrossCompile {
// compile for all target architectures with tags // compile for all target architectures with tags
for _, tags := range []string{"release", "debug"} { for _, tags := range []string{"release", "debug"} {

View File

@ -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()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()

View File

@ -97,6 +97,12 @@ func newCredentials(t testing.TB) (key, secret string) {
} }
func TestBackendMinio(t *testing.T) { func TestBackendMinio(t *testing.T) {
defer func() {
if t.Skipped() {
SkipDisallowed(t, "restic/backend/s3.TestBackendMinio")
}
}()
// try to find a minio binary // try to find a minio binary
_, err := exec.LookPath("minio") _, err := exec.LookPath("minio")
if err != nil { if err != nil {
@ -179,6 +185,12 @@ func TestBackendMinio(t *testing.T) {
} }
func TestBackendS3(t *testing.T) { func TestBackendS3(t *testing.T) {
defer func() {
if t.Skipped() {
SkipDisallowed(t, "restic/backend/s3.TestBackendS3")
}
}()
vars := []string{ vars := []string{
"RESTIC_TEST_S3_KEY", "RESTIC_TEST_S3_KEY",
"RESTIC_TEST_S3_SECRET", "RESTIC_TEST_S3_SECRET",

View File

@ -29,7 +29,13 @@ func findSFTPServerBinary() string {
var sftpServer = findSFTPServerBinary() 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 == "" { if sftpServer == "" {
t.Skip("sftp server binary not found") t.Skip("sftp server binary not found")
} }

View File

@ -3,19 +3,22 @@ package test
import ( import (
"fmt" "fmt"
"os" "os"
"strings"
"testing"
) )
var ( var (
TestPassword = getStringVar("RESTIC_TEST_PASSWORD", "geheim") TestPassword = getStringVar("RESTIC_TEST_PASSWORD", "geheim")
TestCleanupTempDirs = getBoolVar("RESTIC_TEST_CLEANUP", true) TestCleanupTempDirs = getBoolVar("RESTIC_TEST_CLEANUP", true)
TestTempDir = getStringVar("RESTIC_TEST_TMPDIR", "") TestTempDir = getStringVar("RESTIC_TEST_TMPDIR", "")
RunIntegrationTest = getBoolVar("RESTIC_TEST_INTEGRATION", true) RunIntegrationTest = getBoolVar("RESTIC_TEST_INTEGRATION", true)
RunFuseTest = getBoolVar("RESTIC_TEST_FUSE", true) RunFuseTest = getBoolVar("RESTIC_TEST_FUSE", true)
TestSFTPPath = getStringVar("RESTIC_TEST_SFTPPATH", "/usr/lib/ssh:/usr/lib/openssh:/usr/libexec") TestSFTPPath = getStringVar("RESTIC_TEST_SFTPPATH", "/usr/lib/ssh:/usr/lib/openssh:/usr/libexec")
TestWalkerPath = getStringVar("RESTIC_TEST_PATH", ".") TestWalkerPath = getStringVar("RESTIC_TEST_PATH", ".")
BenchArchiveDirectory = getStringVar("RESTIC_BENCH_DIR", ".") BenchArchiveDirectory = getStringVar("RESTIC_BENCH_DIR", ".")
TestS3Server = getStringVar("RESTIC_TEST_S3_SERVER", "") TestS3Server = getStringVar("RESTIC_TEST_S3_SERVER", "")
TestRESTServer = getStringVar("RESTIC_TEST_REST_SERVER", "") TestRESTServer = getStringVar("RESTIC_TEST_REST_SERVER", "")
TestIntegrationDisallowSkip = getStringVar("RESTIC_TEST_DISALLOW_SKIP", "")
) )
func getStringVar(name, defaultValue string) string { func getStringVar(name, defaultValue string) string {
@ -40,3 +43,15 @@ func getBoolVar(name string, defaultValue bool) bool {
return defaultValue 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)
}
}
}