-
Notifications
You must be signed in to change notification settings - Fork 0
/
localStorage_test.go
59 lines (49 loc) · 1.02 KB
/
localStorage_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
package gtbackend
import (
"github.com/GlidingTracks/gt-backend/constant"
"os"
"testing"
)
func TestLocalStorage(t *testing.T) {
uid := "test"
filePath := "./testdata/text.txt"
fileName := "text.txt"
t.Run("Save", func(t *testing.T) {
f, err := os.Open(filePath)
if err != nil {
t.Error("Could not open test file: ", filePath)
}
_, _, err = SaveFileToLocalStorage(uid, filePath, f)
if err != nil {
t.Error("Could not save File")
}
s := checkFileExist(uid, fileName)
if !s {
t.Error("File not created")
}
})
t.Run("Delete", func(t *testing.T) {
err := DeleteFileFromLocalStorage(uid, fileName)
if err != nil {
t.Error("Could not delete File")
}
s := checkFileExist(uid, fileName)
if s {
t.Error("File not deleted")
}
})
}
func checkFileExist(uid string, fileName string) (exist bool) {
path := createFilePath(constant.LSRoot, uid, fileName)
f, err := os.Stat(path)
if err != nil {
exist = false
return
}
if f != nil {
exist = true
return
}
exist = false
return
}