github.com/argoproj/argo-cd/v3@v3.2.1/ui/src/app/applications/components/utils.test.tsx (about)

     1  import * as React from 'react';
     2  import * as renderer from 'react-test-renderer';
     3  import {
     4      Application,
     5      HealthStatus,
     6      HealthStatuses,
     7      OperationPhases,
     8      ResourceResult,
     9      ResultCodes,
    10      State,
    11      SyncStatuses
    12  } from '../../shared/models';
    13  import * as jsYaml from 'js-yaml';
    14  import {
    15      ComparisonStatusIcon,
    16      getAppOperationState,
    17      getOperationType,
    18      getPodStateReason,
    19      HealthStatusIcon,
    20      OperationState,
    21      ResourceResultIcon
    22  } from './utils';
    23  
    24  const zero = new Date(0).toISOString();
    25  
    26  test('getAppOperationState.DeletionTimestamp', () => {
    27      const state = getAppOperationState({metadata: {deletionTimestamp: zero}} as Application);
    28  
    29      expect(state).toStrictEqual({phase: OperationPhases.Running, startedAt: zero});
    30  });
    31  
    32  test('getAppOperationState.Operation', () => {
    33      const state = getAppOperationState({metadata: {}, operation: {}} as Application);
    34  
    35      expect(state.phase).toBe(OperationPhases.Running);
    36      expect(state.startedAt).toBeDefined();
    37      expect(state.operation).toStrictEqual({sync: {}});
    38  });
    39  
    40  test('getAppOperationState.Status', () => {
    41      const state = getAppOperationState({
    42          metadata: {},
    43          status: {operationState: {phase: OperationPhases.Error, startedAt: zero}},
    44      } as Application);
    45  
    46      expect(state.phase).toBe(OperationPhases.Error);
    47  });
    48  
    49  test('getOperationType.Delete', () => {
    50      const state = getOperationType({metadata: {deletionTimestamp: zero.toString()}} as Application);
    51  
    52      expect(state).toBe('Delete');
    53  });
    54  
    55  test('getOperationType.Sync.Operation', () => {
    56      const state = getOperationType({metadata: {}, operation: {sync: {}}} as Application);
    57  
    58      expect(state).toBe('Sync');
    59  });
    60  
    61  test('getOperationType.DeleteAndRecentSync', () => {
    62      const state = getOperationType({metadata: {deletionTimestamp: '123'}, status: {operationState: {operation: {sync: {}}}}} as Application);
    63  
    64      expect(state).toBe('Delete');
    65  });
    66  
    67  test('getOperationType.Sync.Status', () => {
    68      const state = getOperationType({metadata: {}, status: {operationState: {operation: {sync: {}}}}} as Application);
    69  
    70      expect(state).toBe('Sync');
    71  });
    72  
    73  test('getOperationType.Unknown', () => {
    74      const state = getOperationType({metadata: {}, status: {}} as Application);
    75  
    76      expect(state).toBe('Unknown');
    77  });
    78  
    79  test('OperationState.undefined', () => {
    80      const tree = renderer.create(<OperationState app={{metadata: {}, status: {}} as Application} />).toJSON();
    81  
    82      expect(tree).toMatchSnapshot();
    83  });
    84  
    85  test('OperationState.quiet', () => {
    86      const tree = renderer.create(<OperationState app={{metadata: {}, status: {operationState: {}}} as Application} quiet={true} />).toJSON();
    87  
    88      expect(tree).toMatchSnapshot();
    89  });
    90  
    91  test('OperationState.Unknown', () => {
    92      const tree = renderer.create(<OperationState app={{metadata: {}, status: {operationState: {}}} as Application} />).toJSON();
    93  
    94      expect(tree).toMatchSnapshot();
    95  });
    96  
    97  test('OperationState.Deleting', () => {
    98      const tree = renderer.create(<OperationState app={{metadata: {deletionTimestamp: zero}, status: {operationState: {}}} as Application} />).toJSON();
    99  
   100      expect(tree).toMatchSnapshot();
   101  });
   102  
   103  test('OperationState.Sync OK', () => {
   104      const tree = renderer
   105          .create(<OperationState app={{metadata: {}, status: {operationState: {operation: {sync: {}}, phase: OperationPhases.Succeeded}}} as Application} />)
   106          .toJSON();
   107  
   108      expect(tree).toMatchSnapshot();
   109  });
   110  
   111  test('OperationState.Sync error', () => {
   112      const tree = renderer.create(<OperationState app={{metadata: {}, status: {operationState: {operation: {sync: {}}, phase: OperationPhases.Error}}} as Application} />).toJSON();
   113  
   114      expect(tree).toMatchSnapshot();
   115  });
   116  
   117  test('OperationState.Sync failed', () => {
   118      const tree = renderer.create(<OperationState app={{metadata: {}, status: {operationState: {operation: {sync: {}}, phase: OperationPhases.Failed}}} as Application} />).toJSON();
   119  
   120      expect(tree).toMatchSnapshot();
   121  });
   122  
   123  test('OperationState.Syncing', () => {
   124      const tree = renderer
   125          .create(<OperationState app={{metadata: {}, status: {operationState: {operation: {sync: {}}, phase: OperationPhases.Running}}} as Application} />)
   126          .toJSON();
   127  
   128      expect(tree).toMatchSnapshot();
   129  });
   130  
   131  test('ComparisonStatusIcon.Synced', () => {
   132      const tree = renderer.create(<ComparisonStatusIcon status={SyncStatuses.Synced} />).toJSON();
   133  
   134      expect(tree).toMatchSnapshot();
   135  });
   136  
   137  test('ComparisonStatusIcon.OutOfSync', () => {
   138      const tree = renderer.create(<ComparisonStatusIcon status={SyncStatuses.OutOfSync} />).toJSON();
   139  
   140      expect(tree).toMatchSnapshot();
   141  });
   142  
   143  test('ComparisonStatusIcon.Unknown', () => {
   144      const tree = renderer.create(<ComparisonStatusIcon status={SyncStatuses.Unknown} />).toJSON();
   145  
   146      expect(tree).toMatchSnapshot();
   147  });
   148  
   149  test('HealthStatusIcon.Unknown', () => {
   150      const tree = renderer.create(<HealthStatusIcon state={{status: HealthStatuses.Unknown} as HealthStatus} />).toJSON();
   151  
   152      expect(tree).toMatchSnapshot();
   153  });
   154  test('HealthStatusIcon.Progressing', () => {
   155      const tree = renderer.create(<HealthStatusIcon state={{status: HealthStatuses.Progressing} as HealthStatus} />).toJSON();
   156  
   157      expect(tree).toMatchSnapshot();
   158  });
   159  
   160  test('HealthStatusIcon.Suspended', () => {
   161      const tree = renderer.create(<HealthStatusIcon state={{status: HealthStatuses.Suspended} as HealthStatus} />).toJSON();
   162  
   163      expect(tree).toMatchSnapshot();
   164  });
   165  
   166  test('HealthStatusIcon.Healthy', () => {
   167      const tree = renderer.create(<HealthStatusIcon state={{status: HealthStatuses.Healthy} as HealthStatus} />).toJSON();
   168  
   169      expect(tree).toMatchSnapshot();
   170  });
   171  
   172  test('HealthStatusIcon.Degraded', () => {
   173      const tree = renderer.create(<HealthStatusIcon state={{status: HealthStatuses.Degraded} as HealthStatus} />).toJSON();
   174  
   175      expect(tree).toMatchSnapshot();
   176  });
   177  test('HealthStatusIcon.Missing', () => {
   178      const tree = renderer.create(<HealthStatusIcon state={{status: HealthStatuses.Missing} as HealthStatus} />).toJSON();
   179  
   180      expect(tree).toMatchSnapshot();
   181  });
   182  
   183  test('ResourceResultIcon.Synced', () => {
   184      const tree = renderer.create(<ResourceResultIcon resource={{status: ResultCodes.Synced, message: 'my-message'} as ResourceResult} />).toJSON();
   185  
   186      expect(tree).toMatchSnapshot();
   187  });
   188  
   189  test('ResourceResultIcon.Pruned', () => {
   190      const tree = renderer.create(<ResourceResultIcon resource={{status: ResultCodes.Pruned} as ResourceResult} />).toJSON();
   191  
   192      expect(tree).toMatchSnapshot();
   193  });
   194  
   195  test('ResourceResultIcon.SyncFailed', () => {
   196      const tree = renderer.create(<ResourceResultIcon resource={{status: ResultCodes.SyncFailed} as ResourceResult} />).toJSON();
   197  
   198      expect(tree).toMatchSnapshot();
   199  });
   200  
   201  test('ResourceResultIcon.Hook.Running', () => {
   202      const tree = renderer
   203          .create(
   204              <ResourceResultIcon
   205                  resource={
   206                      {
   207                          hookType: 'Sync',
   208                          hookPhase: OperationPhases.Running,
   209                          message: 'my-message',
   210                      } as ResourceResult
   211                  }
   212              />,
   213          )
   214          .toJSON();
   215  
   216      expect(tree).toMatchSnapshot();
   217  });
   218  
   219  test('ResourceResultIcon.Hook.Failed', () => {
   220      const tree = renderer.create(<ResourceResultIcon resource={{hookType: 'Sync', hookPhase: OperationPhases.Failed} as ResourceResult} />).toJSON();
   221  
   222      expect(tree).toMatchSnapshot();
   223  });
   224  
   225  test('ResourceResultIcon.Hook.Error', () => {
   226      const tree = renderer.create(<ResourceResultIcon resource={{hookType: 'Sync', hookPhase: OperationPhases.Error} as ResourceResult} />).toJSON();
   227  
   228      expect(tree).toMatchSnapshot();
   229  });
   230  
   231  test('ResourceResultIcon.Hook.Succeeded', () => {
   232      const tree = renderer.create(<ResourceResultIcon resource={{hookType: 'Sync', hookPhase: OperationPhases.Succeeded} as ResourceResult} />).toJSON();
   233  
   234      expect(tree).toMatchSnapshot();
   235  });
   236  
   237  test('ResourceResultIcon.Hook.Terminating', () => {
   238      const tree = renderer.create(<ResourceResultIcon resource={{hookType: 'Sync', hookPhase: OperationPhases.Terminating} as ResourceResult} />).toJSON();
   239  
   240      expect(tree).toMatchSnapshot();
   241  });
   242  
   243  // These tests are equivalent to those in controller/cache/info_test.go. If you change a test here, update the corresponding test there.
   244  describe('getPodStateReason', () => {
   245      it('TestGetPodInfo', () => {
   246        const podYaml = `
   247    apiVersion: v1
   248    kind: Pod
   249    metadata:
   250      name: helm-guestbook-pod
   251      namespace: default
   252      ownerReferences:
   253      - apiVersion: extensions/v1beta1
   254        kind: ReplicaSet
   255        name: helm-guestbook-rs
   256      resourceVersion: "123"
   257      labels:
   258        app: guestbook
   259    spec:
   260      nodeName: minikube
   261      containers:
   262      - image: bar
   263        resources:
   264          requests:
   265            memory: 128Mi
   266        `
   267  
   268          const pod = jsYaml.load(podYaml);
   269  
   270          const {reason} = getPodStateReason(pod as State);
   271  
   272          expect(reason).toBe('Unknown');
   273      });
   274  
   275      it('TestGetPodWithInitialContainerInfo', () => {
   276          const podYaml = `
   277    apiVersion: "v1"
   278    kind: "Pod"
   279    metadata: 
   280      labels: 
   281        app: "app-with-initial-container"
   282      name: "app-with-initial-container-5f46976fdb-vd6rv"
   283      namespace: "default"
   284      ownerReferences: 
   285      - apiVersion: "apps/v1"
   286        kind: "ReplicaSet"
   287        name: "app-with-initial-container-5f46976fdb"
   288    spec: 
   289      containers: 
   290      - image: "alpine:latest"
   291        imagePullPolicy: "Always"
   292        name: "app-with-initial-container"
   293      initContainers: 
   294      - image: "alpine:latest"
   295        imagePullPolicy: "Always"
   296        name: "app-with-initial-container-logshipper"
   297      nodeName: "minikube"
   298    status: 
   299      containerStatuses: 
   300      - image: "alpine:latest"
   301        name: "app-with-initial-container"
   302        ready: true
   303        restartCount: 0
   304        started: true
   305        state: 
   306          running: 
   307            startedAt: "2024-10-08T08:44:25Z"
   308      initContainerStatuses: 
   309      - image: "alpine:latest"
   310        name: "app-with-initial-container-logshipper"
   311        ready: true
   312        restartCount: 0
   313        started: false
   314        state: 
   315          terminated: 
   316            exitCode: 0
   317            reason: "Completed"
   318      phase: "Running"
   319  `;
   320          const pod = jsYaml.load(podYaml);
   321  
   322          const {reason} = getPodStateReason(pod as State);
   323              expect(reason).toBe('Running');
   324      });
   325  
   326      it('TestGetPodWithInitialContainerInfoWithResources', () => {
   327        const podYaml = `
   328          apiVersion: "v1"
   329          kind: "Pod"
   330          metadata:
   331              labels:
   332                  app: "app-with-initial-container"
   333              name: "app-with-initial-container-5f46976fdb-vd6rv"
   334              namespace: "default"
   335              ownerReferences:
   336              - apiVersion: "apps/v1"
   337                kind: "ReplicaSet"
   338                name: "app-with-initial-container-5f46976fdb"
   339          spec:
   340              containers:
   341              - image: "alpine:latest"
   342                imagePullPolicy: "Always"
   343                name: "app-with-initial-container"
   344                resources:
   345                  requests:
   346                    cpu: "100m"
   347                    memory: "128Mi"
   348                  limits:
   349                    cpu: "500m"
   350                    memory: "512Mi"
   351              initContainers:
   352              - image: "alpine:latest"
   353                imagePullPolicy: "Always"
   354                name: "app-with-initial-container-logshipper"
   355                resources:
   356                  requests:
   357                    cpu: "50m"
   358                    memory: "64Mi"
   359                  limits:
   360                    cpu: "250m"
   361                    memory: "256Mi"
   362              nodeName: "minikube"
   363          status:
   364              containerStatuses:
   365              - image: "alpine:latest"
   366                name: "app-with-initial-container"
   367                ready: true
   368                restartCount: 0
   369                started: true
   370                state:
   371                  running:
   372                    startedAt: "2024-10-08T08:44:25Z"
   373              initContainerStatuses:
   374              - image: "alpine:latest"
   375                name: "app-with-initial-container-logshipper"
   376                ready: true
   377                restartCount: 0
   378                started: false
   379                state:
   380                  terminated:
   381                    exitCode: 0
   382                    reason: "Completed"
   383              phase: "Running"
   384  `;
   385  
   386          const pod = jsYaml.load(podYaml);
   387  
   388          const {reason} = getPodStateReason(pod as State);
   389              expect(reason).toBe('Running');
   390      });
   391  
   392      it('TestGetPodInfoWithSidecar', () => {
   393          const podYaml = `
   394    apiVersion: v1
   395    kind: Pod
   396    metadata:
   397      labels:
   398        app: app-with-sidecar
   399      name: app-with-sidecar-6664cc788c-lqlrp
   400      namespace: default
   401      ownerReferences:
   402        - apiVersion: apps/v1
   403          kind: ReplicaSet
   404          name: app-with-sidecar-6664cc788c
   405    spec:
   406      containers:
   407      - image: 'docker.m.daocloud.io/library/alpine:latest'
   408        imagePullPolicy: Always
   409        name: app-with-sidecar
   410      initContainers:
   411      - image: 'docker.m.daocloud.io/library/alpine:latest'
   412        imagePullPolicy: Always
   413        name: logshipper
   414        restartPolicy: Always
   415      nodeName: minikube
   416    status:
   417      containerStatuses:
   418      - image: 'docker.m.daocloud.io/library/alpine:latest'
   419        name: app-with-sidecar
   420        ready: true
   421        restartCount: 0
   422        started: true
   423        state:
   424          running:
   425            startedAt: '2024-10-08T08:39:43Z'
   426      initContainerStatuses:
   427      - image: 'docker.m.daocloud.io/library/alpine:latest'
   428        name: logshipper
   429        ready: true
   430        restartCount: 0
   431        started: true
   432        state:
   433          running:
   434            startedAt: '2024-10-08T08:39:40Z'
   435      phase: Running
   436  `;
   437          const pod = jsYaml.load(podYaml);
   438  
   439          const {reason} = getPodStateReason(pod as State);
   440              expect(reason).toBe('Running');
   441      });
   442  
   443      it('TestGetPodInfoWithInitialContainer', () => {
   444          const podYaml = `
   445    apiVersion: v1
   446    kind: Pod
   447    metadata:
   448      generateName: myapp-long-exist-56b7d8794d-
   449      labels:
   450        app: myapp-long-exist
   451      name: myapp-long-exist-56b7d8794d-pbgrd
   452      namespace: linghao
   453      ownerReferences:
   454        - apiVersion: apps/v1
   455          kind: ReplicaSet
   456          name: myapp-long-exist-56b7d8794d
   457    spec:
   458      containers:
   459        - image: alpine:latest
   460          imagePullPolicy: Always
   461          name: myapp-long-exist
   462      initContainers:
   463        - image: alpine:latest
   464          imagePullPolicy: Always
   465          name: myapp-long-exist-logshipper
   466      nodeName: minikube
   467    status:
   468      containerStatuses:
   469        - image: alpine:latest
   470          name: myapp-long-exist
   471          ready: false
   472          restartCount: 0
   473          started: false
   474          state:
   475            waiting:
   476              reason: PodInitializing
   477      initContainerStatuses:
   478        - image: alpine:latest
   479          name: myapp-long-exist-logshipper
   480          ready: false
   481          restartCount: 0
   482          started: true
   483          state:
   484            running:
   485              startedAt: '2024-10-09T08:03:45Z'
   486      phase: Pending
   487      startTime: '2024-10-09T08:02:39Z'
   488  `;
   489          const pod = jsYaml.load(podYaml);
   490  
   491          const {reason} = getPodStateReason(pod as State);
   492              expect(reason).toBe('Init:0/1');
   493      });
   494  
   495      it('TestGetPodInfoWithRestartableInitContainer', () => {
   496          const podYaml = `
   497    apiVersion: v1
   498    kind: Pod
   499    metadata:
   500      name: test1
   501    spec:
   502      initContainers:
   503        - name: restartable-init-1
   504          restartPolicy: Always
   505        - name: restartable-init-2
   506          restartPolicy: Always
   507      containers:
   508        - name: container
   509      nodeName: minikube
   510    status:
   511      phase: Pending
   512      initContainerStatuses:
   513        - name: restartable-init-1
   514          ready: false
   515          restartCount: 3
   516          state:
   517            running: {}
   518          started: false
   519          lastTerminationState:
   520            terminated:
   521              finishedAt: "2023-10-01T00:00:00Z" # Replace with actual time
   522        - name: restartable-init-2
   523          ready: false
   524          state:
   525            waiting: {}
   526          started: false
   527      containerStatuses:
   528        - ready: false
   529          restartCount: 0
   530          state:
   531            waiting: {}
   532      conditions:
   533        - type: PodInitialized
   534          status: "False"
   535  `;
   536          const pod = jsYaml.load(podYaml);
   537  
   538          const {reason} = getPodStateReason(pod as State);
   539              expect(reason).toBe('Init:0/2');
   540      });
   541  
   542      it('TestGetPodInfoWithPartiallyStartedInitContainers', () => {
   543          const podYaml = `
   544    apiVersion: v1
   545    kind: Pod
   546    metadata:
   547      name: test1
   548    spec:
   549      initContainers:
   550        - name: restartable-init-1
   551          restartPolicy: Always
   552        - name: restartable-init-2
   553          restartPolicy: Always
   554      containers:
   555        - name: container
   556      nodeName: minikube
   557    status:
   558      phase: Pending
   559      initContainerStatuses:
   560        - name: restartable-init-1
   561          ready: false
   562          restartCount: 3
   563          state:
   564            running: {}
   565          started: true
   566          lastTerminationState:
   567            terminated:
   568              finishedAt: "2023-10-01T00:00:00Z" # Replace with actual time
   569        - name: restartable-init-2
   570          ready: false
   571          state:
   572            running: {}
   573          started: false
   574      containerStatuses:
   575        - ready: false
   576          restartCount: 0
   577          state:
   578            waiting: {}
   579      conditions:
   580        - type: PodInitialized
   581          status: "False"
   582  `;
   583          const pod = jsYaml.load(podYaml);
   584  
   585          const {reason} = getPodStateReason(pod as State);
   586          expect(reason).toBe('Init:1/2');
   587      });
   588  
   589      it('TestGetPodInfoWithStartedInitContainers', () => {
   590          const podYaml = `
   591    apiVersion: v1
   592    kind: Pod
   593    metadata:
   594      name: test2
   595    spec:
   596      initContainers:
   597        - name: restartable-init-1
   598          restartPolicy: Always
   599        - name: restartable-init-2
   600          restartPolicy: Always
   601      containers:
   602        - name: container
   603      nodeName: minikube
   604    status:
   605      phase: Running
   606      initContainerStatuses:
   607        - name: restartable-init-1
   608          ready: false
   609          restartCount: 3
   610          state:
   611            running: {}
   612          started: true
   613          lastTerminationState:
   614            terminated:
   615              finishedAt: "2023-10-01T00:00:00Z" # Replace with actual time
   616        - name: restartable-init-2
   617          ready: false
   618          state:
   619            running: {}
   620          started: true
   621      containerStatuses:
   622        - ready: true
   623          restartCount: 4
   624          state:
   625            running: {}
   626          lastTerminationState:
   627            terminated:
   628              finishedAt: "2023-10-01T00:00:00Z" # Replace with actual time
   629      conditions:
   630        - type: PodInitialized
   631          status: "True"
   632  `;
   633          const pod = jsYaml.load(podYaml);
   634  
   635          const {reason} = getPodStateReason(pod as State);
   636              expect(reason).toBe('Running');
   637      });
   638  
   639      it('TestGetPodInfoWithNormalInitContainer', () => {
   640          const podYaml = `
   641    apiVersion: v1
   642    kind: Pod
   643    metadata:
   644      name: test7
   645    spec:
   646      initContainers:
   647        - name: init-container
   648      containers:
   649        - name: main-container
   650      nodeName: minikube
   651    status:
   652      phase: podPhase
   653      initContainerStatuses:
   654        - ready: false
   655          restartCount: 3
   656          state:
   657            running: {}
   658          lastTerminationState:
   659            terminated:
   660              finishedAt: "2023-10-01T00:00:00Z" # Replace with the actual time
   661      containerStatuses:
   662        - ready: false
   663          restartCount: 0
   664          state:
   665            waiting: {}
   666  `;
   667          const pod = jsYaml.load(podYaml);
   668  
   669          const {reason} = getPodStateReason(pod as State);
   670              expect(reason).toBe('Init:0/1');
   671      });
   672  
   673      it('TestPodConditionSucceeded', () => {
   674          const podYaml = `
   675  apiVersion: v1
   676  kind: Pod
   677  metadata:
   678    name: test8
   679  spec:
   680    nodeName: minikube
   681    containers:
   682      - name: container
   683  status:
   684    phase: Succeeded
   685    containerStatuses:
   686      - ready: false
   687        restartCount: 0
   688        state:
   689          terminated:
   690            reason: Completed
   691            exitCode: 0
   692  `;
   693          const pod = jsYaml.load(podYaml);
   694  
   695          const {reason} = getPodStateReason(pod as State);
   696  
   697              expect(reason).toBe('Completed');
   698      });
   699  
   700      it('TestPodConditionSucceededWithResources', () => {
   701          const podYaml = `
   702    apiVersion: v1
   703    kind: Pod
   704    metadata:
   705      name: test8
   706    spec:
   707      nodeName: minikube
   708      containers:
   709        - name: container
   710          resources:
   711            requests:
   712              cpu: "50m"
   713              memory: "64Mi"
   714            limits:
   715              cpu: "250m"
   716              memory: "256Mi"
   717    status:
   718      phase: Succeeded
   719      containerStatuses:
   720        - ready: false
   721          restartCount: 0
   722          state:
   723            terminated:
   724              reason: Completed
   725              exitCode: 0
   726  `;
   727          const pod = jsYaml.load(podYaml);
   728  
   729          const {reason} = getPodStateReason(pod as State);
   730  
   731              expect(reason).toBe('Completed');
   732      });
   733  
   734      it('TestPodConditionFailed', () => {
   735          const podYaml = `
   736    apiVersion: v1
   737    kind: Pod
   738    metadata:
   739      name: test9
   740    spec:
   741      nodeName: minikube
   742      containers:
   743        - name: container
   744    status:
   745      phase: Failed
   746      containerStatuses:
   747        - ready: false
   748          restartCount: 0
   749          state:
   750            terminated:
   751              reason: Error
   752              exitCode: 1
   753  `;
   754          const pod = jsYaml.load(podYaml);
   755  
   756          const {reason} = getPodStateReason(pod as State);
   757  
   758              expect(reason).toBe('Error');
   759      });
   760  
   761      it('TestPodConditionFailedWithResources', () => {
   762        const podYaml = `
   763  apiVersion: v1
   764  kind: Pod
   765  metadata:
   766    name: test9
   767  spec:
   768    nodeName: minikube
   769    containers:
   770      - name: container
   771        resources:
   772          requests:
   773            cpu: "50m"
   774            memory: "64Mi"
   775          limits:
   776            cpu: "250m"
   777            memory: "256Mi"
   778  status:
   779    phase: Failed
   780    containerStatuses:
   781      - ready: false
   782        restartCount: 0
   783        state:
   784          terminated:
   785            reason: Error
   786            exitCode: 1
   787  `;
   788        const pod = jsYaml.load(podYaml);
   789  
   790        const {reason} = getPodStateReason(pod as State);
   791  
   792            expect(reason).toBe('Error');
   793    });
   794  
   795      it('TestPodConditionSucceededWithDeletion', () => {
   796          const podYaml = `
   797    apiVersion: v1
   798    kind: Pod
   799    metadata:
   800      name: test10
   801      deletionTimestamp: "2023-10-01T00:00:00Z"
   802    spec:
   803      nodeName: minikube
   804      containers:
   805        - name: container
   806    status:
   807      phase: Succeeded
   808      containerStatuses:
   809        - ready: false
   810          restartCount: 0
   811          state:
   812            terminated:
   813              reason: Completed
   814              exitCode: 0
   815  `;
   816          const pod = jsYaml.load(podYaml);
   817  
   818          const {reason} = getPodStateReason(pod as State);
   819  
   820              expect(reason).toBe('Completed');
   821      });
   822  
   823      it('TestPodConditionRunningWithDeletion', () => {
   824          const podYaml = `
   825    apiVersion: v1
   826    kind: Pod
   827    metadata:
   828      name: test11
   829      deletionTimestamp: "2023-10-01T00:00:00Z"
   830    spec:
   831      nodeName: minikube
   832      containers:
   833        - name: container
   834    status:
   835      phase: Running
   836      containerStatuses:
   837        - ready: false
   838          restartCount: 0
   839          state:
   840            running: {}
   841  `;
   842          const pod = jsYaml.load(podYaml);
   843  
   844          const {reason} = getPodStateReason(pod as State);
   845  
   846              expect(reason).toBe('Terminating');
   847      });
   848  
   849      it('TestPodConditionPendingWithDeletion', () => {
   850          const podYaml = `
   851    apiVersion: v1
   852    kind: Pod
   853    metadata:
   854      name: test12
   855      deletionTimestamp: "2023-10-01T00:00:00Z"
   856    spec:
   857      nodeName: minikube
   858      containers:
   859        - name: container
   860    status:
   861      phase: Pending
   862          `
   863          const pod = jsYaml.load(podYaml);
   864  
   865          const {reason} = getPodStateReason(pod as State);
   866  
   867              expect(reason).toBe('Terminating');
   868      });
   869  
   870      it('TestPodScheduledWithSchedulingGated', () => {
   871          const podYaml = `
   872    apiVersion: v1
   873    kind: Pod
   874    metadata:
   875      name: test13
   876    spec:
   877      nodeName: minikube
   878      containers:
   879        - name: container1
   880        - name: container2
   881    status:
   882      phase: podPhase
   883      conditions:
   884        - type: PodScheduled
   885          status: "False"
   886          reason: SchedulingGated
   887            `
   888  
   889          const pod = jsYaml.load(podYaml);
   890  
   891          const {reason} = getPodStateReason(pod as State);
   892  
   893          expect(reason).toBe('SchedulingGated');
   894      });
   895  });