@@ -1456,7 +1456,7 @@ func TestCopyGraph_WithOptions(t *testing.T) {
1456
1456
},
1457
1457
}
1458
1458
if err := oras .CopyGraph (ctx , src , dst , root , opts ); err != nil {
1459
- t .Fatalf ("CopyGraph() error = %v, wantErr %v " , err , errdef . ErrSizeExceedsLimit )
1459
+ t .Fatalf ("CopyGraph() error = %v" , err )
1460
1460
}
1461
1461
1462
1462
if got , expected := dst .numExists .Load (), int64 (7 ); got != expected {
@@ -1515,7 +1515,7 @@ func TestCopyGraph_WithOptions(t *testing.T) {
1515
1515
return []string {"source" }, nil
1516
1516
}
1517
1517
if err := oras .CopyGraph (ctx , src , dst , root , opts ); err != nil {
1518
- t .Fatalf ("CopyGraph() error = %v, wantErr %v " , err , errdef . ErrSizeExceedsLimit )
1518
+ t .Fatalf ("CopyGraph() error = %v" , err )
1519
1519
}
1520
1520
1521
1521
if got , expected := dst .numExists .Load (), int64 (7 ); got != expected {
@@ -1590,7 +1590,7 @@ func TestCopyGraph_WithOptions(t *testing.T) {
1590
1590
return []string {"source" }, nil
1591
1591
}
1592
1592
if err := oras .CopyGraph (ctx , src , dst , root , opts ); err != nil {
1593
- t .Fatalf ("CopyGraph() error = %v, wantErr %v " , err , errdef . ErrSizeExceedsLimit )
1593
+ t .Fatalf ("CopyGraph() error = %v" , err )
1594
1594
}
1595
1595
1596
1596
if got , expected := dst .numExists .Load (), int64 (7 ); got != expected {
@@ -1679,7 +1679,7 @@ func TestCopyGraph_WithOptions(t *testing.T) {
1679
1679
return []string {"missing/the/data" , "source" }, nil
1680
1680
}
1681
1681
if err := oras .CopyGraph (ctx , src , dst , root , opts ); err != nil {
1682
- t .Fatalf ("CopyGraph() error = %v, wantErr %v " , err , errdef . ErrSizeExceedsLimit )
1682
+ t .Fatalf ("CopyGraph() error = %v" , err )
1683
1683
}
1684
1684
1685
1685
if got , expected := dst .numExists .Load (), int64 (7 ); got != expected {
@@ -1709,6 +1709,134 @@ func TestCopyGraph_WithOptions(t *testing.T) {
1709
1709
t .Errorf ("count(PostCopy()) = %d, want %d" , got , expected )
1710
1710
}
1711
1711
})
1712
+
1713
+ t .Run ("MountFrom empty sourceRepositories" , func (t * testing.T ) {
1714
+ root = descs [6 ]
1715
+ dst := & countingStorage {storage : cas .NewMemory ()}
1716
+ opts = oras.CopyGraphOptions {}
1717
+ var numMountFrom atomic.Int64
1718
+ opts .MountFrom = func (ctx context.Context , desc ocispec.Descriptor ) ([]string , error ) {
1719
+ numMountFrom .Add (1 )
1720
+ return nil , nil
1721
+ }
1722
+ if err := oras .CopyGraph (ctx , src , dst , root , opts ); err != nil {
1723
+ t .Fatalf ("CopyGraph() error = %v" , err )
1724
+ }
1725
+
1726
+ if got , expected := dst .numExists .Load (), int64 (7 ); got != expected {
1727
+ t .Errorf ("count(Exists()) = %d, want %d" , got , expected )
1728
+ }
1729
+ if got , expected := dst .numFetch .Load (), int64 (0 ); got != expected {
1730
+ t .Errorf ("count(Fetch()) = %d, want %d" , got , expected )
1731
+ }
1732
+ if got , expected := dst .numPush .Load (), int64 (7 ); got != expected {
1733
+ t .Errorf ("count(Push()) = %d, want %d" , got , expected )
1734
+ }
1735
+ if got , expected := numMountFrom .Load (), int64 (4 ); got != expected {
1736
+ t .Errorf ("count(MountFrom()) = %d, want %d" , got , expected )
1737
+ }
1738
+ })
1739
+
1740
+ t .Run ("MountFrom error" , func (t * testing.T ) {
1741
+ root = descs [6 ]
1742
+ dst := & countingStorage {storage : cas .NewMemory ()}
1743
+ opts = oras.CopyGraphOptions {}
1744
+ var numMountFrom atomic.Int64
1745
+ e := errors .New ("mountFrom error" )
1746
+ opts .MountFrom = func (ctx context.Context , desc ocispec.Descriptor ) ([]string , error ) {
1747
+ numMountFrom .Add (1 )
1748
+ return nil , e
1749
+ }
1750
+ if err := oras .CopyGraph (ctx , src , dst , root , opts ); ! errors .Is (err , e ) {
1751
+ t .Fatalf ("CopyGraph() error = %v, wantErr %v" , err , e )
1752
+ }
1753
+
1754
+ if got , expected := dst .numExists .Load (), int64 (7 ); got != expected {
1755
+ t .Errorf ("count(Exists()) = %d, want %d" , got , expected )
1756
+ }
1757
+ if got , expected := dst .numFetch .Load (), int64 (0 ); got != expected {
1758
+ t .Errorf ("count(Fetch()) = %d, want %d" , got , expected )
1759
+ }
1760
+ if got , expected := dst .numPush .Load (), int64 (0 ); got != expected {
1761
+ t .Errorf ("count(Push()) = %d, want %d" , got , expected )
1762
+ }
1763
+ if got , expected := numMountFrom .Load (), int64 (4 ); got != expected {
1764
+ t .Errorf ("count(MountFrom()) = %d, want %d" , got , expected )
1765
+ }
1766
+ })
1767
+
1768
+ t .Run ("MountFrom OnMounted error" , func (t * testing.T ) {
1769
+ root = descs [6 ]
1770
+ dst := & countingStorage {storage : cas .NewMemory ()}
1771
+ var numMount atomic.Int64
1772
+ dst .mount = func (ctx context.Context ,
1773
+ desc ocispec.Descriptor ,
1774
+ fromRepo string ,
1775
+ getContent func () (io.ReadCloser , error ),
1776
+ ) error {
1777
+ numMount .Add (1 )
1778
+ if expected := "source" ; fromRepo != expected {
1779
+ t .Fatalf ("fromRepo = %v, want %v" , fromRepo , expected )
1780
+ }
1781
+ rc , err := src .Fetch (ctx , desc )
1782
+ if err != nil {
1783
+ t .Fatalf ("Failed to fetch content: %v" , err )
1784
+ }
1785
+ defer rc .Close ()
1786
+ err = dst .storage .Push (ctx , desc , rc ) // bypass the counters
1787
+ if err != nil {
1788
+ t .Fatalf ("Failed to push content: %v" , err )
1789
+ }
1790
+ return nil
1791
+ }
1792
+ opts = oras.CopyGraphOptions {}
1793
+ var numPreCopy , numPostCopy , numOnMounted , numMountFrom atomic.Int64
1794
+ opts .PreCopy = func (ctx context.Context , desc ocispec.Descriptor ) error {
1795
+ numPreCopy .Add (1 )
1796
+ return nil
1797
+ }
1798
+ opts .PostCopy = func (ctx context.Context , desc ocispec.Descriptor ) error {
1799
+ numPostCopy .Add (1 )
1800
+ return nil
1801
+ }
1802
+ e := errors .New ("onMounted error" )
1803
+ opts .OnMounted = func (ctx context.Context , d ocispec.Descriptor ) error {
1804
+ numOnMounted .Add (1 )
1805
+ return e
1806
+ }
1807
+ opts .MountFrom = func (ctx context.Context , desc ocispec.Descriptor ) ([]string , error ) {
1808
+ numMountFrom .Add (1 )
1809
+ return []string {"source" }, nil
1810
+ }
1811
+ if err := oras .CopyGraph (ctx , src , dst , root , opts ); ! errors .Is (err , e ) {
1812
+ t .Fatalf ("CopyGraph() error = %v, wantErr %v" , err , e )
1813
+ }
1814
+
1815
+ if got , expected := dst .numExists .Load (), int64 (7 ); got != expected {
1816
+ t .Errorf ("count(Exists()) = %d, want %d" , got , expected )
1817
+ }
1818
+ if got , expected := dst .numFetch .Load (), int64 (0 ); got != expected {
1819
+ t .Errorf ("count(Fetch()) = %d, want %d" , got , expected )
1820
+ }
1821
+ if got , expected := dst .numPush .Load (), int64 (0 ); got != expected {
1822
+ t .Errorf ("count(Push()) = %d, want %d" , got , expected )
1823
+ }
1824
+ if got , expected := numMount .Load (), int64 (4 ); got != expected {
1825
+ t .Errorf ("count(Mount()) = %d, want %d" , got , expected )
1826
+ }
1827
+ if got , expected := numOnMounted .Load (), int64 (4 ); got != expected {
1828
+ t .Errorf ("count(OnMounted()) = %d, want %d" , got , expected )
1829
+ }
1830
+ if got , expected := numMountFrom .Load (), int64 (4 ); got != expected {
1831
+ t .Errorf ("count(MountFrom()) = %d, want %d" , got , expected )
1832
+ }
1833
+ if got , expected := numPreCopy .Load (), int64 (0 ); got != expected {
1834
+ t .Errorf ("count(PreCopy()) = %d, want %d" , got , expected )
1835
+ }
1836
+ if got , expected := numPostCopy .Load (), int64 (0 ); got != expected {
1837
+ t .Errorf ("count(PostCopy()) = %d, want %d" , got , expected )
1838
+ }
1839
+ })
1712
1840
}
1713
1841
1714
1842
// countingStorage counts the calls to its content.Storage methods
0 commit comments