@@ -454,3 +454,69 @@ fn test_oci_layer_inspect() -> Result<()> {
454454 Ok ( ( ) )
455455}
456456integration_test ! ( test_oci_layer_inspect) ;
457+
458+ fn test_get_file_obj_ref ( ) -> Result < ( ) > {
459+ let sh = Shell :: new ( ) ?;
460+ let cfsctl = cfsctl ( ) ?;
461+ let repo_dir = tempfile:: tempdir ( ) ?;
462+ let repo = repo_dir. path ( ) ;
463+ let fixture_dir = tempfile:: tempdir ( ) ?;
464+ let rootfs = create_test_rootfs ( fixture_dir. path ( ) ) ?;
465+
466+ cmd ! (
467+ sh,
468+ "{cfsctl} --insecure --repo {repo} create-image {rootfs} my-image"
469+ )
470+ . read ( ) ?;
471+
472+ let out_json = cmd ! (
473+ sh,
474+ "{cfsctl} --insecure --repo {repo} get-file-object-ref {rootfs} --file-path /usr/bin/hello"
475+ )
476+ . read ( ) ?;
477+
478+ let stored_inline = cmd ! ( sh, "jq -r .stored_inline" )
479+ . stdin ( & out_json)
480+ . read ( ) ?
481+ . parse :: < bool > ( ) ?;
482+
483+ assert ! (
484+ !stored_inline,
485+ "usr/bin/hello should've been large enough to be stored in objects directory"
486+ ) ;
487+
488+ let path = cmd ! ( sh, "jq -r .path" ) . stdin ( & out_json) . read ( ) ?;
489+
490+ let full_path = repo. join ( "objects" ) . join ( path) ;
491+
492+ assert ! ( full_path. exists( ) ) ;
493+
494+ let file_hash = cmd ! ( sh, "sha512sum" )
495+ . arg ( rootfs. join ( "usr/bin/hello" ) . as_str ( ) ?)
496+ . read ( ) ?;
497+ let file_hash = file_hash. split_whitespace ( ) . next ( ) . unwrap ( ) . trim ( ) ;
498+
499+ let obj_file_hash = cmd ! ( sh, "sha512sum" ) . arg ( full_path. as_str ( ) ?) . read ( ) ?;
500+ let obj_file_hash = obj_file_hash. split_whitespace ( ) . next ( ) . unwrap ( ) . trim ( ) ;
501+
502+ assert_eq ! ( file_hash, obj_file_hash) ;
503+
504+ let out_json = cmd ! (
505+ sh,
506+ "{cfsctl} --insecure --repo {repo} get-file-object-ref {rootfs} --file-path usr/lib/readme.txt"
507+ )
508+ . read ( ) ?;
509+
510+ let stored_inline = cmd ! ( sh, "jq -r .stored_inline" )
511+ . stdin ( & out_json)
512+ . read ( ) ?
513+ . parse :: < bool > ( ) ?;
514+
515+ assert ! (
516+ stored_inline,
517+ "usr/lib/readme.txt should've been stored inline"
518+ ) ;
519+
520+ Ok ( ( ) )
521+ }
522+ integration_test ! ( test_get_file_obj_ref) ;
0 commit comments