2017-04-25 21:57:59 +08:00
|
|
|
// Serve webdav tests set up a server and run the integration tests
|
|
|
|
// for the webdav remote against it.
|
|
|
|
//
|
|
|
|
// We skip tests on platforms with troublesome character mappings
|
|
|
|
|
2018-11-26 00:34:51 +08:00
|
|
|
//+build !windows,!darwin,go1.9
|
2017-04-25 21:57:59 +08:00
|
|
|
|
|
|
|
package webdav
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"testing"
|
|
|
|
|
2018-01-12 00:05:41 +08:00
|
|
|
_ "github.com/ncw/rclone/backend/local"
|
2018-02-15 04:39:11 +08:00
|
|
|
"github.com/ncw/rclone/cmd/serve/httplib"
|
2017-04-25 21:57:59 +08:00
|
|
|
"github.com/ncw/rclone/fstest"
|
|
|
|
"github.com/stretchr/testify/assert"
|
2018-06-10 18:54:44 +08:00
|
|
|
"golang.org/x/net/webdav"
|
2017-04-25 21:57:59 +08:00
|
|
|
)
|
|
|
|
|
2018-02-15 04:39:11 +08:00
|
|
|
const (
|
2019-05-01 18:16:22 +08:00
|
|
|
testBindAddress = "localhost:0"
|
2018-02-15 04:39:11 +08:00
|
|
|
)
|
|
|
|
|
2018-06-10 18:54:44 +08:00
|
|
|
// check interfaces
|
|
|
|
var (
|
|
|
|
_ os.FileInfo = FileInfo{nil}
|
|
|
|
_ webdav.ETager = FileInfo{nil}
|
|
|
|
_ webdav.ContentTyper = FileInfo{nil}
|
|
|
|
)
|
|
|
|
|
2017-04-25 21:57:59 +08:00
|
|
|
// TestWebDav runs the webdav server then runs the unit tests for the
|
|
|
|
// webdav remote against it.
|
|
|
|
func TestWebDav(t *testing.T) {
|
2018-02-15 04:39:11 +08:00
|
|
|
opt := httplib.DefaultOpt
|
|
|
|
opt.ListenAddr = testBindAddress
|
|
|
|
|
2017-04-25 21:57:59 +08:00
|
|
|
fstest.Initialise()
|
|
|
|
|
|
|
|
fremote, _, clean, err := fstest.RandomRemote(*fstest.RemoteName, *fstest.SubDir)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
defer clean()
|
|
|
|
|
|
|
|
err = fremote.Mkdir("")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// Start the server
|
2018-02-19 22:02:19 +08:00
|
|
|
w := newWebDAV(fremote, &opt)
|
2018-11-02 01:16:31 +08:00
|
|
|
assert.NoError(t, w.serve())
|
|
|
|
defer func() {
|
|
|
|
w.Close()
|
|
|
|
w.Wait()
|
|
|
|
}()
|
2017-04-25 21:57:59 +08:00
|
|
|
|
|
|
|
// Change directory to run the tests
|
2018-01-12 00:05:41 +08:00
|
|
|
err = os.Chdir("../../../backend/webdav")
|
2017-04-25 21:57:59 +08:00
|
|
|
assert.NoError(t, err, "failed to cd to webdav remote")
|
|
|
|
|
|
|
|
// Run the webdav tests with an on the fly remote
|
|
|
|
args := []string{"test"}
|
|
|
|
if testing.Verbose() {
|
|
|
|
args = append(args, "-v")
|
|
|
|
}
|
|
|
|
if *fstest.Verbose {
|
|
|
|
args = append(args, "-verbose")
|
|
|
|
}
|
|
|
|
args = append(args, "-remote", "webdavtest:")
|
|
|
|
cmd := exec.Command("go", args...)
|
|
|
|
cmd.Env = append(os.Environ(),
|
|
|
|
"RCLONE_CONFIG_WEBDAVTEST_TYPE=webdav",
|
2019-05-01 18:16:22 +08:00
|
|
|
"RCLONE_CONFIG_WEBDAVTEST_URL="+w.Server.URL(),
|
2017-04-25 21:57:59 +08:00
|
|
|
"RCLONE_CONFIG_WEBDAVTEST_VENDOR=other",
|
|
|
|
)
|
|
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
if len(out) != 0 {
|
|
|
|
t.Logf("\n----------\n%s----------\n", string(out))
|
|
|
|
}
|
|
|
|
assert.NoError(t, err, "Running webdav integration tests")
|
|
|
|
}
|