1+ #! /usr/bin/env bats
2+
3+ load helpers
4+
5+ SPLITFDSTREAM_SERVER_PID=
6+
7+ splitfdstream_teardown () {
8+ if [[ -n " $SPLITFDSTREAM_SERVER_PID " ]]; then
9+ kill $SPLITFDSTREAM_SERVER_PID 2> /dev/null || true
10+ wait $SPLITFDSTREAM_SERVER_PID 2> /dev/null || true
11+ SPLITFDSTREAM_SERVER_PID=
12+ fi
13+ }
14+
15+ @test " splitfdstream json-rpc-server and apply-splitfdstream" {
16+ case " $STORAGE_DRIVER " in
17+ overlay* )
18+ ;;
19+ * )
20+ skip " driver $STORAGE_DRIVER does not support splitfdstream"
21+ ;;
22+ esac
23+
24+ # Create and populate a test layer
25+ populate
26+
27+ # Get the socket path from runroot
28+ local runroot=` storage status 2>&1 | awk ' /^Run Root:/{print $3}' `
29+ local socket_path=" $runroot /json-rpc.sock"
30+
31+ # Start the JSON-RPC server in the background
32+ storage json-rpc-server --socket " $socket_path " &
33+ SPLITFDSTREAM_SERVER_PID=$!
34+
35+ # Wait for socket to be created (max 10 seconds)
36+ local count=0
37+ while [[ ! -S " $socket_path " && $count -lt 50 ]]; do
38+ sleep 0.2
39+ count=$(( count + 1 ))
40+ done
41+
42+ # Check that the socket exists
43+ [ -S " $socket_path " ]
44+
45+ # Create a new layer using apply-splitfdstream
46+ # This should connect to our JSON-RPC server and fetch the layer
47+ run storage --debug=false apply-splitfdstream --socket " $socket_path " " $lowerlayer "
48+ echo " apply-splitfdstream output: $output "
49+ [ " $status " -eq 0 ]
50+ [ " $output " != " " ]
51+
52+ applied_layer=" $output "
53+
54+ # Verify the layer was created
55+ run storage --debug=false layers
56+ [ " $status " -eq 0 ]
57+ [[ " $output " =~ " $applied_layer " ]]
58+
59+ # Check that we can mount the applied layer
60+ run storage --debug=false mount " $applied_layer "
61+ [ " $status " -eq 0 ]
62+ [ " $output " != " " ]
63+ local applied_mount=" $output "
64+
65+ # Verify some expected content exists (from populate function)
66+ [ -f " $applied_mount /layer1file1" ]
67+ [ -f " $applied_mount /layer1file2" ]
68+ [ -d " $applied_mount /layerdir1" ]
69+
70+ # Unmount the layer
71+ run storage unmount " $applied_layer "
72+ [ " $status " -eq 0 ]
73+
74+ # Clean up
75+ splitfdstream_teardown
76+ }
77+
78+ @test " splitfdstream server socket path uses runroot" {
79+ case " $STORAGE_DRIVER " in
80+ overlay* )
81+ ;;
82+ * )
83+ skip " driver $STORAGE_DRIVER does not support splitfdstream"
84+ ;;
85+ esac
86+
87+ # Get the expected socket path from runroot
88+ local runroot=` storage status 2>&1 | awk ' /^Run Root:/{print $3}' `
89+ local expected_socket=" $runroot /json-rpc.sock"
90+
91+ # Start the JSON-RPC server in the background
92+ storage json-rpc-server &
93+ SPLITFDSTREAM_SERVER_PID=$!
94+
95+ # Wait for socket to be created (max 10 seconds)
96+ local count=0
97+ while [[ ! -S " $expected_socket " && $count -lt 50 ]]; do
98+ sleep 0.2
99+ count=$(( count + 1 ))
100+ done
101+
102+ # Verify the socket is created in the correct location
103+ [ -S " $expected_socket " ]
104+
105+ # Clean up
106+ splitfdstream_teardown
107+ }
0 commit comments