@@ -547,30 +547,35 @@ func TestGitRepositoryReconciler_reconcileSource_checkoutStrategy(t *testing.T)
547
547
name string
548
548
skipForImplementation string
549
549
reference * sourcev1.GitRepositoryRef
550
+ beforeFunc func (obj * sourcev1.GitRepository , latestRev string )
550
551
want sreconcile.Result
551
552
wantErr bool
552
553
wantRevision string
554
+ wantArtifactOutdated bool
553
555
}{
554
556
{
555
- name : "Nil reference (default branch)" ,
556
- want : sreconcile .ResultSuccess ,
557
- wantRevision : "master/<commit>" ,
557
+ name : "Nil reference (default branch)" ,
558
+ want : sreconcile .ResultSuccess ,
559
+ wantRevision : "master/<commit>" ,
560
+ wantArtifactOutdated : true ,
558
561
},
559
562
{
560
563
name : "Branch" ,
561
564
reference : & sourcev1.GitRepositoryRef {
562
565
Branch : "staging" ,
563
566
},
564
- want : sreconcile .ResultSuccess ,
565
- wantRevision : "staging/<commit>" ,
567
+ want : sreconcile .ResultSuccess ,
568
+ wantRevision : "staging/<commit>" ,
569
+ wantArtifactOutdated : true ,
566
570
},
567
571
{
568
572
name : "Tag" ,
569
573
reference : & sourcev1.GitRepositoryRef {
570
574
Tag : "v0.1.0" ,
571
575
},
572
- want : sreconcile .ResultSuccess ,
573
- wantRevision : "v0.1.0/<commit>" ,
576
+ want : sreconcile .ResultSuccess ,
577
+ wantRevision : "v0.1.0/<commit>" ,
578
+ wantArtifactOutdated : true ,
574
579
},
575
580
{
576
581
name : "Branch commit" ,
@@ -579,8 +584,9 @@ func TestGitRepositoryReconciler_reconcileSource_checkoutStrategy(t *testing.T)
579
584
Branch : "staging" ,
580
585
Commit : "<commit>" ,
581
586
},
582
- want : sreconcile .ResultSuccess ,
583
- wantRevision : "staging/<commit>" ,
587
+ want : sreconcile .ResultSuccess ,
588
+ wantRevision : "staging/<commit>" ,
589
+ wantArtifactOutdated : true ,
584
590
},
585
591
{
586
592
name : "Branch commit" ,
@@ -589,32 +595,56 @@ func TestGitRepositoryReconciler_reconcileSource_checkoutStrategy(t *testing.T)
589
595
Branch : "staging" ,
590
596
Commit : "<commit>" ,
591
597
},
592
- want : sreconcile .ResultSuccess ,
593
- wantRevision : "HEAD/<commit>" ,
598
+ want : sreconcile .ResultSuccess ,
599
+ wantRevision : "HEAD/<commit>" ,
600
+ wantArtifactOutdated : true ,
594
601
},
595
602
{
596
603
name : "SemVer" ,
597
604
reference : & sourcev1.GitRepositoryRef {
598
605
SemVer : "*" ,
599
606
},
600
- want : sreconcile .ResultSuccess ,
601
- wantRevision : "v2.0.0/<commit>" ,
607
+ want : sreconcile .ResultSuccess ,
608
+ wantRevision : "v2.0.0/<commit>" ,
609
+ wantArtifactOutdated : true ,
602
610
},
603
611
{
604
612
name : "SemVer range" ,
605
613
reference : & sourcev1.GitRepositoryRef {
606
614
SemVer : "<v0.2.1" ,
607
615
},
608
- want : sreconcile .ResultSuccess ,
609
- wantRevision : "0.2.0/<commit>" ,
616
+ want : sreconcile .ResultSuccess ,
617
+ wantRevision : "0.2.0/<commit>" ,
618
+ wantArtifactOutdated : true ,
610
619
},
611
620
{
612
621
name : "SemVer prerelease" ,
613
622
reference : & sourcev1.GitRepositoryRef {
614
623
SemVer : ">=1.0.0-0 <1.1.0-0" ,
615
624
},
616
- wantRevision : "v1.0.0-alpha/<commit>" ,
617
- want : sreconcile .ResultSuccess ,
625
+ wantRevision : "v1.0.0-alpha/<commit>" ,
626
+ want : sreconcile .ResultSuccess ,
627
+ wantArtifactOutdated : true ,
628
+ },
629
+ {
630
+ name : "Optimized clone" ,
631
+ reference : & sourcev1.GitRepositoryRef {
632
+ Branch : "staging" ,
633
+ },
634
+ beforeFunc : func (obj * sourcev1.GitRepository , latestRev string ) {
635
+ // Add existing artifact on the object and storage.
636
+ obj .Status = sourcev1.GitRepositoryStatus {
637
+ Artifact : & sourcev1.Artifact {
638
+ Revision : "staging/" + latestRev ,
639
+ Path : randStringRunes (10 ),
640
+ },
641
+ }
642
+ testStorage .Archive (obj .GetArtifact (), "testdata/git/repository" , nil )
643
+ conditions .MarkTrue (obj , sourcev1 .ArtifactInStorageCondition , meta .SucceededReason , "foo" )
644
+ },
645
+ want : sreconcile .ResultSuccess ,
646
+ wantRevision : "staging/<commit>" ,
647
+ wantArtifactOutdated : false ,
618
648
},
619
649
}
620
650
@@ -677,6 +707,10 @@ func TestGitRepositoryReconciler_reconcileSource_checkoutStrategy(t *testing.T)
677
707
obj := obj .DeepCopy ()
678
708
obj .Spec .GitImplementation = i
679
709
710
+ if tt .beforeFunc != nil {
711
+ tt .beforeFunc (obj , headRef .Hash ().String ())
712
+ }
713
+
680
714
var commit git.Commit
681
715
var includes artifactSet
682
716
got , err := r .reconcileSource (ctx , obj , & commit , & includes , tmpDir )
@@ -685,10 +719,10 @@ func TestGitRepositoryReconciler_reconcileSource_checkoutStrategy(t *testing.T)
685
719
}
686
720
g .Expect (err != nil ).To (Equal (tt .wantErr ))
687
721
g .Expect (got ).To (Equal (tt .want ))
688
- if tt .wantRevision != "" {
722
+ if tt .wantRevision != "" && ! tt . wantErr {
689
723
revision := strings .ReplaceAll (tt .wantRevision , "<commit>" , headRef .Hash ().String ())
690
724
g .Expect (commit .String ()).To (Equal (revision ))
691
- g .Expect (conditions .IsTrue (obj , sourcev1 .ArtifactOutdatedCondition )).To (BeTrue ( ))
725
+ g .Expect (conditions .IsTrue (obj , sourcev1 .ArtifactOutdatedCondition )).To (Equal ( tt . wantArtifactOutdated ))
692
726
}
693
727
})
694
728
}
0 commit comments