@@ -572,6 +572,50 @@ func TestGitRepositoryReconciler_reconcileSource_authStrategy(t *testing.T) {
572
572
* conditions .UnknownCondition (meta .ReadyCondition , meta .ProgressingReason , "building artifact: new upstream revision 'master@sha1:<commit>'" ),
573
573
},
574
574
},
575
+ {
576
+ // This test is only for verifying the failure state when using
577
+ // provider auth. Protocol http is used for simplicity.
578
+ name : "github provider without secret ref makes FetchFailed=True" ,
579
+ protocol : "http" ,
580
+ beforeFunc : func (obj * sourcev1.GitRepository ) {
581
+ obj .Spec .Provider = sourcev1 .GitProviderGitHub
582
+ conditions .MarkReconciling (obj , meta .ProgressingReason , "foo" )
583
+ conditions .MarkUnknown (obj , meta .ReadyCondition , meta .ProgressingReason , "foo" )
584
+ },
585
+ want : sreconcile .ResultEmpty ,
586
+ wantErr : true ,
587
+ assertConditions : []metav1.Condition {
588
+ * conditions .TrueCondition (sourcev1 .FetchFailedCondition , sourcev1 .InvalidProviderConfigurationReason , "secretRef with github app data must be specified when provider is set to github" ),
589
+ * conditions .TrueCondition (meta .ReconcilingCondition , meta .ProgressingReason , "foo" ),
590
+ * conditions .UnknownCondition (meta .ReadyCondition , meta .ProgressingReason , "foo" ),
591
+ },
592
+ },
593
+ {
594
+ // This test is only for verifying the failure state when using
595
+ // provider auth. Protocol http is used for simplicity.
596
+ name : "empty provider with github app data in secret makes FetchFailed=True" ,
597
+ protocol : "http" ,
598
+ secret : & corev1.Secret {
599
+ ObjectMeta : metav1.ObjectMeta {
600
+ Name : "github-app-secret" ,
601
+ },
602
+ Data : map [string ][]byte {
603
+ github .AppIDKey : []byte ("1111" ),
604
+ },
605
+ },
606
+ beforeFunc : func (obj * sourcev1.GitRepository ) {
607
+ obj .Spec .SecretRef = & meta.LocalObjectReference {Name : "github-app-secret" }
608
+ conditions .MarkReconciling (obj , meta .ProgressingReason , "foo" )
609
+ conditions .MarkUnknown (obj , meta .ReadyCondition , meta .ProgressingReason , "foo" )
610
+ },
611
+ want : sreconcile .ResultEmpty ,
612
+ wantErr : true ,
613
+ assertConditions : []metav1.Condition {
614
+ * conditions .TrueCondition (sourcev1 .FetchFailedCondition , sourcev1 .InvalidProviderConfigurationReason , "secretRef '/github-app-secret' has github app data but provider is not set to github" ),
615
+ * conditions .TrueCondition (meta .ReconcilingCondition , meta .ProgressingReason , "foo" ),
616
+ * conditions .UnknownCondition (meta .ReadyCondition , meta .ProgressingReason , "foo" ),
617
+ },
618
+ },
575
619
}
576
620
577
621
for _ , tt := range tests {
@@ -710,17 +754,6 @@ func TestGitRepositoryReconciler_getAuthOpts_provider(t *testing.T) {
710
754
wantProviderOptsName : sourcev1 .GitProviderGitHub ,
711
755
wantErr : errors .New ("secretRef with github app data must be specified when provider is set to github" ),
712
756
},
713
- {
714
- name : "github provider with secret ref that does not exist" ,
715
- url : "https://github.com/org/repo.git" ,
716
- beforeFunc : func (obj * sourcev1.GitRepository ) {
717
- obj .Spec .Provider = sourcev1 .GitProviderGitHub
718
- obj .Spec .SecretRef = & meta.LocalObjectReference {
719
- Name : "githubAppSecret" ,
720
- }
721
- },
722
- wantErr : errors .New ("failed to get secret '/githubAppSecret': secrets \" githubAppSecret\" not found" ),
723
- },
724
757
{
725
758
name : "github provider with github app data in secret" ,
726
759
url : "https://example.com/org/repo" ,
@@ -768,6 +801,16 @@ func TestGitRepositoryReconciler_getAuthOpts_provider(t *testing.T) {
768
801
obj .Spec .Provider = sourcev1 .GitProviderGeneric
769
802
},
770
803
},
804
+ {
805
+ name : "secret ref defined for non existing secret" ,
806
+ url : "https://github.com/org/repo.git" ,
807
+ beforeFunc : func (obj * sourcev1.GitRepository ) {
808
+ obj .Spec .SecretRef = & meta.LocalObjectReference {
809
+ Name : "authSecret" ,
810
+ }
811
+ },
812
+ wantErr : errors .New ("failed to get secret '/authSecret': secrets \" authSecret\" not found" ),
813
+ },
771
814
{
772
815
url : "https://example.com/org/repo" ,
773
816
name : "no provider" ,
0 commit comments