@@ -98,82 +98,82 @@ pub fn create_image(
9898}
9999
100100#[ cfg( test) ]
101- use crate :: image:: { LeafContent , RegularFile , Stat } ;
102- #[ cfg( test) ]
103- use std:: { cell:: RefCell , collections:: BTreeMap , io:: BufRead , path:: PathBuf } ;
104-
105- #[ cfg( test) ]
106- fn file_entry ( path : & str ) -> oci:: tar:: TarEntry {
107- oci:: tar:: TarEntry {
108- path : PathBuf :: from ( path) ,
109- stat : Stat {
110- st_mode : 0o644 ,
111- st_uid : 0 ,
112- st_gid : 0 ,
113- st_mtim_sec : 0 ,
114- xattrs : RefCell :: new ( BTreeMap :: new ( ) ) ,
115- } ,
116- item : oci:: tar:: TarItem :: Leaf ( LeafContent :: Regular ( RegularFile :: Inline ( [ ] . into ( ) ) ) ) ,
101+ mod test {
102+ use crate :: image:: { LeafContent , RegularFile , Stat } ;
103+ use std:: { cell:: RefCell , collections:: BTreeMap , io:: BufRead , path:: PathBuf } ;
104+
105+ use super :: * ;
106+
107+ fn file_entry ( path : & str ) -> oci:: tar:: TarEntry {
108+ oci:: tar:: TarEntry {
109+ path : PathBuf :: from ( path) ,
110+ stat : Stat {
111+ st_mode : 0o644 ,
112+ st_uid : 0 ,
113+ st_gid : 0 ,
114+ st_mtim_sec : 0 ,
115+ xattrs : RefCell :: new ( BTreeMap :: new ( ) ) ,
116+ } ,
117+ item : oci:: tar:: TarItem :: Leaf ( LeafContent :: Regular ( RegularFile :: Inline ( [ ] . into ( ) ) ) ) ,
118+ }
117119 }
118- }
119120
120- # [ cfg ( test ) ]
121- fn dir_entry ( path : & str ) -> oci:: tar:: TarEntry {
122- oci :: tar :: TarEntry {
123- path : PathBuf :: from ( path ) ,
124- stat : Stat {
125- st_mode : 0o755 ,
126- st_uid : 0 ,
127- st_gid : 0 ,
128- st_mtim_sec : 0 ,
129- xattrs : RefCell :: new ( BTreeMap :: new ( ) ) ,
130- } ,
131- item : oci :: tar :: TarItem :: Directory ,
121+ fn dir_entry ( path : & str ) -> oci :: tar :: TarEntry {
122+ oci:: tar:: TarEntry {
123+ path : PathBuf :: from ( path ) ,
124+ stat : Stat {
125+ st_mode : 0o755 ,
126+ st_uid : 0 ,
127+ st_gid : 0 ,
128+ st_mtim_sec : 0 ,
129+ xattrs : RefCell :: new ( BTreeMap :: new ( ) ) ,
130+ } ,
131+ item : oci :: tar :: TarItem :: Directory ,
132+ }
132133 }
133- }
134134
135- #[ cfg( test) ]
136- fn assert_files ( fs : & FileSystem , expected : & [ & str ] ) -> Result < ( ) > {
137- let mut out = vec ! [ ] ;
138- write_dumpfile ( & mut out, fs) ?;
139- let actual: Vec < String > = out
140- . lines ( )
141- . map ( |line| line. unwrap ( ) . split_once ( ' ' ) . unwrap ( ) . 0 . into ( ) )
142- . collect ( ) ;
143-
144- similar_asserts:: assert_eq!( actual, expected) ;
145- Ok ( ( ) )
146- }
135+ fn assert_files ( fs : & FileSystem , expected : & [ & str ] ) -> Result < ( ) > {
136+ let mut out = vec ! [ ] ;
137+ write_dumpfile ( & mut out, fs) ?;
138+ let actual: Vec < String > = out
139+ . lines ( )
140+ . map ( |line| line. unwrap ( ) . split_once ( ' ' ) . unwrap ( ) . 0 . into ( ) )
141+ . collect ( ) ;
147142
148- #[ test]
149- fn test_process_entry ( ) -> Result < ( ) > {
150- let mut fs = FileSystem :: new ( ) ;
151-
152- // both with and without leading slash should be supported
153- process_entry ( & mut fs, dir_entry ( "/a" ) ) ?;
154- process_entry ( & mut fs, dir_entry ( "b" ) ) ?;
155- process_entry ( & mut fs, dir_entry ( "c" ) ) ?;
156- assert_files ( & fs, & [ "/" , "/a" , "/b" , "/c" ] ) ?;
157-
158- // add some files
159- process_entry ( & mut fs, file_entry ( "/a/b" ) ) ?;
160- process_entry ( & mut fs, file_entry ( "/a/c" ) ) ?;
161- process_entry ( & mut fs, file_entry ( "/b/a" ) ) ?;
162- process_entry ( & mut fs, file_entry ( "/b/c" ) ) ?;
163- process_entry ( & mut fs, file_entry ( "/c/a" ) ) ?;
164- process_entry ( & mut fs, file_entry ( "/c/c" ) ) ?;
165- assert_files (
166- & fs,
167- & [
168- "/" , "/a" , "/a/b" , "/a/c" , "/b" , "/b/a" , "/b/c" , "/c" , "/c/a" , "/c/c" ,
169- ] ,
170- ) ?;
171-
172- // try some whiteouts
173- process_entry ( & mut fs, file_entry ( ".wh.a" ) ) ?; // entire dir
174- process_entry ( & mut fs, file_entry ( "/b/.wh..wh.opq" ) ) ?; // opaque dir
175- process_entry ( & mut fs, file_entry ( "/c/.wh.c" ) ) ?; // single file
176- assert_files ( & fs, & [ "/" , "/b" , "/c" , "/c/a" ] ) ?;
143+ similar_asserts:: assert_eq!( actual, expected) ;
144+ Ok ( ( ) )
145+ }
177146
178- Ok ( ( ) )
147+ #[ test]
148+ fn test_process_entry ( ) -> Result < ( ) > {
149+ let mut fs = FileSystem :: new ( ) ;
150+
151+ // both with and without leading slash should be supported
152+ process_entry ( & mut fs, dir_entry ( "/a" ) ) ?;
153+ process_entry ( & mut fs, dir_entry ( "b" ) ) ?;
154+ process_entry ( & mut fs, dir_entry ( "c" ) ) ?;
155+ assert_files ( & fs, & [ "/" , "/a" , "/b" , "/c" ] ) ?;
156+
157+ // add some files
158+ process_entry ( & mut fs, file_entry ( "/a/b" ) ) ?;
159+ process_entry ( & mut fs, file_entry ( "/a/c" ) ) ?;
160+ process_entry ( & mut fs, file_entry ( "/b/a" ) ) ?;
161+ process_entry ( & mut fs, file_entry ( "/b/c" ) ) ?;
162+ process_entry ( & mut fs, file_entry ( "/c/a" ) ) ?;
163+ process_entry ( & mut fs, file_entry ( "/c/c" ) ) ?;
164+ assert_files (
165+ & fs,
166+ & [
167+ "/" , "/a" , "/a/b" , "/a/c" , "/b" , "/b/a" , "/b/c" , "/c" , "/c/a" , "/c/c" ,
168+ ] ,
169+ ) ?;
170+
171+ // try some whiteouts
172+ process_entry ( & mut fs, file_entry ( ".wh.a" ) ) ?; // entire dir
173+ process_entry ( & mut fs, file_entry ( "/b/.wh..wh.opq" ) ) ?; // opaque dir
174+ process_entry ( & mut fs, file_entry ( "/c/.wh.c" ) ) ?; // single file
175+ assert_files ( & fs, & [ "/" , "/b" , "/c" , "/c/a" ] ) ?;
176+
177+ Ok ( ( ) )
178+ }
179179}
0 commit comments