@@ -14,6 +14,7 @@ import (
14
14
"k8s.io/apimachinery/pkg/types"
15
15
16
16
"github.com/operator-framework/api/pkg/operators/v1alpha1"
17
+ "github.com/stretchr/testify/assert"
17
18
)
18
19
19
20
func TestRequirementAndPermissionStatus (t * testing.T ) {
@@ -297,7 +298,7 @@ func TestRequirementAndPermissionStatus(t *testing.T) {
297
298
Version : "v1" ,
298
299
Kind : "ServiceAccount" ,
299
300
Name : "sa" ,
300
- Status : v1alpha1 .RequirementStatusReasonPresent ,
301
+ Status : v1alpha1 .RequirementStatusReasonPresentNotSatisfied ,
301
302
Dependents : []v1alpha1.DependentStatus {
302
303
{
303
304
Group : "rbac.authorization.k8s.io" ,
@@ -641,7 +642,7 @@ func TestRequirementAndPermissionStatus(t *testing.T) {
641
642
Version : "v1" ,
642
643
Kind : "CustomResourceDefinition" ,
643
644
Name : "c1.g1" ,
644
- Status : v1alpha1 .RequirementStatusReasonNotAvailable ,
645
+ Status : v1alpha1 .RequirementStatusReasonNotPresent ,
645
646
},
646
647
{"operators.coreos.com" , "v1alpha1" , "ClusterServiceVersion" , "csv1" }: {
647
648
Group : "operators.coreos.com" ,
@@ -773,55 +774,78 @@ func TestRequirementAndPermissionStatus(t *testing.T) {
773
774
},
774
775
},
775
776
},
776
- & rbacv1.Role {
777
- ObjectMeta : metav1.ObjectMeta {
778
- Name : "role" ,
779
- Namespace : namespace ,
780
- },
781
- Rules : []rbacv1.PolicyRule {
777
+ },
778
+ existingExtObjs : nil ,
779
+ met : false ,
780
+ expectedRequirementStatuses : map [gvkn ]v1alpha1.RequirementStatus {
781
+ {"" , "v1" , "ServiceAccount" , "sa" }: {
782
+ Group : "" ,
783
+ Version : "v1" ,
784
+ Kind : "ServiceAccount" ,
785
+ Name : "sa" ,
786
+ Status : v1alpha1 .RequirementStatusReasonPresentNotSatisfied ,
787
+ Dependents : []v1alpha1.DependentStatus {},
788
+ },
789
+ {"operators.coreos.com" , "v1alpha1" , "ClusterServiceVersion" , "csv1" }: {
790
+ Group : "operators.coreos.com" ,
791
+ Version : "v1alpha1" ,
792
+ Kind : "ClusterServiceVersion" ,
793
+ Name : "csv1" ,
794
+ Status : v1alpha1 .RequirementStatusReasonPresent ,
795
+ },
796
+ },
797
+ expectedError : nil ,
798
+ },
799
+ {
800
+ description : "RequirementMet/ServiceAccountOwnedByNonCSV" ,
801
+ csv : csvWithUID (csv ("csv" ,
802
+ namespace ,
803
+ "0.0.0" ,
804
+ "" ,
805
+ installStrategy (
806
+ "csv-dep" ,
807
+ []v1alpha1.StrategyDeploymentPermissions {
782
808
{
783
- APIGroups : []string {"" },
784
- Verbs : []string {"*" },
785
- Resources : []string {"donuts" },
809
+ ServiceAccountName : "sa" ,
786
810
},
787
811
},
788
- },
789
- & rbacv1.RoleBinding {
812
+ nil ,
813
+ ),
814
+ nil ,
815
+ nil ,
816
+ v1alpha1 .CSVPhasePending ,
817
+ ), types .UID ("csv-uid" )),
818
+ existingObjs : []runtime.Object {
819
+ & corev1.ServiceAccount {
790
820
ObjectMeta : metav1.ObjectMeta {
791
- Name : "roleBinding " ,
821
+ Name : "sa " ,
792
822
Namespace : namespace ,
793
- },
794
- Subjects : []rbacv1.Subject {
795
- {
796
- Kind : "ServiceAccount" ,
797
- APIGroup : "" ,
798
- Name : "sa" ,
799
- Namespace : namespace ,
823
+ UID : types .UID ("sa" ),
824
+ OwnerReferences : []metav1.OwnerReference {
825
+ {
826
+ Kind : v1alpha1 .SubscriptionKind , // arbitrary non-CSV kind
827
+ UID : "non-csv" ,
828
+ },
800
829
},
801
830
},
802
- RoleRef : rbacv1.RoleRef {
803
- APIGroup : "rbac.authorization.k8s.io" ,
804
- Kind : "Role" ,
805
- Name : "role" ,
806
- },
807
831
},
808
832
},
809
833
existingExtObjs : nil ,
810
- met : false ,
834
+ met : true ,
811
835
expectedRequirementStatuses : map [gvkn ]v1alpha1.RequirementStatus {
812
836
{"" , "v1" , "ServiceAccount" , "sa" }: {
813
837
Group : "" ,
814
838
Version : "v1" ,
815
839
Kind : "ServiceAccount" ,
816
840
Name : "sa" ,
817
- Status : v1alpha1 .RequirementStatusReasonNotPresent ,
841
+ Status : v1alpha1 .RequirementStatusReasonPresent ,
818
842
Dependents : []v1alpha1.DependentStatus {},
819
843
},
820
- {"operators.coreos.com" , "v1alpha1" , "ClusterServiceVersion" , "csv1 " }: {
844
+ {"operators.coreos.com" , "v1alpha1" , "ClusterServiceVersion" , "csv " }: {
821
845
Group : "operators.coreos.com" ,
822
846
Version : "v1alpha1" ,
823
847
Kind : "ClusterServiceVersion" ,
824
- Name : "csv1 " ,
848
+ Name : "csv " ,
825
849
Status : v1alpha1 .RequirementStatusReasonPresent ,
826
850
},
827
851
},
@@ -843,7 +867,8 @@ func TestRequirementAndPermissionStatus(t *testing.T) {
843
867
require .Error (t , err )
844
868
require .EqualError (t , test .expectedError , err .Error ())
845
869
}
846
- require .Equal (t , test .met , met )
870
+ assert := assert .New (t )
871
+ assert .Equal (test .met , met )
847
872
848
873
for _ , status := range statuses {
849
874
key := gvkn {
@@ -854,14 +879,15 @@ func TestRequirementAndPermissionStatus(t *testing.T) {
854
879
}
855
880
856
881
expected , ok := test .expectedRequirementStatuses [key ]
857
- require .True (t , ok , fmt .Sprintf ("permission requirement status %+v found but not expected" , key ))
858
- require .Len (t , status .Dependents , len (expected .Dependents ), "number of dependents is not what was expected" )
882
+ assert .True (ok , fmt .Sprintf ("permission requirement status %+v found but not expected" , key ))
883
+ assert .Equal (expected .Status , status .Status )
884
+ assert .Len (status .Dependents , len (expected .Dependents ), "number of dependents is not what was expected" )
859
885
860
886
// Delete the requirement status to mark as found
861
887
delete (test .expectedRequirementStatuses , key )
862
888
}
863
889
864
- require .Len (t , test .expectedRequirementStatuses , 0 , "not all expected permission requirement statuses were found" )
890
+ assert .Len (test .expectedRequirementStatuses , 0 , "not all expected permission requirement statuses were found" )
865
891
})
866
892
}
867
893
}
0 commit comments