Skip to content

Commit

Permalink
add test cases for start directory option
Browse files Browse the repository at this point in the history
  • Loading branch information
drakkan committed Mar 2, 2022
1 parent 0d10697 commit 855d382
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions request-server_test.go
Expand Up @@ -7,6 +7,7 @@ import (
"io/ioutil"
"net"
"os"
"path"
"runtime"
"testing"
"time"
Expand Down Expand Up @@ -36,7 +37,7 @@ func (cs csPair) testHandler() *root {

const sock = "/tmp/rstest.sock"

func clientRequestServerPair(t *testing.T) *csPair {
func clientRequestServerPair(t *testing.T, options ...RequestServerOption) *csPair {
skipIfWindows(t)
skipIfPlan9(t)

Expand All @@ -61,7 +62,6 @@ func clientRequestServerPair(t *testing.T) *csPair {
require.NoError(t, err)

handlers := InMemHandler()
var options []RequestServerOption
if *testAllocator {
options = append(options, WithRSAllocator())
}
Expand Down Expand Up @@ -780,6 +780,37 @@ func TestRequestStatVFSError(t *testing.T) {
checkRequestServerAllocator(t, p)
}

func TestRequestStartDirOption(t *testing.T) {
startDir := "/start/dir"
p := clientRequestServerPair(t, WithStartDirectory(startDir))
defer p.Close()

// create the start directory
err := p.cli.MkdirAll(startDir)
assert.NoError(t, err)
// the working directory must be the defined start directory
wd, err := p.cli.Getwd()
assert.NoError(t, err)
assert.Equal(t, startDir, wd)
// upload a file using a relative path, it must be uploaded to the start directory
fileName := "file.txt"
_, err = putTestFile(p.cli, fileName, "")
assert.NoError(t, err)
// we must be able to stat the file using both a relative and an absolute path
for _, filePath := range []string{fileName, path.Join(startDir, fileName)} {
fi, err := p.cli.Stat(filePath)
require.NoError(t, err)
assert.Equal(t, fileName, fi.Name())
}
// list dir contents using a relative path
entries, err := p.cli.ReadDir(".")
assert.NoError(t, err)
assert.Len(t, entries, 1)
// delete the file using a relative path
err = p.cli.Remove(fileName)
assert.NoError(t, err)
}

func TestCleanDisconnect(t *testing.T) {
p := clientRequestServerPair(t)
defer p.Close()
Expand Down Expand Up @@ -811,6 +842,7 @@ func TestUncleanDisconnect(t *testing.T) {
func TestCleanPath(t *testing.T) {
assert.Equal(t, "/", cleanPath("/"))
assert.Equal(t, "/", cleanPath("."))
assert.Equal(t, "/", cleanPath(""))
assert.Equal(t, "/", cleanPath("/."))
assert.Equal(t, "/", cleanPath("/a/.."))
assert.Equal(t, "/a/c", cleanPath("/a/b/../c"))
Expand Down

0 comments on commit 855d382

Please sign in to comment.