-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathftp_test.go
195 lines (157 loc) · 4.21 KB
/
ftp_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
188
189
190
191
192
193
194
195
package joint_test
// ATTENTION!
// To pass this test in its entirety should be set environment variable
// JOINT_FTP to address of test FTP-service with credentials. For example,
// `set JOINT_FTP=ftp://user:password@192.168.1.1:21`
// Then copy 'testdata' folder with ISO-file to the FTP root folder as is.
import (
"io/fs"
"os"
"testing"
jnt "github.com/schwarzlichtbezirk/joint"
)
// Environment variable name with address of FTP service.
const ftpenv = "JOINT_FTP"
func TestFtpJoint(t *testing.T) {
var err error
var ftpaddr string
if ftpaddr = os.Getenv(ftpenv); ftpaddr == "" {
t.Log("environment variable JOINT_FTP does not set, test on FTP joints skipped")
return // skip test if JOINT_FTP is not set
}
var j = &jnt.FtpJoint{}
if err = j.Make(nil, ftpaddr); err != nil {
t.Fatal(err)
}
defer j.Cleanup()
if err = j.ChangeDir("testdata"); err != nil {
t.Fatal(err)
}
var fi fs.FileInfo
if fi, err = j.Info("external.iso"); err != nil {
t.Fatal(err)
}
if fi.Size() != isosize {
t.Fatal("ISO-file size does not match")
}
if err = j.ChangeDirToParent(); err != nil {
t.Fatal(err)
}
if err = checkReadDir(j); err != nil {
t.Fatal(err)
}
}
// Check file reading in external ISO-disk placed at FTP.
func TestFtpExtReadFile(t *testing.T) {
var err error
var ftpaddr string
if ftpaddr = os.Getenv(ftpenv); ftpaddr == "" {
return // skip test if JOINT_FTP is not set
}
var j1 jnt.Joint = &jnt.FtpJoint{}
if err = j1.Make(nil, ftpaddr); 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 FTP.
func TestFtpIntReadFile(t *testing.T) {
var err error
var ftpaddr string
if ftpaddr = os.Getenv(ftpenv); ftpaddr == "" {
return // skip test if JOINT_FTP is not set
}
var j1 jnt.Joint = &jnt.FtpJoint{}
if err = j1.Make(nil, ftpaddr); 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 FTP.
func TestFtpExtDirList(t *testing.T) {
var err error
var ftpaddr string
if ftpaddr = os.Getenv(ftpenv); ftpaddr == "" {
return // skip test if JOINT_FTP is not set
}
var j1 jnt.Joint = &jnt.FtpJoint{}
if err = j1.Make(nil, ftpaddr); 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 FTP.
func TestFtpIntDirList(t *testing.T) {
var err error
var ftpaddr string
if ftpaddr = os.Getenv(ftpenv); ftpaddr == "" {
return // skip test if JOINT_FTP is not set
}
var j1 jnt.Joint = &jnt.FtpJoint{}
if err = j1.Make(nil, ftpaddr); 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 FtpJoint.
func TestFtpReadChunk(t *testing.T) {
var err error
var ftpaddr string
if ftpaddr = os.Getenv(ftpenv); ftpaddr == "" {
return // skip test if JOINT_FTP is not set
}
var j1 jnt.Joint = &jnt.FtpJoint{}
if err = j1.Make(nil, ftpaddr); err != nil {
t.Fatal(err)
}
defer j1.Cleanup()
var j2 jnt.Joint = &jnt.IsoJoint{}
if err = readChunk(j2, j1); err != nil {
t.Fatal(err)
}
}