@@ -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 ) {
@@ -827,6 +828,85 @@ func TestRequirementAndPermissionStatus(t *testing.T) {
827
828
},
828
829
expectedError : nil ,
829
830
},
831
+ {
832
+ description : "RequirementMet/ServiceAccountOwnedByNonCSV" ,
833
+ csv : csvWithUID (csv ("csv" ,
834
+ namespace ,
835
+ "0.0.0" ,
836
+ "" ,
837
+ installStrategy (
838
+ "csv-dep" ,
839
+ []v1alpha1.StrategyDeploymentPermissions {
840
+ {
841
+ ServiceAccountName : "sa" ,
842
+ },
843
+ },
844
+ nil ,
845
+ ),
846
+ nil ,
847
+ nil ,
848
+ v1alpha1 .CSVPhasePending ,
849
+ ), types .UID ("csv-uid" )),
850
+ existingObjs : []runtime.Object {
851
+ & corev1.ServiceAccount {
852
+ ObjectMeta : metav1.ObjectMeta {
853
+ Name : "sa" ,
854
+ Namespace : namespace ,
855
+ UID : types .UID ("sa" ),
856
+ OwnerReferences : []metav1.OwnerReference {
857
+ {
858
+ Kind : v1alpha1 .SubscriptionKind , // arbitrary non-CSV kind
859
+ UID : "non-csv" ,
860
+ },
861
+ },
862
+ },
863
+ },
864
+ & rbacv1.Role {
865
+ ObjectMeta : metav1.ObjectMeta {
866
+ Name : "role" ,
867
+ Namespace : namespace ,
868
+ },
869
+ },
870
+ & rbacv1.RoleBinding {
871
+ ObjectMeta : metav1.ObjectMeta {
872
+ Name : "roleBinding" ,
873
+ Namespace : namespace ,
874
+ },
875
+ Subjects : []rbacv1.Subject {
876
+ {
877
+ Kind : "ServiceAccount" ,
878
+ Name : "sa" ,
879
+ Namespace : namespace ,
880
+ },
881
+ },
882
+ RoleRef : rbacv1.RoleRef {
883
+ APIGroup : "rbac.authorization.k8s.io" ,
884
+ Kind : "Role" ,
885
+ Name : "role" ,
886
+ },
887
+ },
888
+ },
889
+ existingExtObjs : nil ,
890
+ met : true ,
891
+ expectedRequirementStatuses : map [gvkn ]v1alpha1.RequirementStatus {
892
+ {"" , "v1" , "ServiceAccount" , "sa" }: {
893
+ Group : "" ,
894
+ Version : "v1" ,
895
+ Kind : "ServiceAccount" ,
896
+ Name : "sa" ,
897
+ Status : v1alpha1 .RequirementStatusReasonPresent ,
898
+ Dependents : []v1alpha1.DependentStatus {},
899
+ },
900
+ {"operators.coreos.com" , "v1alpha1" , "ClusterServiceVersion" , "csv" }: {
901
+ Group : "operators.coreos.com" ,
902
+ Version : "v1alpha1" ,
903
+ Kind : "ClusterServiceVersion" ,
904
+ Name : "csv" ,
905
+ Status : v1alpha1 .RequirementStatusReasonPresent ,
906
+ },
907
+ },
908
+ expectedError : nil ,
909
+ },
830
910
}
831
911
832
912
for _ , test := range tests {
@@ -843,7 +923,8 @@ func TestRequirementAndPermissionStatus(t *testing.T) {
843
923
require .Error (t , err )
844
924
require .EqualError (t , test .expectedError , err .Error ())
845
925
}
846
- require .Equal (t , test .met , met )
926
+ assert := assert .New (t )
927
+ assert .Equal (test .met , met )
847
928
848
929
for _ , status := range statuses {
849
930
key := gvkn {
@@ -854,14 +935,14 @@ func TestRequirementAndPermissionStatus(t *testing.T) {
854
935
}
855
936
856
937
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" )
938
+ assert .True (ok , fmt .Sprintf ("permission requirement status %+v found but not expected" , key ))
939
+ assert .Len (status .Dependents , len (expected .Dependents ), "number of dependents is not what was expected" )
859
940
860
941
// Delete the requirement status to mark as found
861
942
delete (test .expectedRequirementStatuses , key )
862
943
}
863
944
864
- require .Len (t , test .expectedRequirementStatuses , 0 , "not all expected permission requirement statuses were found" )
945
+ assert .Len (test .expectedRequirementStatuses , 0 , "not all expected permission requirement statuses were found" )
865
946
})
866
947
}
867
948
}
0 commit comments