@@ -25,6 +25,8 @@ import (
2525 "k8s.io/apimachinery/pkg/api/resource"
2626 "k8s.io/apimachinery/pkg/util/intstr"
2727
28+ "github.com/argoproj/argo-cd/v3/util/oci"
29+
2830 cacheutil "github.com/argoproj/argo-cd/v3/util/cache"
2931
3032 "github.com/stretchr/testify/assert"
@@ -49,14 +51,15 @@ import (
4951 helmmocks "github.com/argoproj/argo-cd/v3/util/helm/mocks"
5052 utilio "github.com/argoproj/argo-cd/v3/util/io"
5153 iomocks "github.com/argoproj/argo-cd/v3/util/io/mocks"
54+ ocimocks "github.com/argoproj/argo-cd/v3/util/oci/mocks"
5255)
5356
5457const testSignature = `gpg: Signature made Wed Feb 26 23:22:34 2020 CET
5558gpg: using RSA key 4AEE18F83AFDEB23
5659gpg: Good signature from "GitHub (web-flow commit signing) <[email protected] >" [ultimate] 5760`
5861
59- type clientFunc func (* gitmocks.Client , * helmmocks.Client , * iomocks.TempPaths )
62+ type clientFunc func (* gitmocks.Client , * helmmocks.Client , * ocimocks. Client , * iomocks.TempPaths )
6063
6164type repoCacheMocks struct {
6265 mock.Mock
@@ -104,7 +107,7 @@ func newServiceWithMocks(t *testing.T, root string, signed bool) (*Service, *git
104107 if err != nil {
105108 panic (err )
106109 }
107- return newServiceWithOpt (t , func (gitClient * gitmocks.Client , helmClient * helmmocks.Client , paths * iomocks.TempPaths ) {
110+ return newServiceWithOpt (t , func (gitClient * gitmocks.Client , helmClient * helmmocks.Client , ociClient * ocimocks. Client , paths * iomocks.TempPaths ) {
108111 gitClient .On ("Init" ).Return (nil )
109112 gitClient .On ("IsRevisionPresent" , mock .Anything ).Return (false )
110113 gitClient .On ("Fetch" , mock .Anything ).Return (nil )
@@ -133,6 +136,10 @@ func newServiceWithMocks(t *testing.T, root string, signed bool) (*Service, *git
133136 helmClient .On ("CleanChartCache" , oobChart , version ).Return (nil )
134137 helmClient .On ("DependencyBuild" ).Return (nil )
135138
139+ ociClient .On ("GetTags" , mock .Anything , mock .Anything ).Return (nil )
140+ ociClient .On ("ResolveRevision" , mock .Anything , mock .Anything , mock .Anything ).Return ("" , nil )
141+ ociClient .On ("Extract" , mock .Anything , mock .Anything ).Return ("./testdata/my-chart" , utilio .NopCloser , nil )
142+
136143 paths .On ("Add" , mock .Anything , mock .Anything ).Return (root , nil )
137144 paths .On ("GetPath" , mock .Anything ).Return (root , nil )
138145 paths .On ("GetPathIfExists" , mock .Anything ).Return (root , nil )
@@ -144,8 +151,9 @@ func newServiceWithOpt(t *testing.T, cf clientFunc, root string) (*Service, *git
144151 t .Helper ()
145152 helmClient := & helmmocks.Client {}
146153 gitClient := & gitmocks.Client {}
154+ ociClient := & ocimocks.Client {}
147155 paths := & iomocks.TempPaths {}
148- cf (gitClient , helmClient , paths )
156+ cf (gitClient , helmClient , ociClient , paths )
149157 cacheMocks := newCacheMocks ()
150158 t .Cleanup (cacheMocks .mockCache .StopRedisCallback )
151159 service := NewService (metrics .NewMetricsServer (), cacheMocks .cache , RepoServerInitConstants {ParallelismLimit : 1 }, & git.NoopCredsStore {}, root )
@@ -156,6 +164,9 @@ func newServiceWithOpt(t *testing.T, cf clientFunc, root string) (*Service, *git
156164 service .newHelmClient = func (_ string , _ helm.Creds , _ bool , _ string , _ string , _ ... helm.ClientOpts ) helm.Client {
157165 return helmClient
158166 }
167+ service .newOCIClient = func (_ string , _ oci.Creds , _ string , _ string , _ []string , _ ... oci.ClientOpts ) (oci.Client , error ) {
168+ return ociClient , nil
169+ }
159170 service .gitRepoInitializer = func (_ string ) goio.Closer {
160171 return utilio .NopCloser
161172 }
@@ -184,7 +195,7 @@ func newServiceWithCommitSHA(t *testing.T, root, revision string) *Service {
184195 revisionErr = errors .New ("not a commit SHA" )
185196 }
186197
187- service , gitClient , _ := newServiceWithOpt (t , func (gitClient * gitmocks.Client , _ * helmmocks.Client , paths * iomocks.TempPaths ) {
198+ service , gitClient , _ := newServiceWithOpt (t , func (gitClient * gitmocks.Client , _ * helmmocks.Client , _ * ocimocks. Client , paths * iomocks.TempPaths ) {
188199 gitClient .On ("Init" ).Return (nil )
189200 gitClient .On ("IsRevisionPresent" , mock .Anything ).Return (false )
190201 gitClient .On ("Fetch" , mock .Anything ).Return (nil )
@@ -3515,7 +3526,7 @@ func TestErrorGetGitDirectories(t *testing.T) {
35153526 },
35163527 }, want : nil , wantErr : assert .Error },
35173528 {name : "InvalidResolveRevision" , fields : fields {service : func () * Service {
3518- s , _ , _ := newServiceWithOpt (t , func (gitClient * gitmocks.Client , _ * helmmocks.Client , paths * iomocks.TempPaths ) {
3529+ s , _ , _ := newServiceWithOpt (t , func (gitClient * gitmocks.Client , _ * helmmocks.Client , _ * ocimocks. Client , paths * iomocks.TempPaths ) {
35193530 gitClient .On ("Checkout" , mock .Anything , mock .Anything ).Return ("" , nil )
35203531 gitClient .On ("LsRemote" , mock .Anything ).Return ("" , errors .New ("ah error" ))
35213532 gitClient .On ("Root" ).Return (root )
@@ -3532,7 +3543,7 @@ func TestErrorGetGitDirectories(t *testing.T) {
35323543 },
35333544 }, want : nil , wantErr : assert .Error },
35343545 {name : "ErrorVerifyCommit" , fields : fields {service : func () * Service {
3535- s , _ , _ := newServiceWithOpt (t , func (gitClient * gitmocks.Client , _ * helmmocks.Client , paths * iomocks.TempPaths ) {
3546+ s , _ , _ := newServiceWithOpt (t , func (gitClient * gitmocks.Client , _ * helmmocks.Client , _ * ocimocks. Client , paths * iomocks.TempPaths ) {
35363547 gitClient .On ("Checkout" , mock .Anything , mock .Anything ).Return ("" , nil )
35373548 gitClient .On ("LsRemote" , mock .Anything ).Return ("" , errors .New ("ah error" ))
35383549 gitClient .On ("VerifyCommitSignature" , mock .Anything ).Return ("" , fmt .Errorf ("revision %s is not signed" , "sadfsadf" ))
@@ -3566,7 +3577,7 @@ func TestErrorGetGitDirectories(t *testing.T) {
35663577func TestGetGitDirectories (t * testing.T ) {
35673578 // test not using the cache
35683579 root := "./testdata/git-files-dirs"
3569- s , _ , cacheMocks := newServiceWithOpt (t , func (gitClient * gitmocks.Client , _ * helmmocks.Client , paths * iomocks.TempPaths ) {
3580+ s , _ , cacheMocks := newServiceWithOpt (t , func (gitClient * gitmocks.Client , _ * helmmocks.Client , _ * ocimocks. Client , paths * iomocks.TempPaths ) {
35703581 gitClient .On ("Init" ).Return (nil )
35713582 gitClient .On ("IsRevisionPresent" , mock .Anything ).Return (false )
35723583 gitClient .On ("Fetch" , mock .Anything ).Return (nil )
@@ -3599,7 +3610,7 @@ func TestGetGitDirectories(t *testing.T) {
35993610func TestGetGitDirectoriesWithHiddenDirSupported (t * testing.T ) {
36003611 // test not using the cache
36013612 root := "./testdata/git-files-dirs"
3602- s , _ , cacheMocks := newServiceWithOpt (t , func (gitClient * gitmocks.Client , _ * helmmocks.Client , paths * iomocks.TempPaths ) {
3613+ s , _ , cacheMocks := newServiceWithOpt (t , func (gitClient * gitmocks.Client , _ * helmmocks.Client , _ * ocimocks. Client , paths * iomocks.TempPaths ) {
36033614 gitClient .On ("Init" ).Return (nil )
36043615 gitClient .On ("IsRevisionPresent" , mock .Anything ).Return (false )
36053616 gitClient .On ("Fetch" , mock .Anything ).Return (nil )
@@ -3657,7 +3668,7 @@ func TestErrorGetGitFiles(t *testing.T) {
36573668 },
36583669 }, want : nil , wantErr : assert .Error },
36593670 {name : "InvalidResolveRevision" , fields : fields {service : func () * Service {
3660- s , _ , _ := newServiceWithOpt (t , func (gitClient * gitmocks.Client , _ * helmmocks.Client , paths * iomocks.TempPaths ) {
3671+ s , _ , _ := newServiceWithOpt (t , func (gitClient * gitmocks.Client , _ * helmmocks.Client , _ * ocimocks. Client , paths * iomocks.TempPaths ) {
36613672 gitClient .On ("Checkout" , mock .Anything , mock .Anything ).Return ("" , nil )
36623673 gitClient .On ("LsRemote" , mock .Anything ).Return ("" , errors .New ("ah error" ))
36633674 gitClient .On ("Root" ).Return (root )
@@ -3693,7 +3704,7 @@ func TestGetGitFiles(t *testing.T) {
36933704 "./testdata/git-files-dirs/config.yaml" , "./testdata/git-files-dirs/config.yaml" , "./testdata/git-files-dirs/app/foo/bar/config.yaml" ,
36943705 }
36953706 root := ""
3696- s , _ , cacheMocks := newServiceWithOpt (t , func (gitClient * gitmocks.Client , _ * helmmocks.Client , paths * iomocks.TempPaths ) {
3707+ s , _ , cacheMocks := newServiceWithOpt (t , func (gitClient * gitmocks.Client , _ * helmmocks.Client , _ * ocimocks. Client , paths * iomocks.TempPaths ) {
36973708 gitClient .On ("Init" ).Return (nil )
36983709 gitClient .On ("IsRevisionPresent" , mock .Anything ).Return (false )
36993710 gitClient .On ("Fetch" , mock .Anything ).Return (nil )
@@ -3760,7 +3771,7 @@ func TestErrorUpdateRevisionForPaths(t *testing.T) {
37603771 },
37613772 }, want : nil , wantErr : assert .Error },
37623773 {name : "InvalidResolveRevision" , fields : fields {service : func () * Service {
3763- s , _ , _ := newServiceWithOpt (t , func (gitClient * gitmocks.Client , _ * helmmocks.Client , paths * iomocks.TempPaths ) {
3774+ s , _ , _ := newServiceWithOpt (t , func (gitClient * gitmocks.Client , _ * helmmocks.Client , _ * ocimocks. Client , paths * iomocks.TempPaths ) {
37643775 gitClient .On ("Checkout" , mock .Anything , mock .Anything ).Return ("" , nil )
37653776 gitClient .On ("LsRemote" , mock .Anything ).Return ("" , errors .New ("ah error" ))
37663777 gitClient .On ("Root" ).Return (root )
@@ -3778,7 +3789,7 @@ func TestErrorUpdateRevisionForPaths(t *testing.T) {
37783789 },
37793790 }, want : nil , wantErr : assert .Error },
37803791 {name : "InvalidResolveSyncedRevision" , fields : fields {service : func () * Service {
3781- s , _ , _ := newServiceWithOpt (t , func (gitClient * gitmocks.Client , _ * helmmocks.Client , paths * iomocks.TempPaths ) {
3792+ s , _ , _ := newServiceWithOpt (t , func (gitClient * gitmocks.Client , _ * helmmocks.Client , _ * ocimocks. Client , paths * iomocks.TempPaths ) {
37823793 gitClient .On ("Checkout" , mock .Anything , mock .Anything ).Return ("" , nil )
37833794 gitClient .On ("LsRemote" , "HEAD" ).Once ().Return ("632039659e542ed7de0c170a4fcc1c571b288fc0" , nil )
37843795 gitClient .On ("LsRemote" , mock .Anything ).Return ("" , errors .New ("ah error" ))
@@ -3831,7 +3842,7 @@ func TestUpdateRevisionForPaths(t *testing.T) {
38313842 cacheHit * cacheHit
38323843 }{
38333844 {name : "NoPathAbort" , fields : func () fields {
3834- s , _ , c := newServiceWithOpt (t , func (gitClient * gitmocks.Client , _ * helmmocks.Client , _ * iomocks.TempPaths ) {
3845+ s , _ , c := newServiceWithOpt (t , func (gitClient * gitmocks.Client , _ * helmmocks.Client , _ * ocimocks. Client , _ * iomocks.TempPaths ) {
38353846 gitClient .On ("Checkout" , mock .Anything , mock .Anything ).Return ("" , nil )
38363847 }, "." )
38373848 return fields {
@@ -3846,7 +3857,7 @@ func TestUpdateRevisionForPaths(t *testing.T) {
38463857 },
38473858 }, want : & apiclient.UpdateRevisionForPathsResponse {}, wantErr : assert .NoError },
38483859 {name : "SameResolvedRevisionAbort" , fields : func () fields {
3849- s , _ , c := newServiceWithOpt (t , func (gitClient * gitmocks.Client , _ * helmmocks.Client , paths * iomocks.TempPaths ) {
3860+ s , _ , c := newServiceWithOpt (t , func (gitClient * gitmocks.Client , _ * helmmocks.Client , _ * ocimocks. Client , paths * iomocks.TempPaths ) {
38503861 gitClient .On ("Checkout" , mock .Anything , mock .Anything ).Return ("" , nil )
38513862 gitClient .On ("LsRemote" , "HEAD" ).Once ().Return ("632039659e542ed7de0c170a4fcc1c571b288fc0" , nil )
38523863 gitClient .On ("LsRemote" , "SYNCEDHEAD" ).Once ().Return ("632039659e542ed7de0c170a4fcc1c571b288fc0" , nil )
@@ -3869,7 +3880,7 @@ func TestUpdateRevisionForPaths(t *testing.T) {
38693880 Revision : "632039659e542ed7de0c170a4fcc1c571b288fc0" ,
38703881 }, wantErr : assert .NoError },
38713882 {name : "ChangedFilesDoNothing" , fields : func () fields {
3872- s , _ , c := newServiceWithOpt (t , func (gitClient * gitmocks.Client , _ * helmmocks.Client , paths * iomocks.TempPaths ) {
3883+ s , _ , c := newServiceWithOpt (t , func (gitClient * gitmocks.Client , _ * helmmocks.Client , _ * ocimocks. Client , paths * iomocks.TempPaths ) {
38733884 gitClient .On ("Init" ).Return (nil )
38743885 gitClient .On ("Fetch" , mock .Anything ).Once ().Return (nil )
38753886 gitClient .On ("IsRevisionPresent" , "632039659e542ed7de0c170a4fcc1c571b288fc0" ).Once ().Return (false )
@@ -3902,7 +3913,7 @@ func TestUpdateRevisionForPaths(t *testing.T) {
39023913 Changes : true ,
39033914 }, wantErr : assert .NoError },
39043915 {name : "NoChangesUpdateCache" , fields : func () fields {
3905- s , _ , c := newServiceWithOpt (t , func (gitClient * gitmocks.Client , _ * helmmocks.Client , paths * iomocks.TempPaths ) {
3916+ s , _ , c := newServiceWithOpt (t , func (gitClient * gitmocks.Client , _ * helmmocks.Client , _ * ocimocks. Client , paths * iomocks.TempPaths ) {
39063917 gitClient .On ("Init" ).Return (nil )
39073918 gitClient .On ("Fetch" , mock .Anything ).Once ().Return (nil )
39083919 gitClient .On ("IsRevisionPresent" , "632039659e542ed7de0c170a4fcc1c571b288fc0" ).Once ().Return (false )
@@ -3944,7 +3955,7 @@ func TestUpdateRevisionForPaths(t *testing.T) {
39443955 revision : "632039659e542ed7de0c170a4fcc1c571b288fc0" ,
39453956 }},
39463957 {name : "NoChangesHelmMultiSourceUpdateCache" , fields : func () fields {
3947- s , _ , c := newServiceWithOpt (t , func (gitClient * gitmocks.Client , _ * helmmocks.Client , paths * iomocks.TempPaths ) {
3958+ s , _ , c := newServiceWithOpt (t , func (gitClient * gitmocks.Client , _ * helmmocks.Client , _ * ocimocks. Client , paths * iomocks.TempPaths ) {
39483959 gitClient .On ("Init" ).Return (nil )
39493960 gitClient .On ("IsRevisionPresent" , "632039659e542ed7de0c170a4fcc1c571b288fc0" ).Once ().Return (false )
39503961 gitClient .On ("Fetch" , mock .Anything ).Once ().Return (nil )
@@ -4480,3 +4491,34 @@ func Test_SkipSchemaValidation(t *testing.T) {
44804491 require .ErrorContains (t , err , "values don't meet the specifications of the schema(s)" )
44814492 })
44824493}
4494+
4495+ func TestGenerateManifest_OCISourceSkipsGitClient (t * testing.T ) {
4496+ svc := newService (t , t .TempDir ())
4497+
4498+ gitCalled := false
4499+ svc .newGitClient = func (_ , _ string , _ git.Creds , _ , _ bool , _ , _ string , _ ... git.ClientOpts ) (git.Client , error ) {
4500+ gitCalled = true
4501+ return nil , errors .New ("git should not be called for OCI" )
4502+ }
4503+
4504+ req := & apiclient.ManifestRequest {
4505+ HasMultipleSources : true ,
4506+ Repo : & v1alpha1.Repository {
4507+ Repo : "oci://example.com/foo" ,
4508+ },
4509+ ApplicationSource : & v1alpha1.ApplicationSource {
4510+ Path : "" ,
4511+ TargetRevision : "v1" ,
4512+ Ref : "foo" ,
4513+ RepoURL : "oci://example.com/foo" ,
4514+ },
4515+ ProjectName : "foo-project" ,
4516+ ProjectSourceRepos : []string {"*" },
4517+ }
4518+
4519+ _ , err := svc .GenerateManifest (t .Context (), req )
4520+ require .NoError (t , err )
4521+
4522+ // verify that newGitClient was never invoked
4523+ assert .False (t , gitCalled , "GenerateManifest should not invoke Git for OCI sources" )
4524+ }
0 commit comments