2017-05-02 21:35:07 +00:00
|
|
|
package mounttest
|
2016-07-17 22:03:23 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2017-05-02 21:35:07 +00:00
|
|
|
"time"
|
2016-07-17 22:03:23 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2017-01-29 11:29:42 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2016-07-17 22:03:23 +00:00
|
|
|
)
|
|
|
|
|
2017-05-08 17:05:12 +00:00
|
|
|
// TestWriteFileNoWrite tests writing a file with no write()'s to it
|
2016-07-17 22:03:23 +00:00
|
|
|
func TestWriteFileNoWrite(t *testing.T) {
|
2016-08-20 11:43:33 +00:00
|
|
|
run.skipIfNoFUSE(t)
|
|
|
|
|
2017-11-07 17:27:53 +00:00
|
|
|
fd, err := osCreate(run.path("testnowrite"))
|
2016-07-17 22:03:23 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
err = fd.Close()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2017-05-02 21:35:07 +00:00
|
|
|
// FIXME - wait for the Release on the file
|
|
|
|
time.Sleep(10 * time.Millisecond)
|
|
|
|
|
2016-07-17 22:03:23 +00:00
|
|
|
run.checkDir(t, "testnowrite 0")
|
|
|
|
|
|
|
|
run.rm(t, "testnowrite")
|
|
|
|
}
|
|
|
|
|
2017-05-08 17:05:12 +00:00
|
|
|
// FIXMETestWriteOpenFileInDirListing tests open file in directory listing
|
2016-07-17 22:03:23 +00:00
|
|
|
func FIXMETestWriteOpenFileInDirListing(t *testing.T) {
|
2016-08-20 11:43:33 +00:00
|
|
|
run.skipIfNoFUSE(t)
|
|
|
|
|
2017-11-07 17:27:53 +00:00
|
|
|
fd, err := osCreate(run.path("testnowrite"))
|
2016-07-17 22:03:23 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
run.checkDir(t, "testnowrite 0")
|
|
|
|
|
|
|
|
err = fd.Close()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
run.rm(t, "testnowrite")
|
|
|
|
}
|
|
|
|
|
2017-05-08 17:05:12 +00:00
|
|
|
// TestWriteFileWrite tests writing a file and reading it back
|
2016-07-17 22:03:23 +00:00
|
|
|
func TestWriteFileWrite(t *testing.T) {
|
2016-08-20 11:43:33 +00:00
|
|
|
run.skipIfNoFUSE(t)
|
|
|
|
|
2016-07-17 22:03:23 +00:00
|
|
|
run.createFile(t, "testwrite", "data")
|
|
|
|
run.checkDir(t, "testwrite 4")
|
|
|
|
contents := run.readFile(t, "testwrite")
|
|
|
|
assert.Equal(t, "data", contents)
|
|
|
|
run.rm(t, "testwrite")
|
|
|
|
}
|
|
|
|
|
2017-05-08 17:05:12 +00:00
|
|
|
// TestWriteFileOverwrite tests overwriting a file
|
2016-07-17 22:03:23 +00:00
|
|
|
func TestWriteFileOverwrite(t *testing.T) {
|
2016-08-20 11:43:33 +00:00
|
|
|
run.skipIfNoFUSE(t)
|
|
|
|
|
2016-07-17 22:03:23 +00:00
|
|
|
run.createFile(t, "testwrite", "data")
|
|
|
|
run.checkDir(t, "testwrite 4")
|
|
|
|
run.createFile(t, "testwrite", "potato")
|
|
|
|
contents := run.readFile(t, "testwrite")
|
|
|
|
assert.Equal(t, "potato", contents)
|
|
|
|
run.rm(t, "testwrite")
|
|
|
|
}
|
|
|
|
|
2017-05-08 17:05:12 +00:00
|
|
|
// TestWriteFileFsync tests Fsync
|
2017-01-29 11:29:42 +00:00
|
|
|
//
|
|
|
|
// NB the code for this is in file.go rather than write.go
|
|
|
|
func TestWriteFileFsync(t *testing.T) {
|
|
|
|
filepath := run.path("to be synced")
|
2017-11-07 17:27:53 +00:00
|
|
|
fd, err := osCreate(filepath)
|
2017-01-29 11:29:42 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
_, err = fd.Write([]byte("hello"))
|
|
|
|
require.NoError(t, err)
|
|
|
|
err = fd.Sync()
|
|
|
|
require.NoError(t, err)
|
|
|
|
err = fd.Close()
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|