filebrowser/filemanager_test.go

50 lines
826 B
Go
Raw Normal View History

2017-07-25 18:57:27 +08:00
package filemanager
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
2017-07-28 04:39:23 +08:00
"github.com/hacdias/fileutils"
2017-07-25 18:57:27 +08:00
)
type test struct {
*FileManager
Temp string
}
func (t test) Clean() {
t.db.Close()
os.RemoveAll(t.Temp)
}
func newTest(t *testing.T) *test {
temp, err := ioutil.TempDir("", t.Name())
if err != nil {
t.Fatalf("Error creating temporary directory: %v", err)
}
scope := filepath.Join(temp, "scope")
database := filepath.Join(temp, "database.db")
2017-07-28 04:39:23 +08:00
err = fileutils.CopyDir("./testdata", scope)
2017-07-25 18:57:27 +08:00
if err != nil {
t.Fatalf("Error copying the test data: %v", err)
}
user := DefaultUser
2017-07-28 04:39:23 +08:00
user.FileSystem = fileutils.Dir(scope)
2017-07-25 18:57:27 +08:00
fm, err := New(database, user)
if err != nil {
t.Fatalf("Error creating a file manager instance: %v", err)
}
return &test{
FileManager: fm,
Temp: temp,
}
}