mirror of
https://github.com/octoleo/restic.git
synced 2024-11-22 04:45:15 +00:00
tests: Ensure that backend tests cannot be skipped on Travis
This commit is contained in:
parent
5c6ec78789
commit
ee68f9298b
@ -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"} {
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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",
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user