@@ -756,126 +756,6 @@ describe('Users tests', () => {
756756 } )
757757} )
758758
759- describe ( 'PodService' , ( ) => {
760- let otomiStack : OtomiStack
761- let clientMock : {
762- listNamespacedPod : jest . Mock
763- listPodForAllNamespaces : jest . Mock
764- }
765-
766- beforeEach ( ( ) => {
767- otomiStack = new OtomiStack ( )
768- clientMock = {
769- listNamespacedPod : jest . fn ( ) ,
770- listPodForAllNamespaces : jest . fn ( ) ,
771- }
772- // Override the API client
773- ; ( otomiStack as any ) . getApiClient = jest . fn ( ( ) => clientMock )
774- } )
775-
776- describe ( 'getK8sPodLabelsForWorkload' , ( ) => {
777- const baseLabels = { 'app.kubernetes.io/name' : 'test' , custom : 'label' }
778-
779- it ( 'should return labels on primary Istio selector (namespaced)' , async ( ) => {
780- clientMock . listNamespacedPod . mockResolvedValue ( { items : [ { metadata : { labels : baseLabels } } ] } )
781-
782- const labels = await otomiStack . getK8sPodLabelsForWorkload ( 'test' , 'default' )
783-
784- expect ( clientMock . listNamespacedPod ) . toHaveBeenCalledWith ( {
785- namespace : 'default' ,
786- labelSelector : 'service.istio.io/canonical-name=test' ,
787- } )
788- expect ( labels ) . toEqual ( baseLabels )
789- } )
790-
791- it ( 'should fallback to RabbitMQ selector when primary returns none' , async ( ) => {
792- clientMock . listNamespacedPod
793- . mockResolvedValueOnce ( { items : [ ] } )
794- . mockResolvedValueOnce ( { items : [ { metadata : { labels : { rabbit : 'yes' } } } ] } )
795-
796- const labels = await otomiStack . getK8sPodLabelsForWorkload ( 'test' , 'default' )
797-
798- expect ( clientMock . listNamespacedPod ) . toHaveBeenCalledTimes ( 2 )
799- expect ( clientMock . listNamespacedPod ) . toHaveBeenCalledWith ( {
800- namespace : 'default' ,
801- labelSelector : 'service.istio.io/canonical-name=test' ,
802- } )
803- expect ( clientMock . listNamespacedPod ) . toHaveBeenCalledWith ( {
804- namespace : 'default' ,
805- labelSelector : 'service.istio.io/canonical-name=test-rabbitmq-cluster' ,
806- } )
807- expect ( labels ) . toEqual ( { rabbit : 'yes' } )
808- } )
809-
810- it ( 'should go through all fallback selectors and return empty object if none found' , async ( ) => {
811- clientMock . listNamespacedPod . mockResolvedValue ( { items : [ ] } )
812-
813- const labels = await otomiStack . getK8sPodLabelsForWorkload ( 'foo' , 'bar' )
814-
815- expect ( clientMock . listNamespacedPod ) . toHaveBeenCalledTimes ( 5 )
816- expect ( labels ) . toEqual ( { } )
817- } )
818-
819- it ( 'should search across all namespaces when no namespace provided' , async ( ) => {
820- clientMock . listPodForAllNamespaces . mockResolvedValue ( { items : [ { metadata : { labels : { global : 'yes' } } } ] } )
821-
822- const labels = await otomiStack . getK8sPodLabelsForWorkload ( 'global' , undefined )
823-
824- expect ( clientMock . listPodForAllNamespaces ) . toHaveBeenCalledWith ( {
825- labelSelector : 'service.istio.io/canonical-name=global' ,
826- } )
827- expect ( labels ) . toEqual ( { global : 'yes' } )
828- } )
829- } )
830-
831- describe ( 'listUniquePodNamesByLabel' , ( ) => {
832- it ( 'should return empty array when no pods found (namespaced)' , async ( ) => {
833- clientMock . listNamespacedPod . mockResolvedValue ( { items : [ ] } )
834-
835- const names = await otomiStack . listUniquePodNamesByLabel ( 'app=test' , 'default' )
836-
837- expect ( names ) . toEqual ( [ ] )
838- expect ( clientMock . listNamespacedPod ) . toHaveBeenCalledWith ( { namespace : 'default' , labelSelector : 'app=test' } )
839- } )
840-
841- it ( 'should return full names for unique bases' , async ( ) => {
842- const pods = [
843- { metadata : { name : 'frontend-abc123' } } ,
844- { metadata : { name : 'backend-def456' } } ,
845- { metadata : { name : 'db-gh789' } } ,
846- ]
847- clientMock . listPodForAllNamespaces . mockResolvedValue ( { items : pods } )
848-
849- const names = await otomiStack . listUniquePodNamesByLabel ( 'app=all' )
850-
851- expect ( names ) . toEqual ( [ 'frontend-abc123' , 'backend-def456' , 'db-gh789' ] )
852- } )
853-
854- it ( 'should filter out duplicate base names, keeping first occurrence' , async ( ) => {
855- const pods = [
856- { metadata : { name : 'app-1-a1' } } ,
857- { metadata : { name : 'app-1-b2' } } ,
858- { metadata : { name : 'app-2-c3' } } ,
859- { metadata : { name : 'app-2-d4' } } ,
860- ]
861- clientMock . listPodForAllNamespaces . mockResolvedValue ( { items : pods } )
862-
863- const names = await otomiStack . listUniquePodNamesByLabel ( 'app=dup' )
864-
865- expect ( names ) . toEqual ( [ 'app-1-a1' , 'app-2-c3' ] )
866- } )
867-
868- it ( 'should handle pod names without dashes' , async ( ) => {
869- const pods = [ { metadata : { name : 'singlename' } } ]
870- clientMock . listPodForAllNamespaces . mockResolvedValue ( { items : pods } )
871-
872- const names = await otomiStack . listUniquePodNamesByLabel ( 'app=uniq' )
873-
874- expect ( names ) . toEqual ( [ 'singlename' ] )
875- } )
876- } )
877- } )
878-
879759describe ( 'Code repositories tests' , ( ) => {
880760 let otomiStack : OtomiStack
881761 let teamConfigService : TeamConfigService
0 commit comments