diff --git a/request-server_test.go b/request-server_test.go index eb1a5332..d7130be6 100644 --- a/request-server_test.go +++ b/request-server_test.go @@ -7,6 +7,7 @@ import ( "io/ioutil" "net" "os" + "path" "runtime" "testing" "time" @@ -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) @@ -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()) } @@ -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() @@ -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"))