@@ -8,7 +8,6 @@ import * as io from '@actions/io';
8
8
import * as toolCache from '@actions/tool-cache' ;
9
9
import * as fileHelper from '../src/utilities/files-helper' ;
10
10
import { workflowAnnotations } from '../src/constants' ;
11
- import * as utility from '../src/utilities/utility' ;
12
11
import * as inputParam from '../src/input-parameters' ;
13
12
14
13
import { Kubectl , Resource } from '../src/kubectl-object-model' ;
@@ -21,7 +20,6 @@ const os = require("os");
21
20
22
21
const coreMock = mocked ( core , true ) ;
23
22
const ioMock = mocked ( io , true ) ;
24
- const utilityMock = mocked ( utility , true ) ;
25
23
const inputParamMock = mocked ( inputParam , true ) ;
26
24
27
25
const toolCacheMock = mocked ( toolCache , true ) ;
@@ -43,7 +41,7 @@ const getNamespaceMock = {
43
41
44
42
const resources : Resource [ ] = [ { type : "Deployment" , name : "AppName" } ] ;
45
43
46
- beforeAll ( ( ) => {
44
+ beforeEach ( ( ) => {
47
45
deploymentYaml = fs . readFileSync ( path . join ( __dirname , 'manifests' , 'deployment.yml' ) , 'utf8' ) ;
48
46
49
47
process . env [ "KUBECONFIG" ] = 'kubeConfig' ;
@@ -274,6 +272,31 @@ test("deployment - deploy() - Annotate resources", async () => {
274
272
expect ( kubeCtl . annotate ) . toBeCalledTimes ( 2 ) ;
275
273
} ) ;
276
274
275
+ test ( "deployment - deploy() - Skip Annotate namespace" , async ( ) => {
276
+ process . env [ 'GITHUB_REPOSITORY' ] = 'test1Repo' ;
277
+ const KubernetesManifestUtilityMock = mocked ( KubernetesManifestUtility , true ) ;
278
+ KubernetesManifestUtilityMock . checkManifestStability = jest . fn ( ) . mockReturnValue ( "" ) ;
279
+ const KubernetesObjectUtilityMock = mocked ( KubernetesObjectUtility , true ) ;
280
+ KubernetesObjectUtilityMock . getResources = jest . fn ( ) . mockReturnValue ( resources ) ;
281
+ const fileHelperMock = mocked ( fileHelper , true ) ;
282
+ fileHelperMock . writeObjectsToFile = jest . fn ( ) . mockReturnValue ( [ "~/Deployment_testapp_currentTimestamp" ] ) ;
283
+ const kubeCtl : jest . Mocked < Kubectl > = new Kubectl ( "" ) as any ;
284
+ kubeCtl . apply = jest . fn ( ) . mockReturnValue ( "" ) ;
285
+ kubeCtl . getResource = jest . fn ( ) . mockReturnValue ( getNamespaceMock ) ;
286
+ kubeCtl . getAllPods = jest . fn ( ) . mockReturnValue ( getAllPodsMock ) ;
287
+ kubeCtl . getNewReplicaSet = jest . fn ( ) . mockReturnValue ( "testpod-776cbc86f9" ) ;
288
+ kubeCtl . annotateFiles = jest . fn ( ) . mockReturnValue ( "" ) ;
289
+ kubeCtl . annotate = jest . fn ( ) . mockReturnValue ( "" ) ;
290
+
291
+ const consoleOutputSpy = jest . spyOn ( process . stdout , "write" ) . mockImplementation ( ) ;
292
+
293
+ //Invoke and assert
294
+ await expect ( deployment . deploy ( kubeCtl , [ 'manifests/deployment.yaml' ] , undefined ) ) . resolves . not . toThrowError ( ) ;
295
+ expect ( kubeCtl . annotateFiles ) . toBeCalledWith ( [ "~/Deployment_testapp_currentTimestamp" ] , workflowAnnotations , true ) ;
296
+ expect ( kubeCtl . annotate ) . toBeCalledTimes ( 1 ) ;
297
+ expect ( consoleOutputSpy ) . toHaveBeenNthCalledWith ( 2 , `##[debug]Skipping 'annotate namespace' as namespace annotated by other workflow` + os . EOL )
298
+ } ) ;
299
+
277
300
test ( "deployment - deploy() - Annotate resources failed" , async ( ) => {
278
301
//Mocks
279
302
inputParamMock . forceDeployment = true ;
0 commit comments