@@ -817,44 +817,6 @@ pub(crate) fn switch_origin_inplace(root: &Dir, imgref: &ImageReference) -> Resu
817
817
Ok ( newest_deployment)
818
818
}
819
819
820
- #[ test]
821
- fn test_switch_inplace ( ) -> Result < ( ) > {
822
- use cap_std:: fs:: DirBuilderExt ;
823
-
824
- let td = cap_std_ext:: cap_tempfile:: TempDir :: new ( cap_std:: ambient_authority ( ) ) ?;
825
- let mut builder = cap_std:: fs:: DirBuilder :: new ( ) ;
826
- let builder = builder. recursive ( true ) . mode ( 0o755 ) ;
827
- let deploydir = "sysroot/ostree/deploy/default/deploy" ;
828
- let target_deployment = "af36eb0086bb55ac601600478c6168f834288013d60f8870b7851f44bf86c3c5.0" ;
829
- td. ensure_dir_with (
830
- format ! ( "sysroot/ostree/deploy/default/deploy/{target_deployment}" ) ,
831
- builder,
832
- ) ?;
833
- let deploydir = & td. open_dir ( deploydir) ?;
834
- let orig_imgref = ImageReference {
835
- image : "quay.io/exampleos/original:sometag" . into ( ) ,
836
- transport : "registry" . into ( ) ,
837
- signature : None ,
838
- } ;
839
- {
840
- let origin = origin_from_imageref ( & orig_imgref) ?;
841
- deploydir. atomic_write (
842
- format ! ( "{target_deployment}.origin" ) ,
843
- origin. to_data ( ) . as_bytes ( ) ,
844
- ) ?;
845
- }
846
-
847
- let target_imgref = ImageReference {
848
- image : "quay.io/someother/otherimage:latest" . into ( ) ,
849
- transport : "registry" . into ( ) ,
850
- signature : None ,
851
- } ;
852
-
853
- let replaced = switch_origin_inplace ( & td, & target_imgref) . unwrap ( ) ;
854
- assert_eq ! ( replaced, target_deployment) ;
855
- Ok ( ( ) )
856
- }
857
-
858
820
/// A workaround for https://github.com/ostreedev/ostree/issues/3193
859
821
/// as generated by anaconda.
860
822
#[ context( "Updating /etc/fstab for anaconda+composefs" ) ]
@@ -935,56 +897,100 @@ pub(crate) fn fixup_etc_fstab(root: &Dir) -> Result<()> {
935
897
Ok ( ( ) )
936
898
}
937
899
938
- #[ test]
939
- fn test_fixup_etc_fstab_default ( ) -> Result < ( ) > {
940
- let tempdir = cap_std_ext:: cap_tempfile:: tempdir ( cap_std:: ambient_authority ( ) ) ?;
941
- let default = "UUID=f7436547-20ac-43cb-aa2f-eac9632183f6 /boot auto ro 0 0\n " ;
942
- tempdir. create_dir_all ( "etc" ) ?;
943
- tempdir. atomic_write ( "etc/fstab" , default) ?;
944
- fixup_etc_fstab ( & tempdir) . unwrap ( ) ;
945
- assert_eq ! ( tempdir. read_to_string( "etc/fstab" ) ?, default ) ;
946
- Ok ( ( ) )
947
- }
900
+ #[ cfg( test) ]
901
+ mod tests {
902
+ use super :: * ;
903
+
904
+ #[ test]
905
+ fn test_switch_inplace ( ) -> Result < ( ) > {
906
+ use cap_std:: fs:: DirBuilderExt ;
907
+
908
+ let td = cap_std_ext:: cap_tempfile:: TempDir :: new ( cap_std:: ambient_authority ( ) ) ?;
909
+ let mut builder = cap_std:: fs:: DirBuilder :: new ( ) ;
910
+ let builder = builder. recursive ( true ) . mode ( 0o755 ) ;
911
+ let deploydir = "sysroot/ostree/deploy/default/deploy" ;
912
+ let target_deployment =
913
+ "af36eb0086bb55ac601600478c6168f834288013d60f8870b7851f44bf86c3c5.0" ;
914
+ td. ensure_dir_with (
915
+ format ! ( "sysroot/ostree/deploy/default/deploy/{target_deployment}" ) ,
916
+ builder,
917
+ ) ?;
918
+ let deploydir = & td. open_dir ( deploydir) ?;
919
+ let orig_imgref = ImageReference {
920
+ image : "quay.io/exampleos/original:sometag" . into ( ) ,
921
+ transport : "registry" . into ( ) ,
922
+ signature : None ,
923
+ } ;
924
+ {
925
+ let origin = origin_from_imageref ( & orig_imgref) ?;
926
+ deploydir. atomic_write (
927
+ format ! ( "{target_deployment}.origin" ) ,
928
+ origin. to_data ( ) . as_bytes ( ) ,
929
+ ) ?;
930
+ }
931
+
932
+ let target_imgref = ImageReference {
933
+ image : "quay.io/someother/otherimage:latest" . into ( ) ,
934
+ transport : "registry" . into ( ) ,
935
+ signature : None ,
936
+ } ;
948
937
949
- #[ test]
950
- fn test_fixup_etc_fstab_multi ( ) -> Result < ( ) > {
951
- let tempdir = cap_std_ext:: cap_tempfile:: tempdir ( cap_std:: ambient_authority ( ) ) ?;
952
- let default = "UUID=f7436547-20ac-43cb-aa2f-eac9632183f6 /boot auto ro 0 0\n \
938
+ let replaced = switch_origin_inplace ( & td, & target_imgref) . unwrap ( ) ;
939
+ assert_eq ! ( replaced, target_deployment) ;
940
+ Ok ( ( ) )
941
+ }
942
+
943
+ #[ test]
944
+ fn test_fixup_etc_fstab_default ( ) -> Result < ( ) > {
945
+ let tempdir = cap_std_ext:: cap_tempfile:: tempdir ( cap_std:: ambient_authority ( ) ) ?;
946
+ let default = "UUID=f7436547-20ac-43cb-aa2f-eac9632183f6 /boot auto ro 0 0\n " ;
947
+ tempdir. create_dir_all ( "etc" ) ?;
948
+ tempdir. atomic_write ( "etc/fstab" , default) ?;
949
+ fixup_etc_fstab ( & tempdir) . unwrap ( ) ;
950
+ assert_eq ! ( tempdir. read_to_string( "etc/fstab" ) ?, default ) ;
951
+ Ok ( ( ) )
952
+ }
953
+
954
+ #[ test]
955
+ fn test_fixup_etc_fstab_multi ( ) -> Result < ( ) > {
956
+ let tempdir = cap_std_ext:: cap_tempfile:: tempdir ( cap_std:: ambient_authority ( ) ) ?;
957
+ let default = "UUID=f7436547-20ac-43cb-aa2f-eac9632183f6 /boot auto ro 0 0\n \
953
958
UUID=6907-17CA /boot/efi vfat umask=0077,shortname=winnt 0 2\n ";
954
- tempdir. create_dir_all ( "etc" ) ?;
955
- tempdir. atomic_write ( "etc/fstab" , default) ?;
956
- fixup_etc_fstab ( & tempdir) . unwrap ( ) ;
957
- assert_eq ! ( tempdir. read_to_string( "etc/fstab" ) ?, default ) ;
958
- Ok ( ( ) )
959
- }
959
+ tempdir. create_dir_all ( "etc" ) ?;
960
+ tempdir. atomic_write ( "etc/fstab" , default) ?;
961
+ fixup_etc_fstab ( & tempdir) . unwrap ( ) ;
962
+ assert_eq ! ( tempdir. read_to_string( "etc/fstab" ) ?, default ) ;
963
+ Ok ( ( ) )
964
+ }
960
965
961
- #[ test]
962
- fn test_fixup_etc_fstab_ro ( ) -> Result < ( ) > {
963
- let tempdir = cap_std_ext:: cap_tempfile:: tempdir ( cap_std:: ambient_authority ( ) ) ?;
964
- let default = "UUID=f7436547-20ac-43cb-aa2f-eac9632183f6 /boot auto ro 0 0\n \
966
+ #[ test]
967
+ fn test_fixup_etc_fstab_ro ( ) -> Result < ( ) > {
968
+ let tempdir = cap_std_ext:: cap_tempfile:: tempdir ( cap_std:: ambient_authority ( ) ) ?;
969
+ let default = "UUID=f7436547-20ac-43cb-aa2f-eac9632183f6 /boot auto ro 0 0\n \
965
970
UUID=1eef9f42-40e3-4bd8-ae20-e9f2325f8b52 / xfs ro 0 0\n \
966
971
UUID=6907-17CA /boot/efi vfat umask=0077,shortname=winnt 0 2\n ";
967
- tempdir. create_dir_all ( "etc" ) ?;
968
- tempdir. atomic_write ( "etc/fstab" , default) ?;
969
- fixup_etc_fstab ( & tempdir) . unwrap ( ) ;
970
- assert_eq ! ( tempdir. read_to_string( "etc/fstab" ) ?, default ) ;
971
- Ok ( ( ) )
972
- }
972
+ tempdir. create_dir_all ( "etc" ) ?;
973
+ tempdir. atomic_write ( "etc/fstab" , default) ?;
974
+ fixup_etc_fstab ( & tempdir) . unwrap ( ) ;
975
+ assert_eq ! ( tempdir. read_to_string( "etc/fstab" ) ?, default ) ;
976
+ Ok ( ( ) )
977
+ }
973
978
974
- #[ test]
975
- fn test_fixup_etc_fstab_rw ( ) -> Result < ( ) > {
976
- let tempdir = cap_std_ext:: cap_tempfile:: tempdir ( cap_std:: ambient_authority ( ) ) ?;
977
- // This case uses `defaults`
978
- let default = "UUID=f7436547-20ac-43cb-aa2f-eac9632183f6 /boot auto ro 0 0\n \
979
+ #[ test]
980
+ fn test_fixup_etc_fstab_rw ( ) -> Result < ( ) > {
981
+ let tempdir = cap_std_ext:: cap_tempfile:: tempdir ( cap_std:: ambient_authority ( ) ) ?;
982
+ // This case uses `defaults`
983
+ let default = "UUID=f7436547-20ac-43cb-aa2f-eac9632183f6 /boot auto ro 0 0\n \
979
984
UUID=1eef9f42-40e3-4bd8-ae20-e9f2325f8b52 / xfs defaults 0 0\n \
980
985
UUID=6907-17CA /boot/efi vfat umask=0077,shortname=winnt 0 2\n ";
981
- let modified = "UUID=f7436547-20ac-43cb-aa2f-eac9632183f6 /boot auto ro 0 0\n \
986
+ let modified = "UUID=f7436547-20ac-43cb-aa2f-eac9632183f6 /boot auto ro 0 0\n \
982
987
# Updated by bootc-fstab-edit.service\n \
983
988
UUID=1eef9f42-40e3-4bd8-ae20-e9f2325f8b52 / xfs defaults,ro 0 0\n \
984
989
UUID=6907-17CA /boot/efi vfat umask=0077,shortname=winnt 0 2\n ";
985
- tempdir. create_dir_all ( "etc" ) ?;
986
- tempdir. atomic_write ( "etc/fstab" , default) ?;
987
- fixup_etc_fstab ( & tempdir) . unwrap ( ) ;
988
- assert_eq ! ( tempdir. read_to_string( "etc/fstab" ) ?, modified) ;
989
- Ok ( ( ) )
990
+ tempdir. create_dir_all ( "etc" ) ?;
991
+ tempdir. atomic_write ( "etc/fstab" , default) ?;
992
+ fixup_etc_fstab ( & tempdir) . unwrap ( ) ;
993
+ assert_eq ! ( tempdir. read_to_string( "etc/fstab" ) ?, modified) ;
994
+ Ok ( ( ) )
995
+ }
990
996
}
0 commit comments