-
Notifications
You must be signed in to change notification settings - Fork 0
/
dav_test.go
187 lines (151 loc) · 4.13 KB
/
dav_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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
package joint_test
// ATTENTION!
// To pass this test in its entirety should be set environment variable
// JOINT_DAV to URL of test WebDAV-service with credentials. For example,
// `set JOINT_DAV=https://user:password@example.keenetic.link/webdav/`
// Then copy 'testdata' folder with ISO-file to the WebDAV root folder as is.
import (
"io/fs"
"os"
"testing"
jnt "github.com/schwarzlichtbezirk/joint"
)
// Environment variable name with address of WebDAV service.
const davenv = "JOINT_DAV"
func TestDavJoint(t *testing.T) {
var err error
var davaddr string
if davaddr = os.Getenv(davenv); davaddr == "" {
t.Log("environment variable JOINT_DAV does not set, test on WebDAV joints skipped")
return // skip test if JOINT_DAV is not set
}
var j = &jnt.DavJoint{}
if err = j.Make(nil, davaddr); err != nil {
t.Fatal(err)
}
defer j.Cleanup()
var fi fs.FileInfo
if fi, err = j.Info("testdata/external.iso"); err != nil {
t.Fatal(err)
}
if fi.Size() != isosize {
t.Fatal("ISO-file size does not match")
}
if err = checkReadDir(j); err != nil {
t.Fatal(err)
}
}
// Check file reading in external ISO-disk placed at WebDAV.
func TestDavExtReadFile(t *testing.T) {
var err error
var davaddr string
if davaddr = os.Getenv(davenv); davaddr == "" {
return // skip test if JOINT_DAV is not set
}
var j1 jnt.Joint = &jnt.DavJoint{}
if err = j1.Make(nil, davaddr); err != nil {
t.Fatal(err)
}
defer j1.Cleanup() // Cleanup can be called twice
var j2 jnt.Joint = &jnt.IsoJoint{}
if err = j2.Make(j1, "testdata/external.iso"); err != nil {
t.Fatal(err)
}
defer j2.Cleanup()
for _, fpath := range extfiles {
if err = checkFile(j2, fpath); err != nil {
t.Fatal(err)
}
}
}
// Check file reading in internal ISO-disk placed at WebDAV.
func TestDavIntReadFile(t *testing.T) {
var err error
var davaddr string
if davaddr = os.Getenv(davenv); davaddr == "" {
return // skip test if JOINT_DAV is not set
}
var j1 jnt.Joint = &jnt.DavJoint{}
if err = j1.Make(nil, davaddr); err != nil {
t.Fatal(err)
}
var j2 jnt.Joint = &jnt.IsoJoint{}
if err = j2.Make(j1, "testdata/external.iso"); err != nil {
t.Fatal(err)
}
var j3 jnt.Joint = &jnt.IsoJoint{}
if err = j3.Make(j2, "disk/internal.iso"); err != nil {
t.Fatal(err)
}
defer j3.Cleanup() // only top-level joint must be called for Cleanup
for _, fpath := range intfiles {
if err = checkFile(j3, fpath); err != nil {
t.Fatal(err)
}
}
}
// Check directory list in external ISO-disk placed at WebDAV.
func TestDavExtDirList(t *testing.T) {
var err error
var davaddr string
if davaddr = os.Getenv(davenv); davaddr == "" {
return // skip test if JOINT_DAV is not set
}
var j1 jnt.Joint = &jnt.DavJoint{}
if err = j1.Make(nil, davaddr); err != nil {
t.Fatal(err)
}
var j2 jnt.Joint = &jnt.IsoJoint{}
if err = j2.Make(j1, "testdata/external.iso"); err != nil {
t.Fatal(err)
}
defer j2.Cleanup()
for fpath := range extdirs {
if err = checkDir(j2, fpath, extdirs); err != nil {
t.Fatal(err)
}
}
}
// Check directory list in internal ISO-disk placed at WebDAV.
func TestDavIntDirList(t *testing.T) {
var err error
var davaddr string
if davaddr = os.Getenv(davenv); davaddr == "" {
return // skip test if JOINT_DAV is not set
}
var j1 jnt.Joint = &jnt.DavJoint{}
if err = j1.Make(nil, davaddr); err != nil {
t.Fatal(err)
}
var j2 jnt.Joint = &jnt.IsoJoint{}
if err = j2.Make(j1, "testdata/external.iso"); err != nil {
t.Fatal(err)
}
var j3 jnt.Joint = &jnt.IsoJoint{}
if err = j3.Make(j2, "disk/internal.iso"); err != nil {
t.Fatal(err)
}
defer j3.Cleanup() // only top-level joint must be called for Cleanup
for fpath := range intdirs {
if err = checkDir(j3, fpath, intdirs); err != nil {
t.Fatal(err)
}
}
}
// Read files chunks on DavJoint.
func TestDavReadChunk(t *testing.T) {
var err error
var davaddr string
if davaddr = os.Getenv(davenv); davaddr == "" {
return // skip test if JOINT_DAV is not set
}
var j1 jnt.Joint = &jnt.DavJoint{}
if err = j1.Make(nil, davaddr); err != nil {
t.Fatal(err)
}
defer j1.Cleanup()
var j2 jnt.Joint = &jnt.IsoJoint{}
if err = readChunk(j2, j1); err != nil {
t.Fatal(err)
}
}