aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Unterwurzacher2016-02-07 10:55:13 +0100
committerJakob Unterwurzacher2016-02-07 10:55:13 +0100
commit3a4922b5d747d54c9cb62833c9d69acb96b072f6 (patch)
tree39eea52028ea5a60f1e0cce47be79a88f0a8169e
parente111e20649cfacd7b02dd454d75db879aa2ca53c (diff)
Add tests for long name creation and renaming (currently failing, obviously)
-rw-r--r--integration_tests/helpers.go36
-rw-r--r--integration_tests/main_test.go48
-rw-r--r--internal/toggledlog/log.go10
-rw-r--r--main.go2
4 files changed, 90 insertions, 6 deletions
diff --git a/integration_tests/helpers.go b/integration_tests/helpers.go
index e5458c9..4adce97 100644
--- a/integration_tests/helpers.go
+++ b/integration_tests/helpers.go
@@ -1,6 +1,7 @@
package integration_tests
import (
+ "path/filepath"
"crypto/md5"
"encoding/hex"
"fmt"
@@ -176,3 +177,38 @@ func testRename(t *testing.T, plainDir string) {
}
syscall.Unlink(file2)
}
+
+// verifyExistence - check in 3 ways that "path" exists:
+// stat, open, readdir
+func verifyExistence(path string) bool {
+
+ // Check that file can be stated
+ _, err := os.Stat(path)
+ if err != nil {
+ //t.Log(err)
+ return false
+ }
+
+ // Check that file can be opened
+ fd, err := os.Open(path)
+ if err != nil {
+ //t.Log(err)
+ return false
+ }
+ fd.Close()
+
+ // Check that file shows up in directory listing
+ dir := filepath.Dir(path)
+ name := filepath.Base(path)
+ fi, err := ioutil.ReadDir(dir)
+ if err != nil {
+ //t.Log(err)
+ return false
+ }
+ for _, i := range(fi) {
+ if i.Name() == name {
+ return true
+ }
+ }
+ return false
+}
diff --git a/integration_tests/main_test.go b/integration_tests/main_test.go
index 03b26f9..6ac03e1 100644
--- a/integration_tests/main_test.go
+++ b/integration_tests/main_test.go
@@ -3,6 +3,7 @@ package integration_tests
// File reading, writing, modification, truncate
import (
+ "syscall"
"bytes"
"crypto/md5"
"encoding/hex"
@@ -350,3 +351,50 @@ func TestDirOverwrite(t *testing.T) {
t.Fatal(err)
}
}
+
+func TestLongNames(t *testing.T) {
+ // Create
+ wd := defaultPlainDir
+ n255x := string(bytes.Repeat([]byte("x"), 255))
+ f, err := os.Create(wd+n255x)
+ if err != nil {
+ t.Fatalf("Could not create n255x")
+ }
+ f.Close()
+ if !verifyExistence(wd+n255x) {
+ t.Errorf("n255x is not in directory listing")
+ }
+ // Rename long to long
+ n255y := string(bytes.Repeat([]byte("y"), 255))
+ err = os.Rename(wd+n255x, wd+n255y)
+ if err != nil {
+ t.Fatalf("Could not rename n255x to n255y")
+ }
+ if !verifyExistence(wd+n255y) {
+ t.Errorf("n255y is not in directory listing")
+ }
+ // Rename long to short
+ err = os.Rename(wd+n255y, wd+"short")
+ if err != nil {
+ t.Fatalf("Could not rename n255y to short")
+ }
+ if !verifyExistence(wd+"short") {
+ t.Errorf("short is not in directory listing")
+ }
+ // Rename short to long
+ err = os.Rename(wd+"short", wd+n255x)
+ if err != nil {
+ t.Fatalf("Could not rename short to n255x")
+ }
+ if !verifyExistence(wd+n255x) {
+ t.Errorf("255x is not in directory listing II")
+ }
+ // Unlink
+ err = syscall.Unlink(wd+n255x)
+ if err != nil {
+ t.Fatalf("Could not unlink n255x")
+ }
+ if verifyExistence(wd+n255x) {
+ t.Errorf("n255x still there after unlink")
+ }
+}
diff --git a/internal/toggledlog/log.go b/internal/toggledlog/log.go
index 4a2ad03..5e5191a 100644
--- a/internal/toggledlog/log.go
+++ b/internal/toggledlog/log.go
@@ -25,7 +25,7 @@ type toggledLogger struct {
// Enable or disable output
Enabled bool
// Panic after logging a message, useful in regression tests
- PanicAfter bool
+ Wpanic bool
*log.Logger
}
@@ -34,8 +34,8 @@ func (l *toggledLogger) Printf(format string, v ...interface{}) {
return
}
l.Logger.Printf(format, v...)
- if l.PanicAfter {
- panic("PanicAfter: " + fmt.Sprintf(format, v...))
+ if l.Wpanic {
+ panic("-wpanic turns warning into panic: " + fmt.Sprintf(format, v...))
}
}
func (l *toggledLogger) Println(v ...interface{}) {
@@ -43,8 +43,8 @@ func (l *toggledLogger) Println(v ...interface{}) {
return
}
l.Logger.Println(v...)
- if l.PanicAfter {
- panic("PanicAfter: " + fmt.Sprintln(v...))
+ if l.Wpanic {
+ panic("-wpanic turns warning into panic: " + fmt.Sprintln(v...))
}
}
diff --git a/main.go b/main.go
index 2c1a26c..ef93440 100644
--- a/main.go
+++ b/main.go
@@ -192,7 +192,7 @@ func main() {
toggledlog.Debug.Printf("Debug output enabled")
}
if args.wpanic {
- toggledlog.Warn.PanicAfter = true
+ toggledlog.Warn.Wpanic = true
toggledlog.Debug.Printf("Panicing on warnings")
}
// Every operation below requires CIPHERDIR. Check that we have it.