14
14
def test_drivers_mock_storage_mux_fs (monkeypatch : pytest .MonkeyPatch ):
15
15
with serve (MockStorageMux ()) as client :
16
16
with TemporaryDirectory () as tempdir :
17
+ # original file on the client to be pushed to the exporter
17
18
original = Path (tempdir ) / "original"
19
+ # new file read back from the exporter to the client
18
20
readback = Path (tempdir ) / "readback"
19
21
20
- # absolute path
22
+ # test accessing files with absolute path
23
+
24
+ # fill the original file with random bytes
21
25
original .write_bytes (randbytes (1024 * 1024 * 10 ))
26
+ # write the file to the storage on the exporter
22
27
client .write_local_file (str (original ))
28
+ # read the storage on the exporter to a local file
23
29
client .read_local_file (str (readback ))
30
+ # ensure the contents are equal
24
31
assert original .read_bytes () == readback .read_bytes ()
25
32
26
- # relative path
33
+ # test accessing files with relative path
27
34
with monkeypatch .context () as m :
28
35
m .chdir (tempdir )
29
36
@@ -39,6 +46,7 @@ def test_drivers_mock_storage_mux_fs(monkeypatch: pytest.MonkeyPatch):
39
46
40
47
41
48
def test_drivers_mock_storage_mux_http ():
49
+ # dummy HTTP server returning static test content
42
50
class StaticHandler (BaseHTTPRequestHandler ):
43
51
def do_HEAD (self ):
44
52
self .send_response (200 )
@@ -52,11 +60,13 @@ def do_GET(self):
52
60
self .wfile .write (b"testcontent" * 1000 )
53
61
54
62
with serve (MockStorageMux ()) as client :
63
+ # start the HTTP server
55
64
server = HTTPServer (("127.0.0.1" , 8080 ), StaticHandler )
56
65
server_thread = Thread (target = server .serve_forever )
57
66
server_thread .daemon = True
58
67
server_thread .start ()
59
68
69
+ # write a remote file from the http server to the exporter
60
70
fs = Operator ("http" , endpoint = "http://127.0.0.1:8080" )
61
71
client .write_file (fs , "test" )
62
72
0 commit comments