summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/spf13/afero/mem/file_test.go
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2017-11-13 09:09:58 -0800
committerGitHub <noreply@github.com>2017-11-13 09:09:58 -0800
commit1329aa51b605cb54ba9aae3a82a0a87b881fb7b3 (patch)
tree93cbf354ab894a560fc2cef8ef685d681b4ff889 /vendor/github.com/spf13/afero/mem/file_test.go
parent7304a61ef597970be3031b14e652fb3a4df44304 (diff)
downloadchat-1329aa51b605cb54ba9aae3a82a0a87b881fb7b3.tar.gz
chat-1329aa51b605cb54ba9aae3a82a0a87b881fb7b3.tar.bz2
chat-1329aa51b605cb54ba9aae3a82a0a87b881fb7b3.zip
Updating server dependancies. (#7816)
Diffstat (limited to 'vendor/github.com/spf13/afero/mem/file_test.go')
-rw-r--r--vendor/github.com/spf13/afero/mem/file_test.go154
1 files changed, 154 insertions, 0 deletions
diff --git a/vendor/github.com/spf13/afero/mem/file_test.go b/vendor/github.com/spf13/afero/mem/file_test.go
new file mode 100644
index 000000000..5769067a7
--- /dev/null
+++ b/vendor/github.com/spf13/afero/mem/file_test.go
@@ -0,0 +1,154 @@
+package mem
+
+import (
+ "testing"
+ "time"
+)
+
+func TestFileDataNameRace(t *testing.T) {
+ t.Parallel()
+ const someName = "someName"
+ const someOtherName = "someOtherName"
+ d := FileData{
+ name: someName,
+ }
+
+ if d.Name() != someName {
+ t.Errorf("Failed to read correct Name, was %v", d.Name())
+ }
+
+ ChangeFileName(&d, someOtherName)
+ if d.Name() != someOtherName {
+ t.Errorf("Failed to set Name, was %v", d.Name())
+ }
+
+ go func() {
+ ChangeFileName(&d, someName)
+ }()
+
+ if d.Name() != someName && d.Name() != someOtherName {
+ t.Errorf("Failed to read either Name, was %v", d.Name())
+ }
+}
+
+func TestFileDataModTimeRace(t *testing.T) {
+ t.Parallel()
+ someTime := time.Now()
+ someOtherTime := someTime.Add(1 * time.Minute)
+
+ d := FileData{
+ modtime: someTime,
+ }
+
+ s := FileInfo{
+ FileData: &d,
+ }
+
+ if s.ModTime() != someTime {
+ t.Errorf("Failed to read correct value, was %v", s.ModTime())
+ }
+
+ SetModTime(&d, someOtherTime)
+ if s.ModTime() != someOtherTime {
+ t.Errorf("Failed to set ModTime, was %v", s.ModTime())
+ }
+
+ go func() {
+ SetModTime(&d, someTime)
+ }()
+
+ if s.ModTime() != someTime && s.ModTime() != someOtherTime {
+ t.Errorf("Failed to read either modtime, was %v", s.ModTime())
+ }
+}
+
+func TestFileDataModeRace(t *testing.T) {
+ t.Parallel()
+ const someMode = 0777
+ const someOtherMode = 0660
+
+ d := FileData{
+ mode: someMode,
+ }
+
+ s := FileInfo{
+ FileData: &d,
+ }
+
+ if s.Mode() != someMode {
+ t.Errorf("Failed to read correct value, was %v", s.Mode())
+ }
+
+ SetMode(&d, someOtherMode)
+ if s.Mode() != someOtherMode {
+ t.Errorf("Failed to set Mode, was %v", s.Mode())
+ }
+
+ go func() {
+ SetMode(&d, someMode)
+ }()
+
+ if s.Mode() != someMode && s.Mode() != someOtherMode {
+ t.Errorf("Failed to read either mode, was %v", s.Mode())
+ }
+}
+
+func TestFileDataIsDirRace(t *testing.T) {
+ t.Parallel()
+
+ d := FileData{
+ dir: true,
+ }
+
+ s := FileInfo{
+ FileData: &d,
+ }
+
+ if s.IsDir() != true {
+ t.Errorf("Failed to read correct value, was %v", s.IsDir())
+ }
+
+ go func() {
+ s.Lock()
+ d.dir = false
+ s.Unlock()
+ }()
+
+ //just logging the value to trigger a read:
+ t.Logf("Value is %v", s.IsDir())
+}
+
+func TestFileDataSizeRace(t *testing.T) {
+ t.Parallel()
+
+ const someData = "Hello"
+ const someOtherDataSize = "Hello World"
+
+ d := FileData{
+ data: []byte(someData),
+ dir: false,
+ }
+
+ s := FileInfo{
+ FileData: &d,
+ }
+
+ if s.Size() != int64(len(someData)) {
+ t.Errorf("Failed to read correct value, was %v", s.Size())
+ }
+
+ go func() {
+ s.Lock()
+ d.data = []byte(someOtherDataSize)
+ s.Unlock()
+ }()
+
+ //just logging the value to trigger a read:
+ t.Logf("Value is %v", s.Size())
+
+ //Testing the Dir size case
+ d.dir = true
+ if s.Size() != int64(42) {
+ t.Errorf("Failed to read correct value for dir, was %v", s.Size())
+ }
+}