@@ -556,6 +556,48 @@ void shouldPushManifestWithRegistryConfig(@TempDir Path homeDir) throws Exceptio
556556 });
557557 }
558558
559+ @ Test
560+ @ Execution (ExecutionMode .SAME_THREAD )
561+ void shouldPushManifestWithAlias (@ TempDir Path homeDir ) throws Exception {
562+
563+ // language=toml
564+ String config =
565+ """
566+ [[registry]]
567+ location = "%s"
568+ insecure = true
569+
570+ [aliases]
571+ "my-library/my-namespace"="%s/test/bar"
572+ """
573+ .formatted (this .unsecureRegistry .getRegistry (), this .unsecureRegistry .getRegistry ());
574+ TestUtils .createRegistriesConfFile (homeDir , config );
575+
576+ TestUtils .withHome (homeDir , () -> {
577+ Registry registry = Registry .Builder .builder ().defaults ().build ();
578+
579+ // Empty manifest
580+ ContainerRef containerRef = ContainerRef .parse ("my-library/my-namespace" );
581+ Index emptyIndex = Index .fromManifests (List .of ());
582+ Index pushIndex = registry .pushIndex (containerRef , emptyIndex );
583+
584+ // Assert
585+ assertEquals (2 , pushIndex .getSchemaVersion ());
586+ assertEquals (Const .DEFAULT_INDEX_MEDIA_TYPE , pushIndex .getMediaType ());
587+ assertEquals (0 , pushIndex .getManifests ().size ());
588+
589+ // Push again
590+ registry .pushIndex (containerRef , emptyIndex );
591+
592+ // Delete index
593+ registry .deleteManifest (containerRef );
594+ // Ensure the blob is deleted
595+ assertThrows (OrasException .class , () -> {
596+ registry .getManifest (containerRef );
597+ });
598+ });
599+ }
600+
559601 @ Test
560602 @ Execution (ExecutionMode .SAME_THREAD )
561603 void shouldDetermineRegistryFromAlias (@ TempDir Path homeDir ) throws Exception {
@@ -863,6 +905,46 @@ void testShouldCopySingleArtifactFromRegistryIntoRegistry() throws IOException {
863905 }
864906 }
865907
908+ @ Test
909+ @ Execution (ExecutionMode .SAME_THREAD )
910+ void testShouldArtifactWithAlias (@ TempDir Path homeDir ) throws Exception {
911+
912+ // language=toml
913+ String config =
914+ """
915+ [aliases]
916+ "the-target" = "%s/test/artifact-target"
917+
918+ [[registry]]
919+ location = "%s"
920+ insecure = true
921+ """
922+ .formatted (this .registry .getRegistry (), this .registry .getRegistry ());
923+ TestUtils .createRegistriesConfFile (homeDir , config );
924+
925+ // Copy to same registry
926+ TestUtils .withHome (homeDir , () -> {
927+ try {
928+ Registry registry =
929+ Registry .Builder .builder ().defaults ("myuser" , "mypass" ).build ();
930+
931+ ContainerRef originalRef = ContainerRef .parse ("the-target" );
932+ Path file1 = blobDir .resolve ("source.txt" );
933+ Files .writeString (file1 , "foobar" );
934+
935+ // Push
936+ Manifest manifest = registry .pushArtifact (originalRef , LocalPath .of (file1 ));
937+ assertNotNull (manifest );
938+
939+ // Pull
940+ registry .pullArtifact (originalRef , artifactDir , true );
941+ assertEquals ("foobar" , Files .readString (artifactDir .resolve ("source.txt" )));
942+ } catch (Exception e ) {
943+ throw new RuntimeException (e );
944+ }
945+ });
946+ }
947+
866948 @ Test
867949 @ Execution (ExecutionMode .SAME_THREAD )
868950 @ Disabled ("#" )
0 commit comments