From d60af809bedf69af722853942b3b3be9bec94d8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Sun, 15 Oct 2023 14:26:32 +0200 Subject: [PATCH] Shaman: skip certain tests if the platform cannot do symlinking reliably Windows 10 Home ("Core") only allows symlinking when running as admin, which is not recommended for Flamenco Manager. Instead of failing unit tests on this system, simply skip them. This reduces noise when developing on this platform (i.e. my personal laptop) a lot. --- pkg/shaman/checkout/checkout_test.go | 3 +++ pkg/shaman/checkout/manager_test.go | 5 +++++ pkg/shaman/cleanup_test.go | 5 +++++ pkg/shaman/testsupport/testsupport.go | 17 +++++++++++++++++ 4 files changed, 30 insertions(+) create mode 100644 pkg/shaman/testsupport/testsupport.go diff --git a/pkg/shaman/checkout/checkout_test.go b/pkg/shaman/checkout/checkout_test.go index f78164ed..53f0cd07 100644 --- a/pkg/shaman/checkout/checkout_test.go +++ b/pkg/shaman/checkout/checkout_test.go @@ -9,9 +9,12 @@ import ( "github.com/stretchr/testify/assert" "projects.blender.org/studio/flamenco/pkg/api" "projects.blender.org/studio/flamenco/pkg/shaman/filestore" + "projects.blender.org/studio/flamenco/pkg/shaman/testsupport" ) func TestCheckout(t *testing.T) { + testsupport.SkipTestIfUnableToSymlink(t) + manager, cleanup := createTestManager() defer cleanup() ctx := context.Background() diff --git a/pkg/shaman/checkout/manager_test.go b/pkg/shaman/checkout/manager_test.go index b976d0c1..ebd7d319 100644 --- a/pkg/shaman/checkout/manager_test.go +++ b/pkg/shaman/checkout/manager_test.go @@ -36,6 +36,7 @@ import ( "projects.blender.org/studio/flamenco/pkg/api" "projects.blender.org/studio/flamenco/pkg/shaman/config" "projects.blender.org/studio/flamenco/pkg/shaman/filestore" + "projects.blender.org/studio/flamenco/pkg/shaman/testsupport" ) func createTestManager() (*Manager, func()) { @@ -46,6 +47,8 @@ func createTestManager() (*Manager, func()) { } func TestSymlinkToCheckout(t *testing.T) { + testsupport.SkipTestIfUnableToSymlink(t) + manager, cleanup := createTestManager() defer cleanup() @@ -101,6 +104,8 @@ func TestPrepareCheckout(t *testing.T) { } func TestEraseCheckout(t *testing.T) { + testsupport.SkipTestIfUnableToSymlink(t) + manager, cleanup := createTestManager() defer cleanup() ctx := context.Background() diff --git a/pkg/shaman/cleanup_test.go b/pkg/shaman/cleanup_test.go index f45d809e..584dda43 100644 --- a/pkg/shaman/cleanup_test.go +++ b/pkg/shaman/cleanup_test.go @@ -36,6 +36,7 @@ import ( "projects.blender.org/studio/flamenco/pkg/shaman/config" "projects.blender.org/studio/flamenco/pkg/shaman/filestore" "projects.blender.org/studio/flamenco/pkg/shaman/jwtauth" + "projects.blender.org/studio/flamenco/pkg/shaman/testsupport" ) func createTestShaman() (*Server, func()) { @@ -116,6 +117,8 @@ func TestGCFindOldFiles(t *testing.T) { // Test of the lower-level functions of the garbage collector. func TestGCComponents(t *testing.T) { + testsupport.SkipTestIfUnableToSymlink(t) + server, cleanup := createTestShaman() defer cleanup() @@ -200,6 +203,8 @@ func TestGCComponents(t *testing.T) { // Test of the high-level GCStorage() function. func TestGarbageCollect(t *testing.T) { + testsupport.SkipTestIfUnableToSymlink(t) + server, cleanup := createTestShaman() defer cleanup() diff --git a/pkg/shaman/testsupport/testsupport.go b/pkg/shaman/testsupport/testsupport.go new file mode 100644 index 00000000..41817f01 --- /dev/null +++ b/pkg/shaman/testsupport/testsupport.go @@ -0,0 +1,17 @@ +package testsupport + +import ( + "testing" + + "projects.blender.org/studio/flamenco/pkg/sysinfo" +) + +func SkipTestIfUnableToSymlink(t *testing.T) { + can, err := sysinfo.CanSymlink() + switch { + case err != nil: + t.Fatalf("error checking platform symlinking capabilities: %v", err) + case !can: + t.Skip("symlinking not possible on current platform") + } +}