-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathtest_integration.rs
386 lines (318 loc) · 10.6 KB
/
test_integration.rs
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
#[cfg(feature = "integration-test")]
mod common;
#[cfg(feature = "integration-test")]
mod test {
use crate::common::{assert_bufs_equal, setup, TEST_FILE_INTS};
use bytes::{BufMut, BytesMut};
use hdfs_native::{client::FileStatus, minidfs::DfsFeatures, Client, Result, WriteOptions};
use serial_test::serial;
use std::collections::HashSet;
#[tokio::test]
#[serial]
async fn test_basic() {
test_with_features(&HashSet::new()).await.unwrap();
}
#[tokio::test]
#[serial]
#[cfg(feature = "kerberos")]
async fn test_security_kerberos() {
test_with_features(&HashSet::from([DfsFeatures::Security]))
.await
.unwrap();
}
#[tokio::test]
#[serial]
async fn test_security_token() {
test_with_features(&HashSet::from([DfsFeatures::Security, DfsFeatures::Token]))
.await
.unwrap();
}
#[tokio::test]
#[serial]
#[cfg(feature = "kerberos")]
async fn test_integrity_kerberos() {
test_with_features(&HashSet::from([
DfsFeatures::Security,
DfsFeatures::Integrity,
]))
.await
.unwrap();
}
#[tokio::test]
#[serial]
async fn test_integrity_token() {
test_with_features(&HashSet::from([
DfsFeatures::Security,
DfsFeatures::Token,
DfsFeatures::Integrity,
]))
.await
.unwrap();
}
#[tokio::test]
#[serial]
#[cfg(feature = "kerberos")]
async fn test_privacy_kerberos() {
test_with_features(&HashSet::from([
DfsFeatures::Security,
DfsFeatures::Privacy,
]))
.await
.unwrap();
}
#[tokio::test]
#[serial]
async fn test_privacy_token() {
test_with_features(&HashSet::from([
DfsFeatures::Security,
DfsFeatures::Token,
DfsFeatures::Privacy,
]))
.await
.unwrap();
}
#[tokio::test]
#[serial]
#[cfg(feature = "kerberos")]
async fn test_aes() {
test_with_features(&HashSet::from([
DfsFeatures::Security,
DfsFeatures::Privacy,
DfsFeatures::AES,
]))
.await
.unwrap();
}
#[tokio::test]
#[serial]
#[cfg(feature = "kerberos")]
async fn test_forced_data_transfer_encryption() {
// DataTransferEncryption enabled but privacy isn't, still force encryption
test_with_features(&HashSet::from([
DfsFeatures::Security,
DfsFeatures::DataTransferEncryption,
]))
.await
.unwrap();
}
#[tokio::test]
#[serial]
#[cfg(feature = "kerberos")]
async fn test_data_transfer_encryption() {
test_with_features(&HashSet::from([
DfsFeatures::Security,
DfsFeatures::Privacy,
DfsFeatures::DataTransferEncryption,
]))
.await
.unwrap();
}
#[tokio::test]
#[serial]
#[cfg(feature = "kerberos")]
async fn test_data_transfer_encryption_aes() {
test_with_features(&HashSet::from([
DfsFeatures::Security,
DfsFeatures::Privacy,
DfsFeatures::DataTransferEncryption,
DfsFeatures::AES,
]))
.await
.unwrap();
}
#[tokio::test]
#[serial]
async fn test_basic_ha() {
test_with_features(&HashSet::from([DfsFeatures::HA]))
.await
.unwrap();
}
#[tokio::test]
#[serial]
#[cfg(feature = "kerberos")]
async fn test_security_privacy_ha() {
test_with_features(&HashSet::from([
DfsFeatures::Security,
DfsFeatures::Privacy,
DfsFeatures::HA,
]))
.await
.unwrap();
}
#[tokio::test]
#[serial]
async fn test_security_token_ha() {
test_with_features(&HashSet::from([
DfsFeatures::Security,
DfsFeatures::Token,
DfsFeatures::HA,
]))
.await
.unwrap();
}
#[tokio::test]
#[serial]
async fn test_rbf() {
test_with_features(&HashSet::from([DfsFeatures::RBF]))
.await
.unwrap();
}
pub async fn test_with_features(features: &HashSet<DfsFeatures>) -> Result<()> {
let _ = env_logger::builder().is_test(true).try_init();
let _dfs = setup(features);
let client = Client::default();
test_file_info(&client).await?;
test_listing(&client).await?;
test_rename(&client).await?;
test_dirs(&client).await?;
test_read_write(&client).await?;
// We use writing to create files, so do this after
test_recursive_listing(&client).await?;
test_set_times(&client).await?;
test_set_owner(&client).await?;
Ok(())
}
async fn test_file_info(client: &Client) -> Result<()> {
let status = client.get_file_info("/testfile").await?;
// Path is empty, I guess because we already know what file we just got the info for?
assert_eq!(status.path, "/testfile");
assert_eq!(status.length, TEST_FILE_INTS * 4);
Ok(())
}
async fn test_listing(client: &Client) -> Result<()> {
let statuses: Vec<FileStatus> = client
.list_status("/", false)
.await?
.into_iter()
// Only include files, since federation things could result in folders being created
.filter(|s| !s.isdir)
.collect();
assert_eq!(statuses.len(), 1);
let status = &statuses[0];
assert_eq!(status.path, "/testfile");
assert_eq!(status.length, TEST_FILE_INTS * 4);
Ok(())
}
async fn test_rename(client: &Client) -> Result<()> {
client.rename("/testfile", "/testfile2", false).await?;
assert!(client.list_status("/testfile", false).await.is_err());
assert_eq!(client.list_status("/testfile2", false).await?.len(), 1);
client.rename("/testfile2", "/testfile", false).await?;
assert!(client.list_status("/testfile2", false).await.is_err());
assert_eq!(client.list_status("/testfile", false).await?.len(), 1);
Ok(())
}
async fn test_dirs(client: &Client) -> Result<()> {
client.mkdirs("/testdir", 0o755, false).await?;
assert!(client
.list_status("/testdir", false)
.await
.is_ok_and(|s| s.is_empty()));
client.delete("/testdir", false).await?;
assert!(client.list_status("/testdir", false).await.is_err());
client.mkdirs("/testdir1/testdir2", 0o755, true).await?;
assert!(client
.list_status("/testdir1", false)
.await
.is_ok_and(|s| s.len() == 1));
// Deleting non-empty dir without recursive fails
assert!(client.delete("/testdir1", false).await.is_err());
assert!(client.delete("/testdir1", true).await.is_ok_and(|r| r));
Ok(())
}
async fn test_read_write(client: &Client) -> Result<()> {
let write_options = WriteOptions::default().overwrite(true);
// Create an empty file
let mut writer = client.create("/newfile", &write_options).await?;
writer.close().await?;
assert_eq!(client.get_file_info("/newfile").await?.length, 0);
let mut writer = client.create("/newfile", &write_options).await?;
let mut file_contents = BytesMut::new();
let mut data = BytesMut::new();
for i in 0..1024 {
file_contents.put_i32(i);
data.put_i32(i);
}
let buf = data.freeze();
writer.write(buf).await?;
writer.close().await?;
assert_eq!(client.get_file_info("/newfile").await?.length, 4096);
let mut reader = client.read("/newfile").await?;
let read_data = reader.read(reader.file_length()).await?;
assert_bufs_equal(&file_contents, &read_data, None);
let mut data = BytesMut::new();
for i in 0..1024 {
file_contents.put_i32(i);
data.put_i32(i);
}
let buf = data.freeze();
let mut writer = client.append("/newfile").await?;
writer.write(buf).await?;
writer.close().await?;
let mut reader = client.read("/newfile").await?;
let read_data = reader.read(reader.file_length()).await?;
assert_bufs_equal(&file_contents, &read_data, None);
assert!(client.delete("/newfile", false).await.is_ok_and(|r| r));
Ok(())
}
async fn test_recursive_listing(client: &Client) -> Result<()> {
let write_options = WriteOptions::default();
client.mkdirs("/dir/nested", 0o755, true).await?;
client
.create("/dir/file1", &write_options)
.await?
.close()
.await?;
client
.create("/dir/nested/file2", &write_options)
.await?
.close()
.await?;
client
.create("/dir/nested/file3", &write_options)
.await?
.close()
.await?;
let statuses = client.list_status("/dir", true).await?;
assert_eq!(statuses.len(), 4);
client.delete("/dir", true).await?;
Ok(())
}
async fn test_set_times(client: &Client) -> Result<()> {
client
.create("/test", WriteOptions::default())
.await?
.close()
.await?;
let mtime = 1717641455;
let atime = 1717641456;
client.set_times("/test", mtime, atime).await?;
let file_info = client.get_file_info("/test").await?;
assert_eq!(file_info.modification_time, mtime);
assert_eq!(file_info.access_time, atime);
client.delete("/test", false).await?;
Ok(())
}
async fn test_set_owner(client: &Client) -> Result<()> {
client
.create("/test", WriteOptions::default())
.await?
.close()
.await?;
client
.set_owner("/test", Some("testuser"), Some("testgroup"))
.await?;
let file_info = client.get_file_info("/test").await?;
assert_eq!(file_info.owner, "testuser");
assert_eq!(file_info.group, "testgroup");
client.set_owner("/test", Some("testuser2"), None).await?;
let file_info = client.get_file_info("/test").await?;
assert_eq!(file_info.owner, "testuser2");
assert_eq!(file_info.group, "testgroup");
client.set_owner("/test", None, Some("testgroup2")).await?;
let file_info = client.get_file_info("/test").await?;
assert_eq!(file_info.owner, "testuser2");
assert_eq!(file_info.group, "testgroup2");
Ok(())
}
}