@@ -26,10 +26,10 @@ import (
2626 . "github.com/onsi/gomega"
2727 "github.com/otiai10/copy"
2828 helmchart "helm.sh/helm/v3/pkg/chart"
29- "helm.sh/helm/v3/pkg/chart/loader"
3029 "helm.sh/helm/v3/pkg/chartutil"
3130 "helm.sh/helm/v3/pkg/repo"
3231
32+ "github.com/fluxcd/source-controller/internal/helm/chart/secureloader"
3333 "github.com/fluxcd/source-controller/internal/helm/repository"
3434)
3535
@@ -86,31 +86,31 @@ func TestLocalBuilder_Build(t *testing.T) {
8686 },
8787 {
8888 name : "invalid local reference - no file" ,
89- reference : LocalReference {Path : "/tmp/ non-existent-path.xyz" },
89+ reference : LocalReference {WorkDir : "/tmp" , Path : " non-existent-path.xyz" },
9090 wantErr : "no such file or directory" ,
9191 },
9292 {
9393 name : "invalid version metadata" ,
94- reference : LocalReference {Path : "./. ./testdata/charts/helmchart" },
94+ reference : LocalReference {Path : "../testdata/charts/helmchart" },
9595 buildOpts : BuildOptions {VersionMetadata : "^" },
9696 wantErr : "Invalid Metadata string" ,
9797 },
9898 {
9999 name : "with version metadata" ,
100- reference : LocalReference {Path : "./. ./testdata/charts/helmchart" },
100+ reference : LocalReference {Path : "../testdata/charts/helmchart" },
101101 buildOpts : BuildOptions {VersionMetadata : "foo" },
102102 wantVersion : "0.1.0+foo" ,
103103 wantPackaged : true ,
104104 },
105105 {
106106 name : "already packaged chart" ,
107- reference : LocalReference {Path : "./. ./testdata/charts/helmchart-0.1.0.tgz" },
107+ reference : LocalReference {Path : "../testdata/charts/helmchart-0.1.0.tgz" },
108108 wantVersion : "0.1.0" ,
109109 wantPackaged : false ,
110110 },
111111 {
112112 name : "default values" ,
113- reference : LocalReference {Path : "./. ./testdata/charts/helmchart" },
113+ reference : LocalReference {Path : "../testdata/charts/helmchart" },
114114 wantValues : chartutil.Values {
115115 "replicaCount" : float64 (1 ),
116116 },
@@ -119,7 +119,7 @@ func TestLocalBuilder_Build(t *testing.T) {
119119 },
120120 {
121121 name : "with values files" ,
122- reference : LocalReference {Path : "./. ./testdata/charts/helmchart" },
122+ reference : LocalReference {Path : "../testdata/charts/helmchart" },
123123 buildOpts : BuildOptions {
124124 ValuesFiles : []string {"custom-values1.yaml" , "custom-values2.yaml" },
125125 },
@@ -145,7 +145,7 @@ fullnameOverride: "full-foo-name-override"`),
145145 },
146146 {
147147 name : "chart with dependencies" ,
148- reference : LocalReference {Path : "./. ./testdata/charts/helmchartwithdeps" },
148+ reference : LocalReference {Path : "../testdata/charts/helmchartwithdeps" },
149149 repositories : map [string ]* repository.ChartRepository {
150150 "https://grafana.github.io/helm-charts/" : mockRepo (),
151151 },
@@ -164,11 +164,11 @@ fullnameOverride: "full-foo-name-override"`),
164164 },
165165 {
166166 name : "v1 chart with dependencies" ,
167- reference : LocalReference {Path : "./. ./testdata/charts/helmchartwithdeps-v1" },
167+ reference : LocalReference {Path : "../testdata/charts/helmchartwithdeps-v1" },
168168 repositories : map [string ]* repository.ChartRepository {
169169 "https://grafana.github.io/helm-charts/" : mockRepo (),
170170 },
171- dependentChartPaths : []string {"./. ./testdata/charts/helmchart-v1" },
171+ dependentChartPaths : []string {"../testdata/charts/helmchart-v1" },
172172 wantVersion : "0.3.0" ,
173173 wantPackaged : true ,
174174 },
@@ -184,13 +184,23 @@ fullnameOverride: "full-foo-name-override"`),
184184 // Only if the reference is a LocalReference, set the WorkDir.
185185 localRef , ok := tt .reference .(LocalReference )
186186 if ok {
187+ // If the source chart path is valid, copy it into the workdir
188+ // and update the localRef.Path with the copied local chart
189+ // path.
190+ if localRef .Path != "" {
191+ _ , err := os .Lstat (localRef .Path )
192+ if err == nil {
193+ helmchartDir := filepath .Join (workDir , "testdata" , "charts" , filepath .Base (localRef .Path ))
194+ g .Expect (copy .Copy (localRef .Path , helmchartDir )).ToNot (HaveOccurred ())
195+ }
196+ }
187197 localRef .WorkDir = workDir
188198 tt .reference = localRef
189199 }
190200
191201 // Write value file in the base dir.
192202 for _ , f := range tt .valuesFiles {
193- vPath := filepath .Join (workDir , f .Name )
203+ vPath := filepath .Join (localRef . WorkDir , f .Name )
194204 g .Expect (os .WriteFile (vPath , f .Data , 0644 )).ToNot (HaveOccurred ())
195205 }
196206
@@ -223,7 +233,7 @@ fullnameOverride: "full-foo-name-override"`),
223233 g .Expect (cb .Path ).ToNot (BeEmpty (), "empty Build.Path" )
224234
225235 // Load the resulting chart and verify the values.
226- resultChart , err := loader . Load (cb .Path )
236+ resultChart , err := secureloader . LoadFile (cb .Path )
227237 g .Expect (err ).ToNot (HaveOccurred ())
228238 g .Expect (resultChart .Metadata .Version ).To (Equal (tt .wantVersion ))
229239
@@ -241,7 +251,7 @@ func TestLocalBuilder_Build_CachedChart(t *testing.T) {
241251 g .Expect (err ).ToNot (HaveOccurred ())
242252 defer os .RemoveAll (workDir )
243253
244- reference := LocalReference { Path : "./../testdata/charts/helmchart" }
254+ testChartPath := "./../testdata/charts/helmchart"
245255
246256 dm := NewDependencyManager ()
247257 b := NewLocalBuilder (dm )
@@ -250,6 +260,11 @@ func TestLocalBuilder_Build_CachedChart(t *testing.T) {
250260 g .Expect (err ).ToNot (HaveOccurred ())
251261 defer os .RemoveAll (tmpDir )
252262
263+ // Copy the source chart into the workdir.
264+ g .Expect (copy .Copy (testChartPath , filepath .Join (workDir , "testdata" , "charts" , filepath .Base ("helmchart" )))).ToNot (HaveOccurred ())
265+
266+ reference := LocalReference {WorkDir : workDir , Path : testChartPath }
267+
253268 // Build first time.
254269 targetPath := filepath .Join (tmpDir , "chart1.tgz" )
255270 buildOpts := BuildOptions {}
0 commit comments