@@ -35,26 +35,28 @@ import (
35
35
fileutil "github.com/argoproj/argo-cd/v2/test/fixture/path"
36
36
"github.com/argoproj/argo-cd/v2/util/argo"
37
37
cacheutil "github.com/argoproj/argo-cd/v2/util/cache"
38
+ dbmocks "github.com/argoproj/argo-cd/v2/util/db/mocks"
38
39
"github.com/argoproj/argo-cd/v2/util/git"
39
40
gitmocks "github.com/argoproj/argo-cd/v2/util/git/mocks"
40
41
"github.com/argoproj/argo-cd/v2/util/helm"
41
42
helmmocks "github.com/argoproj/argo-cd/v2/util/helm/mocks"
42
43
"github.com/argoproj/argo-cd/v2/util/io"
44
+ iomocks "github.com/argoproj/argo-cd/v2/util/io/mocks"
43
45
)
44
46
45
47
const testSignature = `gpg: Signature made Wed Feb 26 23:22:34 2020 CET
46
48
gpg: using RSA key 4AEE18F83AFDEB23
47
49
gpg: Good signature from "GitHub (web-flow commit signing) <noreply@github.com>" [ultimate]
48
50
`
49
51
50
- type clientFunc func (* gitmocks.Client , * helmmocks.Client )
52
+ type clientFunc func (* gitmocks.Client , * helmmocks.Client , * iomocks. TempPaths )
51
53
52
54
func newServiceWithMocks (root string , signed bool ) (* Service , * gitmocks.Client ) {
53
55
root , err := filepath .Abs (root )
54
56
if err != nil {
55
57
panic (err )
56
58
}
57
- return newServiceWithOpt (func (gitClient * gitmocks.Client , helmClient * helmmocks.Client ) {
59
+ return newServiceWithOpt (func (gitClient * gitmocks.Client , helmClient * helmmocks.Client , paths * iomocks. TempPaths ) {
58
60
gitClient .On ("Init" ).Return (nil )
59
61
gitClient .On ("Fetch" , mock .Anything ).Return (nil )
60
62
gitClient .On ("Checkout" , mock .Anything , mock .Anything ).Return (nil )
@@ -79,13 +81,17 @@ func newServiceWithMocks(root string, signed bool) (*Service, *gitmocks.Client)
79
81
helmClient .On ("CleanChartCache" , chart , version ).Return (nil )
80
82
helmClient .On ("CleanChartCache" , oobChart , version ).Return (nil )
81
83
helmClient .On ("DependencyBuild" ).Return (nil )
84
+
85
+ paths .On ("GetPath" , mock .Anything ).Return (root , nil )
86
+ paths .On ("GetPathIfExists" , mock .Anything ).Return (root , nil )
82
87
}, root )
83
88
}
84
89
85
90
func newServiceWithOpt (cf clientFunc , root string ) (* Service , * gitmocks.Client ) {
86
91
helmClient := & helmmocks.Client {}
87
92
gitClient := & gitmocks.Client {}
88
- cf (gitClient , helmClient )
93
+ paths := & iomocks.TempPaths {}
94
+ cf (gitClient , helmClient , paths )
89
95
service := NewService (metrics .NewMetricsServer (), cache .NewCache (
90
96
cacheutil .NewCache (cacheutil .NewInMemoryCache (1 * time .Minute )),
91
97
1 * time .Minute ,
@@ -101,6 +107,7 @@ func newServiceWithOpt(cf clientFunc, root string) (*Service, *gitmocks.Client)
101
107
service .gitRepoInitializer = func (rootPath string ) goio.Closer {
102
108
return io .NopCloser
103
109
}
110
+ service .gitRepoPaths = paths
104
111
return service , gitClient
105
112
}
106
113
@@ -122,7 +129,7 @@ func newServiceWithCommitSHA(root, revision string) *Service {
122
129
revisionErr = errors .New ("not a commit SHA" )
123
130
}
124
131
125
- service , gitClient := newServiceWithOpt (func (gitClient * gitmocks.Client , helmClient * helmmocks.Client ) {
132
+ service , gitClient := newServiceWithOpt (func (gitClient * gitmocks.Client , helmClient * helmmocks.Client , paths * iomocks. TempPaths ) {
126
133
gitClient .On ("Init" ).Return (nil )
127
134
gitClient .On ("Fetch" , mock .Anything ).Return (nil )
128
135
gitClient .On ("Checkout" , mock .Anything , mock .Anything ).Return (nil )
@@ -286,6 +293,35 @@ func TestHelmManifestFromChartRepo(t *testing.T) {
286
293
}, response )
287
294
}
288
295
296
+ func TestHelmChartReferencingExternalValues (t * testing.T ) {
297
+ service := newService ("." )
298
+ spec := argoappv1.ApplicationSpec {
299
+ Sources : []argoappv1.ApplicationSource {
300
+ {RepoURL : "https://helm.example.com" , Chart : "my-chart" , TargetRevision : ">= 1.0.0" , Helm : & argoappv1.ApplicationSourceHelm {
301
+ ValueFiles : []string {"$ref/testdata/my-chart/my-chart-values.yaml" },
302
+ }},
303
+ {Ref : "ref" , RepoURL : "https://git.example.com/test/repo" },
304
+ },
305
+ }
306
+ repoDB := & dbmocks.ArgoDB {}
307
+ repoDB .On ("GetRepository" , context .Background (), "https://git.example.com/test/repo" ).Return (& argoappv1.Repository {
308
+ Repo : "https://git.example.com/test/repo" ,
309
+ }, nil )
310
+ refSources , err := argo .GetRefSources (context .Background (), spec , repoDB )
311
+ require .NoError (t , err )
312
+ request := & apiclient.ManifestRequest {Repo : & argoappv1.Repository {}, ApplicationSource : & spec .Sources [0 ], NoCache : true , RefSources : refSources , HasMultipleSources : true }
313
+ response , err := service .GenerateManifest (context .Background (), request )
314
+ assert .NoError (t , err )
315
+ assert .NotNil (t , response )
316
+ assert .Equal (t , & apiclient.ManifestResponse {
317
+ Manifests : []string {"{\" apiVersion\" :\" v1\" ,\" kind\" :\" ConfigMap\" ,\" metadata\" :{\" name\" :\" my-map\" }}" },
318
+ Namespace : "" ,
319
+ Server : "" ,
320
+ Revision : "1.1.0" ,
321
+ SourceType : "Helm" ,
322
+ }, response )
323
+ }
324
+
289
325
func TestGenerateManifestsUseExactRevision (t * testing.T ) {
290
326
service , gitClient := newServiceWithMocks ("." , false )
291
327
@@ -2496,7 +2532,7 @@ func Test_findHelmValueFilesInPath(t *testing.T) {
2496
2532
}
2497
2533
2498
2534
func Test_populateHelmAppDetails (t * testing.T ) {
2499
- var emptyTempPaths = io .NewTempPaths (t .TempDir ())
2535
+ var emptyTempPaths = io .NewRandomizedTempPaths (t .TempDir ())
2500
2536
res := apiclient.RepoAppDetailsResponse {}
2501
2537
q := apiclient.RepoServerAppDetailsQuery {
2502
2538
Repo : & argoappv1.Repository {},
@@ -2513,7 +2549,7 @@ func Test_populateHelmAppDetails(t *testing.T) {
2513
2549
}
2514
2550
2515
2551
func Test_populateHelmAppDetails_values_symlinks (t * testing.T ) {
2516
- var emptyTempPaths = io .NewTempPaths (t .TempDir ())
2552
+ var emptyTempPaths = io .NewRandomizedTempPaths (t .TempDir ())
2517
2553
t .Run ("inbound" , func (t * testing.T ) {
2518
2554
res := apiclient.RepoAppDetailsResponse {}
2519
2555
q := apiclient.RepoServerAppDetailsQuery {Repo : & argoappv1.Repository {}, Source : & argoappv1.ApplicationSource {}}
@@ -2550,7 +2586,7 @@ func TestOCIDependencies(t *testing.T) {
2550
2586
2551
2587
func Test_getResolvedValueFiles (t * testing.T ) {
2552
2588
tempDir := t .TempDir ()
2553
- paths := io .NewTempPaths (tempDir )
2589
+ paths := io .NewRandomizedTempPaths (tempDir )
2554
2590
paths .Add (git .NormalizeGitURL ("https://github.com/org/repo1" ), path .Join (tempDir , "repo1" ))
2555
2591
2556
2592
testCases := []struct {
0 commit comments