filebrowser/filemanager_test.go.txt

50 lines
826 B
Plaintext
Raw Normal View History

2017-07-25 10:57:27 +00:00
package filemanager
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
2017-07-27 20:39:23 +00:00
"github.com/hacdias/fileutils"
2017-07-25 10:57:27 +00: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-27 20:39:23 +00:00
err = fileutils.CopyDir("./testdata", scope)
2017-07-25 10:57:27 +00:00
if err != nil {
t.Fatalf("Error copying the test data: %v", err)
}
user := DefaultUser
2017-07-27 20:39:23 +00:00
user.FileSystem = fileutils.Dir(scope)
2017-07-25 10:57:27 +00: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,
}
}