mirror of
https://github.com/rclone/rclone.git
synced 2026-06-19 19:04:02 +02:00
serve s3: skip TestS3Minio when the docker test framework is unavailable
TestS3Minio brings up a minio container via the fstest/testserver framework, which exec's bash init.d scripts that shell out to docker. This is not available on all platforms - Windows has no POSIX shell to run the scripts, and macOS CI runners have no docker daemon - which caused the build to fail there. Add testy.SkipUnlessDocker to detect whether the framework can run and skip the test when it cannot.
This commit is contained in:
@@ -27,6 +27,7 @@ import (
|
||||
"github.com/rclone/rclone/fs/object"
|
||||
"github.com/rclone/rclone/fs/rc"
|
||||
"github.com/rclone/rclone/fstest"
|
||||
"github.com/rclone/rclone/fstest/testy"
|
||||
"github.com/rclone/rclone/lib/random"
|
||||
"github.com/rclone/rclone/vfs/vfscommon"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -84,6 +85,7 @@ func TestS3(t *testing.T) {
|
||||
// this exercises that streaming path in serve s3 - the path the local
|
||||
// backing in TestS3 cannot cover.
|
||||
func TestS3Minio(t *testing.T) {
|
||||
testy.SkipUnlessDocker(t)
|
||||
servetest.RunWithBackend(t, "s3", startS3(t), "TestS3Minio:")
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,9 @@ package testy
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"sync"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -18,3 +21,37 @@ func SkipUnreliable(t *testing.T) {
|
||||
}
|
||||
t.Skip("Skipping Unreliable Test on CI")
|
||||
}
|
||||
|
||||
var dockerOnce struct {
|
||||
sync.Once
|
||||
ok bool
|
||||
}
|
||||
|
||||
// HaveDocker returns true if the fstest/testserver docker framework can
|
||||
// be used on this host. The framework brings up containers (e.g. minio)
|
||||
// by exec'ing the bash init.d scripts which in turn shell out to docker,
|
||||
// so it needs both a POSIX shell (not available on Windows) and a
|
||||
// reachable docker daemon. The result is cached after the first call.
|
||||
func HaveDocker() bool {
|
||||
dockerOnce.Do(func() {
|
||||
// The init.d scripts are bash and cannot be exec'd on Windows.
|
||||
if runtime.GOOS == "windows" {
|
||||
return
|
||||
}
|
||||
// docker version exits non-zero if the client is installed but
|
||||
// the daemon is unreachable, which is exactly what we want to
|
||||
// detect.
|
||||
dockerOnce.ok = exec.Command("docker", "version").Run() == nil
|
||||
})
|
||||
return dockerOnce.ok
|
||||
}
|
||||
|
||||
// SkipUnlessDocker skips this test unless a working docker daemon is
|
||||
// available. Use it for tests that rely on the fstest/testserver docker
|
||||
// framework, which is not available on all platforms (e.g. Windows and
|
||||
// macOS CI runners).
|
||||
func SkipUnlessDocker(t *testing.T) {
|
||||
if !HaveDocker() {
|
||||
t.Skip("Skipping test as docker is not available")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user