@@ -1125,127 +1125,132 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
1125
1125
}
1126
1126
}
1127
1127
1128
- #[ test]
1129
- fn test_callname ( ) {
1130
- use std:: os:: unix:: ffi:: OsStrExt ;
1131
-
1132
- // Cases that change
1133
- let mapped_cases = [
1134
- ( "" , "bootc" ) ,
1135
- ( "/foo/bar" , "bar" ) ,
1136
- ( "/foo/bar/" , "bar" ) ,
1137
- ( "foo/bar" , "bar" ) ,
1138
- ( "../foo/bar" , "bar" ) ,
1139
- ( "usr/bin/ostree-container" , "ostree-container" ) ,
1140
- ] ;
1141
- for ( input, output) in mapped_cases {
1142
- assert_eq ! (
1143
- output,
1144
- callname_from_argv0( OsStr :: new( input) ) ,
1145
- "Handling mapped case {input}"
1146
- ) ;
1147
- }
1128
+ #[ cfg( test) ]
1129
+ mod tests {
1130
+ use super :: * ;
1131
+
1132
+ #[ test]
1133
+ fn test_callname ( ) {
1134
+ use std:: os:: unix:: ffi:: OsStrExt ;
1135
+
1136
+ // Cases that change
1137
+ let mapped_cases = [
1138
+ ( "" , "bootc" ) ,
1139
+ ( "/foo/bar" , "bar" ) ,
1140
+ ( "/foo/bar/" , "bar" ) ,
1141
+ ( "foo/bar" , "bar" ) ,
1142
+ ( "../foo/bar" , "bar" ) ,
1143
+ ( "usr/bin/ostree-container" , "ostree-container" ) ,
1144
+ ] ;
1145
+ for ( input, output) in mapped_cases {
1146
+ assert_eq ! (
1147
+ output,
1148
+ callname_from_argv0( OsStr :: new( input) ) ,
1149
+ "Handling mapped case {input}"
1150
+ ) ;
1151
+ }
1148
1152
1149
- // Invalid UTF-8
1150
- assert_eq ! ( "bootc" , callname_from_argv0( OsStr :: from_bytes( b"foo\x80 " ) ) ) ;
1153
+ // Invalid UTF-8
1154
+ assert_eq ! ( "bootc" , callname_from_argv0( OsStr :: from_bytes( b"foo\x80 " ) ) ) ;
1155
+
1156
+ // Cases that are identical
1157
+ let ident_cases = [ "foo" , "bootc" ] ;
1158
+ for case in ident_cases {
1159
+ assert_eq ! (
1160
+ case,
1161
+ callname_from_argv0( OsStr :: new( case) ) ,
1162
+ "Handling ident case {case}"
1163
+ ) ;
1164
+ }
1165
+ }
1151
1166
1152
- // Cases that are identical
1153
- let ident_cases = [ "foo" , "bootc" ] ;
1154
- for case in ident_cases {
1167
+ #[ test]
1168
+ fn test_parse_install_args ( ) {
1169
+ // Verify we still process the legacy --target-no-signature-verification
1170
+ let o = Opt :: try_parse_from ( [
1171
+ "bootc" ,
1172
+ "install" ,
1173
+ "to-filesystem" ,
1174
+ "--target-no-signature-verification" ,
1175
+ "/target" ,
1176
+ ] )
1177
+ . unwrap ( ) ;
1178
+ let o = match o {
1179
+ Opt :: Install ( InstallOpts :: ToFilesystem ( fsopts) ) => fsopts,
1180
+ o => panic ! ( "Expected filesystem opts, not {o:?}" ) ,
1181
+ } ;
1182
+ assert ! ( o. target_opts. target_no_signature_verification) ;
1183
+ assert_eq ! ( o. filesystem_opts. root_path. as_str( ) , "/target" ) ;
1184
+ // Ensure we default to old bound images behavior
1155
1185
assert_eq ! (
1156
- case,
1157
- callname_from_argv0( OsStr :: new( case) ) ,
1158
- "Handling ident case {case}"
1186
+ o. config_opts. bound_images,
1187
+ crate :: install:: BoundImagesOpt :: Stored
1159
1188
) ;
1160
1189
}
1161
- }
1162
-
1163
- #[ test]
1164
- fn test_parse_install_args ( ) {
1165
- // Verify we still process the legacy --target-no-signature-verification
1166
- let o = Opt :: try_parse_from ( [
1167
- "bootc" ,
1168
- "install" ,
1169
- "to-filesystem" ,
1170
- "--target-no-signature-verification" ,
1171
- "/target" ,
1172
- ] )
1173
- . unwrap ( ) ;
1174
- let o = match o {
1175
- Opt :: Install ( InstallOpts :: ToFilesystem ( fsopts) ) => fsopts,
1176
- o => panic ! ( "Expected filesystem opts, not {o:?}" ) ,
1177
- } ;
1178
- assert ! ( o. target_opts. target_no_signature_verification) ;
1179
- assert_eq ! ( o. filesystem_opts. root_path. as_str( ) , "/target" ) ;
1180
- // Ensure we default to old bound images behavior
1181
- assert_eq ! (
1182
- o. config_opts. bound_images,
1183
- crate :: install:: BoundImagesOpt :: Stored
1184
- ) ;
1185
- }
1186
1190
1187
- #[ test]
1188
- fn test_parse_opts ( ) {
1189
- assert ! ( matches!(
1190
- Opt :: parse_including_static( [ "bootc" , "status" ] ) ,
1191
- Opt :: Status ( StatusOpts {
1192
- json: false ,
1193
- format: None ,
1194
- format_version: None ,
1195
- booted: false
1196
- } )
1197
- ) ) ;
1198
- assert ! ( matches!(
1199
- Opt :: parse_including_static( [ "bootc" , "status" , "--format-version=0" ] ) ,
1200
- Opt :: Status ( StatusOpts {
1201
- format_version: Some ( 0 ) ,
1202
- ..
1203
- } )
1204
- ) ) ;
1205
- }
1191
+ #[ test]
1192
+ fn test_parse_opts ( ) {
1193
+ assert ! ( matches!(
1194
+ Opt :: parse_including_static( [ "bootc" , "status" ] ) ,
1195
+ Opt :: Status ( StatusOpts {
1196
+ json: false ,
1197
+ format: None ,
1198
+ format_version: None ,
1199
+ booted: false
1200
+ } )
1201
+ ) ) ;
1202
+ assert ! ( matches!(
1203
+ Opt :: parse_including_static( [ "bootc" , "status" , "--format-version=0" ] ) ,
1204
+ Opt :: Status ( StatusOpts {
1205
+ format_version: Some ( 0 ) ,
1206
+ ..
1207
+ } )
1208
+ ) ) ;
1209
+ }
1206
1210
1207
- #[ test]
1208
- fn test_parse_generator ( ) {
1209
- assert ! ( matches!(
1210
- Opt :: parse_including_static( [
1211
- "/usr/lib/systemd/system/bootc-systemd-generator" ,
1212
- "/run/systemd/system"
1213
- ] ) ,
1214
- Opt :: Internals ( InternalsOpts :: SystemdGenerator { normal_dir, .. } ) if normal_dir == "/run/systemd/system"
1215
- ) ) ;
1216
- }
1211
+ #[ test]
1212
+ fn test_parse_generator ( ) {
1213
+ assert ! ( matches!(
1214
+ Opt :: parse_including_static( [
1215
+ "/usr/lib/systemd/system/bootc-systemd-generator" ,
1216
+ "/run/systemd/system"
1217
+ ] ) ,
1218
+ Opt :: Internals ( InternalsOpts :: SystemdGenerator { normal_dir, .. } ) if normal_dir == "/run/systemd/system"
1219
+ ) ) ;
1220
+ }
1217
1221
1218
- #[ test]
1219
- fn test_parse_ostree_ext ( ) {
1220
- assert ! ( matches!(
1221
- Opt :: parse_including_static( [ "bootc" , "internals" , "ostree-container" ] ) ,
1222
- Opt :: Internals ( InternalsOpts :: OstreeContainer { .. } )
1223
- ) ) ;
1224
-
1225
- fn peel ( o : Opt ) -> Vec < OsString > {
1226
- match o {
1227
- Opt :: Internals ( InternalsOpts :: OstreeExt { args } ) => args,
1228
- o => panic ! ( "unexpected {o:?}" ) ,
1222
+ #[ test]
1223
+ fn test_parse_ostree_ext ( ) {
1224
+ assert ! ( matches!(
1225
+ Opt :: parse_including_static( [ "bootc" , "internals" , "ostree-container" ] ) ,
1226
+ Opt :: Internals ( InternalsOpts :: OstreeContainer { .. } )
1227
+ ) ) ;
1228
+
1229
+ fn peel ( o : Opt ) -> Vec < OsString > {
1230
+ match o {
1231
+ Opt :: Internals ( InternalsOpts :: OstreeExt { args } ) => args,
1232
+ o => panic ! ( "unexpected {o:?}" ) ,
1233
+ }
1229
1234
}
1230
- }
1231
- let args = peel ( Opt :: parse_including_static ( [
1232
- "/usr/libexec/libostree/ext/ostree-ima-sign" ,
1233
- "ima-sign" ,
1234
- "--repo=foo" ,
1235
- "foo" ,
1236
- "bar" ,
1237
- "baz" ,
1238
- ] ) ) ;
1239
- assert_eq ! (
1240
- args. as_slice( ) ,
1241
- [ "ima-sign" , "--repo=foo" , "foo" , "bar" , "baz" ]
1242
- ) ;
1235
+ let args = peel ( Opt :: parse_including_static ( [
1236
+ "/usr/libexec/libostree/ext/ostree-ima-sign" ,
1237
+ "ima-sign" ,
1238
+ "--repo=foo" ,
1239
+ "foo" ,
1240
+ "bar" ,
1241
+ "baz" ,
1242
+ ] ) ) ;
1243
+ assert_eq ! (
1244
+ args. as_slice( ) ,
1245
+ [ "ima-sign" , "--repo=foo" , "foo" , "bar" , "baz" ]
1246
+ ) ;
1243
1247
1244
- let args = peel ( Opt :: parse_including_static ( [
1245
- "/usr/libexec/libostree/ext/ostree-container" ,
1246
- "container" ,
1247
- "image" ,
1248
- "pull" ,
1249
- ] ) ) ;
1250
- assert_eq ! ( args. as_slice( ) , [ "container" , "image" , "pull" ] ) ;
1248
+ let args = peel ( Opt :: parse_including_static ( [
1249
+ "/usr/libexec/libostree/ext/ostree-container" ,
1250
+ "container" ,
1251
+ "image" ,
1252
+ "pull" ,
1253
+ ] ) ) ;
1254
+ assert_eq ! ( args. as_slice( ) , [ "container" , "image" , "pull" ] ) ;
1255
+ }
1251
1256
}
0 commit comments