filebrowser/filemanager_test.go

50 lines
820 B
Go
Raw Normal View History

2017-07-25 10:57:27 +00:00
package filemanager
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
2017-07-26 14:57:11 +00:00
"github.com/hacdias/filemanager/dir"
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-26 14:57:11 +00:00
err = dir.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-26 14:57:11 +00:00
user.FileSystem = dir.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,
}
}