Add tests for long name creation and renaming (currently failing, obviously)

This commit is contained in:
Jakob Unterwurzacher 2016-02-07 10:55:13 +01:00
parent e111e20649
commit 3a4922b5d7
4 changed files with 90 additions and 6 deletions

View File

@ -1,6 +1,7 @@
package integration_tests package integration_tests
import ( import (
"path/filepath"
"crypto/md5" "crypto/md5"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
@ -176,3 +177,38 @@ func testRename(t *testing.T, plainDir string) {
} }
syscall.Unlink(file2) 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
}

View File

@ -3,6 +3,7 @@ package integration_tests
// File reading, writing, modification, truncate // File reading, writing, modification, truncate
import ( import (
"syscall"
"bytes" "bytes"
"crypto/md5" "crypto/md5"
"encoding/hex" "encoding/hex"
@ -350,3 +351,50 @@ func TestDirOverwrite(t *testing.T) {
t.Fatal(err) 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")
}
}

View File

@ -25,7 +25,7 @@ type toggledLogger struct {
// Enable or disable output // Enable or disable output
Enabled bool Enabled bool
// Panic after logging a message, useful in regression tests // Panic after logging a message, useful in regression tests
PanicAfter bool Wpanic bool
*log.Logger *log.Logger
} }
@ -34,8 +34,8 @@ func (l *toggledLogger) Printf(format string, v ...interface{}) {
return return
} }
l.Logger.Printf(format, v...) l.Logger.Printf(format, v...)
if l.PanicAfter { if l.Wpanic {
panic("PanicAfter: " + fmt.Sprintf(format, v...)) panic("-wpanic turns warning into panic: " + fmt.Sprintf(format, v...))
} }
} }
func (l *toggledLogger) Println(v ...interface{}) { func (l *toggledLogger) Println(v ...interface{}) {
@ -43,8 +43,8 @@ func (l *toggledLogger) Println(v ...interface{}) {
return return
} }
l.Logger.Println(v...) l.Logger.Println(v...)
if l.PanicAfter { if l.Wpanic {
panic("PanicAfter: " + fmt.Sprintln(v...)) panic("-wpanic turns warning into panic: " + fmt.Sprintln(v...))
} }
} }

View File

@ -192,7 +192,7 @@ func main() {
toggledlog.Debug.Printf("Debug output enabled") toggledlog.Debug.Printf("Debug output enabled")
} }
if args.wpanic { if args.wpanic {
toggledlog.Warn.PanicAfter = true toggledlog.Warn.Wpanic = true
toggledlog.Debug.Printf("Panicing on warnings") toggledlog.Debug.Printf("Panicing on warnings")
} }
// Every operation below requires CIPHERDIR. Check that we have it. // Every operation below requires CIPHERDIR. Check that we have it.