-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstorage_test.go
More file actions
executable file
·106 lines (88 loc) · 2.04 KB
/
Copy pathstorage_test.go
File metadata and controls
executable file
·106 lines (88 loc) · 2.04 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package rubik
import (
"os"
"path/filepath"
"testing"
)
// Requirements: (scaffold script)
// 1. test/ folder inside storage folder
// 2. testFile inside test/ folder
func TestGetStorageContainers(t *testing.T) {
names := GetStorageContainers()
if len(names) != 1 {
t.Errorf("There should be only test folder inside container")
}
if names[0] != "test" {
t.Errorf("Test folder name is not in the list: %v", names)
}
}
func TestAccess(t *testing.T) {
_, err := Storage.Access("test")
if err != nil {
t.Error(err)
}
// if this dir is present remove it
testbP := filepath.Join(".", "storage", "testb")
os.RemoveAll(testbP)
// test case when folder not present -- test if Access creates it
_, err = Storage.Access("testb")
if err != nil {
t.Error(err)
}
if f, _ := os.Stat(testbP); f == nil {
t.Error("Access() did not create a folder")
}
}
func TestRemove(t *testing.T) {
err := Storage.Remove("testb")
if err != nil {
t.Error(err)
}
}
func TestFsGet(t *testing.T) {
fs, err := Storage.Access("test")
if err != nil {
t.Error(err)
}
fileb := fs.Get("testFile")
if fileb == nil {
t.Errorf("Did not read file inside the file store")
} else if string(fileb) != "test" {
t.Errorf("File content is read wrong: %s", string(fileb))
}
}
func TestFsPut(t *testing.T) {
fs, err := Storage.Access("test")
if err != nil {
t.Error(err)
}
testFilebP := filepath.Join(".", "storage", "test", "testFileb")
os.Remove(testFilebP)
err = fs.Put("testFileb", []byte("testb"))
if err != nil {
t.Error(err)
}
if f, _ := os.Stat(testFilebP); f == nil {
t.Error("FileStore.Put() did not write test/testFileb file")
}
}
func TestFsHas(t *testing.T) {
fs, err := Storage.Access("test")
if err != nil {
t.Error(err)
}
hasFile := fs.Has("testFileb")
if !hasFile {
t.Error("FileStore.Has() says testFileb not present; which was written in previous test")
}
}
func TestFsDelete(t *testing.T) {
fs, err := Storage.Access("test")
if err != nil {
t.Error(err)
}
err = fs.Delete("testFileb")
if err != nil {
t.Error(err)
}
}