From 12677b4f8a3be83c591849fc310aa2e2d7988727 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Fri, 5 Jun 2015 22:33:39 +0200 Subject: [PATCH] Use flag instead of build tag to run integration tests --- Makefile | 4 ++-- backend/sftp_test.go | 6 ++++-- cmd/restic/integration_helpers_test.go | 2 -- cmd/restic/integration_test.go | 8 +++++--- test/backend.go | 9 ++++++--- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 04099f41b..fbebac11d 100644 --- a/Makefile +++ b/Makefile @@ -50,15 +50,15 @@ gox: .gopath $(SOURCE) test-integration: .gopath cd $(BASEPATH) && go test $(GOTESTFLAGS) \ - -tags integration \ ./backend \ -cover -covermode=count -coverprofile=integration-sftp.cov \ + -test.integration \ -test.sftppath=$(SFTP_PATH) cd $(BASEPATH) && go test $(GOTESTFLAGS) \ - -tags integration \ ./cmd/restic \ -cover -covermode=count -coverprofile=integration.cov \ + -test.integration \ -test.datafile=$(PWD)/testsuite/fake-data.tar.gz all.cov: .gopath $(SOURCE) test-integration diff --git a/backend/sftp_test.go b/backend/sftp_test.go index 189e26d53..15ab04ead 100644 --- a/backend/sftp_test.go +++ b/backend/sftp_test.go @@ -1,5 +1,3 @@ -// +build integration - package backend_test import ( @@ -37,6 +35,10 @@ func teardownSFTPBackend(t *testing.T, b *sftp.SFTP) { } func TestSFTPBackend(t *testing.T) { + if !*RunIntegrationTest { + t.Skip("integration tests disabled, use `-test.integration` to enable") + } + if *sftpPath == "" { t.Skipf("sftppath not set, skipping TestSFTPBackend") } diff --git a/cmd/restic/integration_helpers_test.go b/cmd/restic/integration_helpers_test.go index 2f3f0ec72..65da5878b 100644 --- a/cmd/restic/integration_helpers_test.go +++ b/cmd/restic/integration_helpers_test.go @@ -1,5 +1,3 @@ -// +build integration - package main import ( diff --git a/cmd/restic/integration_test.go b/cmd/restic/integration_test.go index 4d8106974..f07c35d10 100644 --- a/cmd/restic/integration_test.go +++ b/cmd/restic/integration_test.go @@ -1,5 +1,3 @@ -// +build integration - package main import ( @@ -119,8 +117,12 @@ func cmdFsck(t testing.TB) { } func TestBackup(t *testing.T) { + if !*RunIntegrationTest { + t.Skip("integration tests disabled, use `-test.integration` to enable") + } + if *TestDataFile == "" { - t.Fatal("no data tar file specified, use flag '-test.datafile'") + t.Fatal("no data tar file specified, use flag `-test.datafile`") } tempdir := setupTempdir(t) diff --git a/test/backend.go b/test/backend.go index f1374d14d..8abd28582 100644 --- a/test/backend.go +++ b/test/backend.go @@ -12,9 +12,12 @@ import ( "github.com/restic/restic/repository" ) -var TestPassword = flag.String("test.password", "geheim", `use this password for repositories created during tests (default: "geheim")`) -var TestCleanup = flag.Bool("test.cleanup", true, "clean up after running tests (remove local backend directory with all content)") -var TestTempDir = flag.String("test.tempdir", "", "use this directory for temporary storage (default: system temp dir)") +var ( + TestPassword = flag.String("test.password", "geheim", `use this password for repositories created during tests (default: "geheim")`) + TestCleanup = flag.Bool("test.cleanup", true, "clean up after running tests (remove local backend directory with all content)") + TestTempDir = flag.String("test.tempdir", "", "use this directory for temporary storage (default: system temp dir)") + RunIntegrationTest = flag.Bool("test.integration", false, "run integration tests (default: false)") +) func SetupRepo(t testing.TB) *repository.Repository { tempdir, err := ioutil.TempDir(*TestTempDir, "restic-test-")