2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-25 22:27:35 +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")
// 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"} {

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())
defer cancel()

View File

@ -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",

View File

@ -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")
}

View File

@ -3,6 +3,8 @@ package test
import (
"fmt"
"os"
"strings"
"testing"
)
var (
@ -16,6 +18,7 @@ var (
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)
}
}
}