-
Notifications
You must be signed in to change notification settings - Fork 1
/
fm_test.go
75 lines (67 loc) · 1.52 KB
/
fm_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package gofm
import (
"github.com/kyaxcorp/gofile/driver/filesystem"
"gorm.io/driver/postgres"
"gorm.io/gorm"
"log"
"testing"
)
func getTestDBClient() (*gorm.DB, error) {
dsn := "host=172.29.24.104 user=filemanager password=filemanager dbname=filemanager port=26257 sslmode=require TimeZone=Europe/Chisinau"
return gorm.Open(postgres.Open(dsn), &gorm.Config{})
}
func TestFileManager(t *testing.T) {
// define a storage location
loc := Location{
Name: "local",
Driver: &filesystem.Location{
DirPath: "./newpath/loc1",
},
}
loc2 := Location{
Name: "local2",
Driver: &filesystem.Location{
DirPath: "./newpath/loc2",
},
}
// Get the DB client
db, _err := getTestDBClient()
if _err != nil {
t.Error(_err)
return
}
// Define the file manager
fm := GetInstance(&FileManager{
DBClient: db,
DBAutoMigrate: true,
Name: "instance1",
// Define file manager locations
Locations: Locations{loc, loc2},
})
file := fm.NewFile()
//file.Name = "my super InputFile"
//file.Description = "my description"
file.InputFilePath = "./LICENSE"
file.Locations = []NewFileLocation{
{
// Define the location instance name
LocationName: "local",
},
{
// Define the location instance name
LocationName: "local2",
},
}
f, _err := file.Save()
if _err != nil {
t.Error(_err)
return
}
log.Println("id", f.ID)
foundFile, _err := fm.FindFile(FindFileOptions{ID: f.ID})
if _err != nil {
t.Error(_err, fm.GetInternalError())
return
}
log.Println("found file ID", foundFile.ID)
}