@@ -18,9 +18,11 @@ package controllers
18
18
19
19
import (
20
20
"context"
21
+ "fmt"
21
22
"testing"
22
23
"time"
23
24
25
+ "github.com/fluxcd/pkg/apis/meta"
24
26
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
25
27
"github.com/go-logr/logr"
26
28
. "github.com/onsi/gomega"
@@ -371,6 +373,39 @@ func Test_buildHelmChartFromTemplate(t *testing.T) {
371
373
},
372
374
},
373
375
},
376
+ {
377
+ name : "take cosign verification into account" ,
378
+ modify : func (hr * v2.HelmRelease ) {
379
+ hr .Spec .Chart .Spec .Verify = & sourcev1.OCIRepositoryVerification {
380
+ Provider : "cosign" ,
381
+ SecretRef : & meta.LocalObjectReference {
382
+ Name : "cosign-key" ,
383
+ },
384
+ }
385
+ },
386
+ want : & sourcev1.HelmChart {
387
+ ObjectMeta : metav1.ObjectMeta {
388
+ Name : "default-test-release" ,
389
+ Namespace : "default" ,
390
+ },
391
+ Spec : sourcev1.HelmChartSpec {
392
+ Chart : "chart" ,
393
+ Version : "1.0.0" ,
394
+ SourceRef : sourcev1.LocalHelmChartSourceReference {
395
+ Name : "test-repository" ,
396
+ Kind : "HelmRepository" ,
397
+ },
398
+ Interval : metav1.Duration {Duration : 2 * time .Minute },
399
+ ValuesFiles : []string {"values.yaml" },
400
+ Verify : & sourcev1.OCIRepositoryVerification {
401
+ Provider : "cosign" ,
402
+ SecretRef : & meta.LocalObjectReference {
403
+ Name : "cosign-key" ,
404
+ },
405
+ },
406
+ },
407
+ },
408
+ },
374
409
}
375
410
for _ , tt := range tests {
376
411
t .Run (tt .name , func (t * testing.T ) {
@@ -398,6 +433,9 @@ func Test_helmChartRequiresUpdate(t *testing.T) {
398
433
Kind : "HelmRepository" ,
399
434
},
400
435
Interval : & metav1.Duration {Duration : 2 * time .Minute },
436
+ Verify : & sourcev1.OCIRepositoryVerification {
437
+ Provider : "cosign" ,
438
+ },
401
439
},
402
440
},
403
441
},
@@ -469,16 +507,26 @@ func Test_helmChartRequiresUpdate(t *testing.T) {
469
507
},
470
508
want : true ,
471
509
},
510
+ {
511
+ name : "detects verify change" ,
512
+ modify : func (hr * v2.HelmRelease , hc * sourcev1.HelmChart ) {
513
+ hr .Spec .Chart .Spec .Verify .Provider = "foo-bar"
514
+ },
515
+ want : true ,
516
+ },
472
517
}
473
518
for _ , tt := range tests {
474
519
t .Run (tt .name , func (t * testing.T ) {
475
520
g := NewWithT (t )
476
521
477
522
hr := hrWithChartTemplate .DeepCopy ()
478
523
hc := buildHelmChartFromTemplate (hr )
524
+ // second copy to avoid modifying the original
525
+ hr = hrWithChartTemplate .DeepCopy ()
479
526
g .Expect (helmChartRequiresUpdate (hr , hc )).To (Equal (false ))
480
527
481
528
tt .modify (hr , hc )
529
+ fmt .Println ("verify" , hr .Spec .Chart .Spec .Verify .Provider , hc .Spec .Verify .Provider )
482
530
g .Expect (helmChartRequiresUpdate (hr , hc )).To (Equal (tt .want ))
483
531
})
484
532
}
0 commit comments