mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-03-03 08:12:18 +08:00
Migrate to esbuild/Vitest and upgrade @actions/* to ESM-only versions (#492)
* Migrate build toolchain from ncc/Jest to esbuild/Vitest Replace the legacy ncc/Jest/Babel build stack with a modern ESM toolchain: Build: - Replace @vercel/ncc with esbuild (--platform=node --target=node20 --format=esm) - Add createRequire banner for CJS interop in ESM bundle - Add "type": "module" to package.json - Add tsc --noEmit typecheck script (esbuild strips types without checking) - Add typecheck to husky pre-commit hook Dependencies: - Bump @actions/core@3, exec@3, io@3, tool-cache@4 (ESM-only) - Replace jest/ts-jest/@babel/* with vitest@4 Tests: - Convert 29 test files: jest.fn()→vi.fn(), jest.mock()→vi.mock(), jest.spyOn()→vi.spyOn() - Fix vitest 4 compat: mockImplementation requires args, mock call tracking, await .rejects CI: - Update build step from ncc build → npm run build - Update composite action to use npm run build * Switch tsconfig to NodeNext module resolution Change module/moduleResolution from ES2022/bundler to NodeNext/NodeNext and target from ES2022 to ES2020. - Add .js extensions to all relative imports across 59 source/test files (required by NodeNext module resolution) - Add vitest/globals to tsconfig types array for global test API declarations
This commit is contained in:
parent
84e2095bf0
commit
01cfe404ef
8
.github/actions/minikube-setup/action.yml
vendored
8
.github/actions/minikube-setup/action.yml
vendored
@ -15,18 +15,14 @@ runs:
|
||||
rm -rf node_modules/
|
||||
npm install
|
||||
|
||||
- name: Install ncc
|
||||
- name: Build
|
||||
shell: bash
|
||||
run: npm i -g @vercel/ncc
|
||||
run: npm run build
|
||||
|
||||
- name: Install conntrack
|
||||
shell: bash
|
||||
run: sudo apt-get install -y conntrack
|
||||
|
||||
- name: Build
|
||||
shell: bash
|
||||
run: ncc build src/run.ts -o lib
|
||||
|
||||
- uses: Azure/setup-kubectl@776406bce94f63e41d621b960d78ee25c8b76ede # v4.0.1
|
||||
name: Install Kubectl
|
||||
|
||||
|
||||
@ -25,10 +25,10 @@ jobs:
|
||||
run: |
|
||||
rm -rf node_modules/
|
||||
npm install
|
||||
- name: Install ncc
|
||||
run: npm i -g @vercel/ncc
|
||||
|
||||
- name: Build
|
||||
run: ncc build src/run.ts -o lib
|
||||
run: npm run build
|
||||
|
||||
- name: Azure login
|
||||
uses: azure/login@v2.3.0
|
||||
with:
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
npm run typecheck || {
|
||||
echo ""
|
||||
echo "❌ Type check failed."
|
||||
echo "💡 Run 'npm run typecheck' to see errors."
|
||||
exit 1
|
||||
}
|
||||
npm test
|
||||
npm run format-check || {
|
||||
echo ""
|
||||
|
||||
@ -1,20 +0,0 @@
|
||||
module.exports = {
|
||||
moduleFileExtensions: ['js', 'ts'],
|
||||
testEnvironment: 'node',
|
||||
testMatch: ['**/*.test.ts'],
|
||||
transform: {
|
||||
'\\.[jt]sx?$': 'babel-jest'
|
||||
},
|
||||
transformIgnorePatterns: [
|
||||
'node_modules/(?!' +
|
||||
[
|
||||
'@octokit',
|
||||
'universal-user-agent',
|
||||
'before-after-hook',
|
||||
'minimist'
|
||||
].join('|') +
|
||||
')'
|
||||
],
|
||||
verbose: true,
|
||||
testTimeout: 9000
|
||||
}
|
||||
10743
package-lock.json
generated
10743
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
34
package.json
34
package.json
@ -3,38 +3,34 @@
|
||||
"version": "5.0.4",
|
||||
"author": "Deepak Sattiraju",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"prebuild": "npm i @vercel/ncc",
|
||||
"build": "ncc build src/run.ts -o lib",
|
||||
"test": "jest",
|
||||
"coverage": "jest --coverage=true",
|
||||
"build": "esbuild src/run.ts --bundle --platform=node --target=node20 --format=esm --outfile=lib/index.js --banner:js=\"import { createRequire } from 'module';const require = createRequire(import.meta.url);\"",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"test": "vitest run",
|
||||
"coverage": "vitest run --coverage",
|
||||
"format": "prettier --write .",
|
||||
"format-check": "prettier --check .",
|
||||
"prepare": "husky"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/core": "^2.0.2",
|
||||
"@actions/exec": "^2.0.0",
|
||||
"@actions/io": "^2.0.0",
|
||||
"@actions/tool-cache": "3.0.0",
|
||||
"@babel/preset-env": "^7.28.6",
|
||||
"@babel/preset-typescript": "^7.28.5",
|
||||
"@actions/core": "^3.0.0",
|
||||
"@actions/exec": "^3.0.0",
|
||||
"@actions/io": "^3.0.2",
|
||||
"@actions/tool-cache": "4.0.0",
|
||||
"@octokit/core": "^7.0.6",
|
||||
"@octokit/plugin-retry": "^8.0.3",
|
||||
"@types/minipass": "^3.3.5",
|
||||
"husky": "^9.1.7",
|
||||
"js-yaml": "4.1.1",
|
||||
"minimist": "^1.2.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^30.0.0",
|
||||
"@types/js-yaml": "^4.0.9",
|
||||
"@types/minimist": "^1.2.5",
|
||||
"@types/node": "^25.0.9",
|
||||
"@vercel/ncc": "^0.38.4",
|
||||
"jest": "^30.2.0",
|
||||
"prettier": "^3.8.0",
|
||||
"ts-jest": "^29.4.6",
|
||||
"typescript": "5.9.3"
|
||||
"@types/node": "^25.2.3",
|
||||
"esbuild": "^0.27",
|
||||
"husky": "^9.1.7",
|
||||
"prettier": "^3.8.1",
|
||||
"typescript": "5.9.3",
|
||||
"vitest": "^4"
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,19 +1,19 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as models from '../types/kubernetesTypes'
|
||||
import * as KubernetesConstants from '../types/kubernetesTypes'
|
||||
import {Kubectl, Resource} from '../types/kubectl'
|
||||
import * as models from '../types/kubernetesTypes.js'
|
||||
import * as KubernetesConstants from '../types/kubernetesTypes.js'
|
||||
import {Kubectl, Resource} from '../types/kubectl.js'
|
||||
import {
|
||||
getResources,
|
||||
updateManifestFiles
|
||||
} from '../utilities/manifestUpdateUtils'
|
||||
} from '../utilities/manifestUpdateUtils.js'
|
||||
import {
|
||||
annotateAndLabelResources,
|
||||
checkManifestStability,
|
||||
deployManifests
|
||||
} from '../strategyHelpers/deploymentHelper'
|
||||
import {DeploymentStrategy} from '../types/deploymentStrategy'
|
||||
import {parseTrafficSplitMethod} from '../types/trafficSplitMethod'
|
||||
import {ClusterType} from '../inputUtils'
|
||||
} from '../strategyHelpers/deploymentHelper.js'
|
||||
import {DeploymentStrategy} from '../types/deploymentStrategy.js'
|
||||
import {parseTrafficSplitMethod} from '../types/trafficSplitMethod.js'
|
||||
import {ClusterType} from '../inputUtils.js'
|
||||
export const ResourceTypeManagedCluster =
|
||||
'Microsoft.ContainerService/managedClusters'
|
||||
export const ResourceTypeFleet = 'Microsoft.ContainerService/fleets'
|
||||
|
||||
@ -1,44 +1,44 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as canaryDeploymentHelper from '../strategyHelpers/canary/canaryHelper'
|
||||
import * as SMICanaryDeploymentHelper from '../strategyHelpers/canary/smiCanaryHelper'
|
||||
import * as PodCanaryHelper from '../strategyHelpers/canary/podCanaryHelper'
|
||||
import * as canaryDeploymentHelper from '../strategyHelpers/canary/canaryHelper.js'
|
||||
import * as SMICanaryDeploymentHelper from '../strategyHelpers/canary/smiCanaryHelper.js'
|
||||
import * as PodCanaryHelper from '../strategyHelpers/canary/podCanaryHelper.js'
|
||||
import {
|
||||
getResources,
|
||||
updateManifestFiles
|
||||
} from '../utilities/manifestUpdateUtils'
|
||||
import {annotateAndLabelResources} from '../strategyHelpers/deploymentHelper'
|
||||
import * as models from '../types/kubernetesTypes'
|
||||
import * as KubernetesManifestUtility from '../utilities/manifestStabilityUtils'
|
||||
} from '../utilities/manifestUpdateUtils.js'
|
||||
import {annotateAndLabelResources} from '../strategyHelpers/deploymentHelper.js'
|
||||
import * as models from '../types/kubernetesTypes.js'
|
||||
import * as KubernetesManifestUtility from '../utilities/manifestStabilityUtils.js'
|
||||
import {
|
||||
deleteGreenObjects,
|
||||
getManifestObjects,
|
||||
NONE_LABEL_VALUE
|
||||
} from '../strategyHelpers/blueGreen/blueGreenHelper'
|
||||
} from '../strategyHelpers/blueGreen/blueGreenHelper.js'
|
||||
|
||||
import {BlueGreenManifests} from '../types/blueGreenTypes'
|
||||
import {DeployResult} from '../types/deployResult'
|
||||
import {BlueGreenManifests} from '../types/blueGreenTypes.js'
|
||||
import {DeployResult} from '../types/deployResult.js'
|
||||
|
||||
import {
|
||||
promoteBlueGreenIngress,
|
||||
promoteBlueGreenService,
|
||||
promoteBlueGreenSMI
|
||||
} from '../strategyHelpers/blueGreen/promote'
|
||||
} from '../strategyHelpers/blueGreen/promote.js'
|
||||
|
||||
import {
|
||||
routeBlueGreenService,
|
||||
routeBlueGreenIngressUnchanged,
|
||||
routeBlueGreenSMI
|
||||
} from '../strategyHelpers/blueGreen/route'
|
||||
} from '../strategyHelpers/blueGreen/route.js'
|
||||
|
||||
import {cleanupSMI} from '../strategyHelpers/blueGreen/smiBlueGreenHelper'
|
||||
import {Kubectl, Resource} from '../types/kubectl'
|
||||
import {DeploymentStrategy} from '../types/deploymentStrategy'
|
||||
import {cleanupSMI} from '../strategyHelpers/blueGreen/smiBlueGreenHelper.js'
|
||||
import {Kubectl, Resource} from '../types/kubectl.js'
|
||||
import {DeploymentStrategy} from '../types/deploymentStrategy.js'
|
||||
import {
|
||||
parseTrafficSplitMethod,
|
||||
TrafficSplitMethod
|
||||
} from '../types/trafficSplitMethod'
|
||||
import {parseRouteStrategy, RouteStrategy} from '../types/routeStrategy'
|
||||
import {ClusterType} from '../inputUtils'
|
||||
} from '../types/trafficSplitMethod.js'
|
||||
import {parseRouteStrategy, RouteStrategy} from '../types/routeStrategy.js'
|
||||
import {ClusterType} from '../inputUtils.js'
|
||||
|
||||
export async function promote(
|
||||
kubectl: Kubectl,
|
||||
|
||||
@ -1,20 +1,20 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as canaryDeploymentHelper from '../strategyHelpers/canary/canaryHelper'
|
||||
import * as SMICanaryDeploymentHelper from '../strategyHelpers/canary/smiCanaryHelper'
|
||||
import {Kubectl} from '../types/kubectl'
|
||||
import {BlueGreenManifests} from '../types/blueGreenTypes'
|
||||
import * as canaryDeploymentHelper from '../strategyHelpers/canary/canaryHelper.js'
|
||||
import * as SMICanaryDeploymentHelper from '../strategyHelpers/canary/smiCanaryHelper.js'
|
||||
import {Kubectl} from '../types/kubectl.js'
|
||||
import {BlueGreenManifests} from '../types/blueGreenTypes.js'
|
||||
import {
|
||||
rejectBlueGreenIngress,
|
||||
rejectBlueGreenService,
|
||||
rejectBlueGreenSMI
|
||||
} from '../strategyHelpers/blueGreen/reject'
|
||||
import {getManifestObjects} from '../strategyHelpers/blueGreen/blueGreenHelper'
|
||||
import {DeploymentStrategy} from '../types/deploymentStrategy'
|
||||
} from '../strategyHelpers/blueGreen/reject.js'
|
||||
import {getManifestObjects} from '../strategyHelpers/blueGreen/blueGreenHelper.js'
|
||||
import {DeploymentStrategy} from '../types/deploymentStrategy.js'
|
||||
import {
|
||||
parseTrafficSplitMethod,
|
||||
TrafficSplitMethod
|
||||
} from '../types/trafficSplitMethod'
|
||||
import {parseRouteStrategy, RouteStrategy} from '../types/routeStrategy'
|
||||
} from '../types/trafficSplitMethod.js'
|
||||
import {parseRouteStrategy, RouteStrategy} from '../types/routeStrategy.js'
|
||||
|
||||
export async function reject(
|
||||
kubectl: Kubectl,
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
import {parseResourceTypeInput} from './inputUtils'
|
||||
import {ResourceTypeFleet, ResourceTypeManagedCluster} from './actions/deploy'
|
||||
import {parseResourceTypeInput} from './inputUtils.js'
|
||||
import {
|
||||
ResourceTypeFleet,
|
||||
ResourceTypeManagedCluster
|
||||
} from './actions/deploy.js'
|
||||
|
||||
describe('InputUtils', () => {
|
||||
describe('parseResourceTypeInput', () => {
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
import * as core from '@actions/core'
|
||||
import {parseAnnotations} from './types/annotations'
|
||||
import {ResourceTypeFleet, ResourceTypeManagedCluster} from './actions/deploy'
|
||||
import {parseAnnotations} from './types/annotations.js'
|
||||
import {
|
||||
ResourceTypeFleet,
|
||||
ResourceTypeManagedCluster
|
||||
} from './actions/deploy.js'
|
||||
|
||||
export const inputAnnotations = parseAnnotations(
|
||||
core.getInput('annotations', {required: false})
|
||||
|
||||
22
src/run.ts
22
src/run.ts
@ -1,19 +1,19 @@
|
||||
import * as core from '@actions/core'
|
||||
import {getKubectlPath, Kubectl} from './types/kubectl'
|
||||
import {getKubectlPath, Kubectl} from './types/kubectl.js'
|
||||
import {
|
||||
deploy,
|
||||
ResourceTypeFleet,
|
||||
ResourceTypeManagedCluster
|
||||
} from './actions/deploy'
|
||||
import {ClusterType} from './inputUtils'
|
||||
import {promote} from './actions/promote'
|
||||
import {reject} from './actions/reject'
|
||||
import {Action, parseAction} from './types/action'
|
||||
import {parseDeploymentStrategy} from './types/deploymentStrategy'
|
||||
import {getFilesFromDirectoriesAndURLs} from './utilities/fileUtils'
|
||||
import {PrivateKubectl} from './types/privatekubectl'
|
||||
import {parseResourceTypeInput} from './inputUtils'
|
||||
import {parseDuration} from './utilities/durationUtils'
|
||||
} from './actions/deploy.js'
|
||||
import {ClusterType} from './inputUtils.js'
|
||||
import {promote} from './actions/promote.js'
|
||||
import {reject} from './actions/reject.js'
|
||||
import {Action, parseAction} from './types/action.js'
|
||||
import {parseDeploymentStrategy} from './types/deploymentStrategy.js'
|
||||
import {getFilesFromDirectoriesAndURLs} from './utilities/fileUtils.js'
|
||||
import {PrivateKubectl} from './types/privatekubectl.js'
|
||||
import {parseResourceTypeInput} from './inputUtils.js'
|
||||
import {parseDuration} from './utilities/durationUtils.js'
|
||||
|
||||
export async function run() {
|
||||
// verify kubeconfig is set
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import {vi} from 'vitest'
|
||||
import type {MockInstance} from 'vitest'
|
||||
import {
|
||||
deployWithLabel,
|
||||
deleteGreenObjects,
|
||||
@ -8,16 +10,16 @@ import {
|
||||
getNewBlueGreenObject,
|
||||
GREEN_LABEL_VALUE,
|
||||
isServiceRouted
|
||||
} from './blueGreenHelper'
|
||||
import {BlueGreenDeployment} from '../../types/blueGreenTypes'
|
||||
import * as bgHelper from './blueGreenHelper'
|
||||
import {Kubectl} from '../../types/kubectl'
|
||||
import * as fileHelper from '../../utilities/fileUtils'
|
||||
import {K8sObject} from '../../types/k8sObject'
|
||||
import * as manifestUpdateUtils from '../../utilities/manifestUpdateUtils'
|
||||
} from './blueGreenHelper.js'
|
||||
import {BlueGreenDeployment} from '../../types/blueGreenTypes.js'
|
||||
import * as bgHelper from './blueGreenHelper.js'
|
||||
import {Kubectl} from '../../types/kubectl.js'
|
||||
import * as fileHelper from '../../utilities/fileUtils.js'
|
||||
import {K8sObject} from '../../types/k8sObject.js'
|
||||
import * as manifestUpdateUtils from '../../utilities/manifestUpdateUtils.js'
|
||||
import {ExecOutput} from '@actions/exec'
|
||||
|
||||
jest.mock('../../types/kubectl')
|
||||
vi.mock('../../types/kubectl')
|
||||
|
||||
const kubectl = new Kubectl('')
|
||||
const TEST_TIMEOUT = '60s'
|
||||
@ -37,17 +39,17 @@ const MOCK_EXEC_OUTPUT = {
|
||||
describe('bluegreenhelper functions', () => {
|
||||
let testObjects
|
||||
beforeEach(() => {
|
||||
//@ts-ignore
|
||||
Kubectl.mockClear()
|
||||
vi.restoreAllMocks()
|
||||
vi.mocked(Kubectl).mockClear()
|
||||
testObjects = getManifestObjects(['test/unit/manifests/test-ingress.yml'])
|
||||
|
||||
jest
|
||||
.spyOn(fileHelper, 'writeObjectsToFile')
|
||||
.mockImplementationOnce(() => [''])
|
||||
vi.spyOn(fileHelper, 'writeObjectsToFile').mockImplementationOnce(() => [
|
||||
''
|
||||
])
|
||||
})
|
||||
|
||||
test('correctly deletes services and workloads according to label', async () => {
|
||||
jest.spyOn(bgHelper, 'deleteObjects').mockReturnValue({} as Promise<void>)
|
||||
vi.spyOn(bgHelper, 'deleteObjects').mockReturnValue({} as Promise<void>)
|
||||
|
||||
const value = await deleteGreenObjects(
|
||||
kubectl,
|
||||
@ -65,21 +67,16 @@ describe('bluegreenhelper functions', () => {
|
||||
})
|
||||
|
||||
test('handles timeout when deleting objects', async () => {
|
||||
// Mock deleteObjects to prevent actual execution
|
||||
const deleteSpy = jest
|
||||
.spyOn(kubectl, 'delete')
|
||||
.mockResolvedValue(MOCK_EXEC_OUTPUT)
|
||||
const deleteMock = vi.fn().mockResolvedValue(MOCK_EXEC_OUTPUT)
|
||||
kubectl.delete = deleteMock
|
||||
|
||||
await bgHelper.deleteObjects(
|
||||
kubectl,
|
||||
EXPECTED_GREEN_OBJECTS,
|
||||
TEST_TIMEOUT
|
||||
)
|
||||
const deleteList = EXPECTED_GREEN_OBJECTS
|
||||
|
||||
// Verify kubectl.delete is called with timeout for each object in deleteList
|
||||
expect(deleteSpy).toHaveBeenCalledTimes(EXPECTED_GREEN_OBJECTS.length)
|
||||
EXPECTED_GREEN_OBJECTS.forEach(({name, kind}) => {
|
||||
expect(deleteSpy).toHaveBeenCalledWith(
|
||||
await bgHelper.deleteObjects(kubectl, deleteList, TEST_TIMEOUT)
|
||||
|
||||
expect(deleteMock).toHaveBeenCalledTimes(deleteList.length)
|
||||
deleteList.forEach(({name, kind}) => {
|
||||
expect(deleteMock).toHaveBeenCalledWith(
|
||||
[kind, name],
|
||||
undefined,
|
||||
TEST_TIMEOUT
|
||||
@ -135,7 +132,7 @@ describe('bluegreenhelper functions', () => {
|
||||
})
|
||||
|
||||
test('correctly makes labeled workloads', async () => {
|
||||
const kubectlApplySpy = jest.spyOn(kubectl, 'apply').mockResolvedValue({
|
||||
const kubectlApplySpy = vi.spyOn(kubectl, 'apply').mockResolvedValue({
|
||||
stdout: 'deployment.apps/nginx-deployment created',
|
||||
stderr: '',
|
||||
exitCode: 0
|
||||
@ -179,9 +176,9 @@ describe('bluegreenhelper functions', () => {
|
||||
exitCode: 0
|
||||
}
|
||||
|
||||
jest
|
||||
.spyOn(kubectl, 'getResource')
|
||||
.mockImplementation(() => Promise.resolve(mockExecOutput))
|
||||
vi.spyOn(kubectl, 'getResource').mockImplementation(() =>
|
||||
Promise.resolve(mockExecOutput)
|
||||
)
|
||||
const fetched = await fetchResource(
|
||||
kubectl,
|
||||
'nginx-deployment',
|
||||
@ -209,12 +206,12 @@ describe('bluegreenhelper functions', () => {
|
||||
]
|
||||
|
||||
for (const testCase of errorTestCases) {
|
||||
const spy = jest.spyOn(kubectl, 'getResource')
|
||||
const spy = vi.spyOn(kubectl, 'getResource')
|
||||
|
||||
if (testCase.mockOutput) {
|
||||
spy.mockImplementation(() => Promise.resolve(testCase.mockOutput))
|
||||
} else {
|
||||
spy.mockImplementation()
|
||||
spy.mockResolvedValue(null)
|
||||
}
|
||||
|
||||
const fetched = await fetchResource(
|
||||
@ -235,12 +232,13 @@ describe('bluegreenhelper functions', () => {
|
||||
stderr: ''
|
||||
} as ExecOutput
|
||||
|
||||
jest.spyOn(kubectl, 'getResource').mockResolvedValue(mockExecOutput)
|
||||
jest
|
||||
.spyOn(manifestUpdateUtils, 'UnsetClusterSpecificDetails')
|
||||
.mockImplementation(() => {
|
||||
throw new Error('test error')
|
||||
})
|
||||
vi.spyOn(kubectl, 'getResource').mockResolvedValue(mockExecOutput)
|
||||
vi.spyOn(
|
||||
manifestUpdateUtils,
|
||||
'UnsetClusterSpecificDetails'
|
||||
).mockImplementation(() => {
|
||||
throw new Error('test error')
|
||||
})
|
||||
|
||||
expect(
|
||||
await fetchResource(kubectl, 'nginx-deployment', 'Deployment')
|
||||
@ -267,7 +265,7 @@ describe('bluegreenhelper functions', () => {
|
||||
|
||||
describe('deployObjects', () => {
|
||||
let mockObjects: any[]
|
||||
let kubectlApplySpy: jest.SpyInstance
|
||||
let kubectlApplySpy: MockInstance
|
||||
|
||||
const mockSuccessResult: ExecOutput = {
|
||||
stdout: 'deployment.apps/nginx-deployment created',
|
||||
@ -285,11 +283,11 @@ describe('bluegreenhelper functions', () => {
|
||||
// //@ts-ignore
|
||||
// Kubectl.mockClear()
|
||||
mockObjects = [testObjects.deploymentEntityList[0]]
|
||||
kubectlApplySpy = jest.spyOn(kubectl, 'apply')
|
||||
kubectlApplySpy = vi.spyOn(kubectl, 'apply')
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks()
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('should return execution result and manifest files when kubectl apply succeeds', async () => {
|
||||
|
||||
@ -2,27 +2,27 @@ import * as core from '@actions/core'
|
||||
import * as fs from 'fs'
|
||||
import * as yaml from 'js-yaml'
|
||||
|
||||
import {DeployResult} from '../../types/deployResult'
|
||||
import {K8sObject, K8sDeleteObject} from '../../types/k8sObject'
|
||||
import {Kubectl} from '../../types/kubectl'
|
||||
import {DeployResult} from '../../types/deployResult.js'
|
||||
import {K8sObject, K8sDeleteObject} from '../../types/k8sObject.js'
|
||||
import {Kubectl} from '../../types/kubectl.js'
|
||||
import {
|
||||
isDeploymentEntity,
|
||||
isIngressEntity,
|
||||
isServiceEntity,
|
||||
KubernetesWorkload
|
||||
} from '../../types/kubernetesTypes'
|
||||
} from '../../types/kubernetesTypes.js'
|
||||
import {
|
||||
BlueGreenDeployment,
|
||||
BlueGreenManifests
|
||||
} from '../../types/blueGreenTypes'
|
||||
import * as fileHelper from '../../utilities/fileUtils'
|
||||
import {updateSpecLabels} from '../../utilities/manifestSpecLabelUtils'
|
||||
import {checkForErrors} from '../../utilities/kubectlUtils'
|
||||
} from '../../types/blueGreenTypes.js'
|
||||
import * as fileHelper from '../../utilities/fileUtils.js'
|
||||
import {updateSpecLabels} from '../../utilities/manifestSpecLabelUtils.js'
|
||||
import {checkForErrors} from '../../utilities/kubectlUtils.js'
|
||||
import {
|
||||
UnsetClusterSpecificDetails,
|
||||
updateObjectLabels,
|
||||
updateSelectorLabels
|
||||
} from '../../utilities/manifestUpdateUtils'
|
||||
} from '../../utilities/manifestUpdateUtils.js'
|
||||
|
||||
export const GREEN_LABEL_VALUE = 'green'
|
||||
export const NONE_LABEL_VALUE = 'None'
|
||||
|
||||
@ -1,21 +1,23 @@
|
||||
import {BlueGreenDeployment} from '../../types/blueGreenTypes'
|
||||
import {vi} from 'vitest'
|
||||
import type {MockInstance} from 'vitest'
|
||||
import {BlueGreenDeployment} from '../../types/blueGreenTypes.js'
|
||||
import {
|
||||
deployBlueGreen,
|
||||
deployBlueGreenIngress,
|
||||
deployBlueGreenService,
|
||||
deployBlueGreenSMI
|
||||
} from './deploy'
|
||||
import * as routeTester from './route'
|
||||
import {Kubectl} from '../../types/kubectl'
|
||||
import {RouteStrategy} from '../../types/routeStrategy'
|
||||
import * as TSutils from '../../utilities/trafficSplitUtils'
|
||||
import * as bgHelper from './blueGreenHelper'
|
||||
import * as smiHelper from './smiBlueGreenHelper'
|
||||
} from './deploy.js'
|
||||
import * as routeTester from './route.js'
|
||||
import {Kubectl} from '../../types/kubectl.js'
|
||||
import {RouteStrategy} from '../../types/routeStrategy.js'
|
||||
import * as TSutils from '../../utilities/trafficSplitUtils.js'
|
||||
import * as bgHelper from './blueGreenHelper.js'
|
||||
import * as smiHelper from './smiBlueGreenHelper.js'
|
||||
import {ExecOutput} from '@actions/exec'
|
||||
|
||||
const ingressFilepath = ['test/unit/manifests/test-ingress-new.yml']
|
||||
|
||||
jest.mock('../../types/kubectl')
|
||||
vi.mock('../../types/kubectl')
|
||||
|
||||
// Shared variables and mock objects used across all test suites
|
||||
const mockDeployResult = {
|
||||
@ -30,7 +32,7 @@ const mockBgDeployment: BlueGreenDeployment = {
|
||||
|
||||
describe('deploy tests', () => {
|
||||
let kubectl: Kubectl
|
||||
let kubectlApplySpy: jest.SpyInstance
|
||||
let kubectlApplySpy: MockInstance
|
||||
|
||||
const mockSuccessResult: ExecOutput = {
|
||||
stdout: 'deployment.apps/nginx-deployment created',
|
||||
@ -45,21 +47,20 @@ describe('deploy tests', () => {
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
//@ts-ignore
|
||||
Kubectl.mockClear()
|
||||
vi.mocked(Kubectl).mockClear()
|
||||
kubectl = new Kubectl('')
|
||||
kubectlApplySpy = jest.spyOn(kubectl, 'apply')
|
||||
kubectlApplySpy = vi.spyOn(kubectl, 'apply')
|
||||
})
|
||||
|
||||
test('correctly determines deploy type and acts accordingly', async () => {
|
||||
kubectlApplySpy.mockResolvedValue(mockSuccessResult)
|
||||
|
||||
jest
|
||||
.spyOn(routeTester, 'routeBlueGreenForDeploy')
|
||||
.mockImplementation(() => Promise.resolve(mockBgDeployment))
|
||||
jest
|
||||
.spyOn(TSutils, 'getTrafficSplitAPIVersion')
|
||||
.mockImplementation(() => Promise.resolve('v1alpha3'))
|
||||
vi.spyOn(routeTester, 'routeBlueGreenForDeploy').mockImplementation(() =>
|
||||
Promise.resolve(mockBgDeployment)
|
||||
)
|
||||
vi.spyOn(TSutils, 'getTrafficSplitAPIVersion').mockImplementation(() =>
|
||||
Promise.resolve('v1alpha3')
|
||||
)
|
||||
|
||||
const ingressResult = await deployBlueGreen(
|
||||
kubectl,
|
||||
@ -112,12 +113,12 @@ describe('deploy tests', () => {
|
||||
fn: () =>
|
||||
deployBlueGreen(kubectl, ingressFilepath, RouteStrategy.INGRESS),
|
||||
setup: () => {
|
||||
jest
|
||||
.spyOn(routeTester, 'routeBlueGreenForDeploy')
|
||||
.mockImplementation(() => Promise.resolve(mockBgDeployment))
|
||||
jest
|
||||
.spyOn(TSutils, 'getTrafficSplitAPIVersion')
|
||||
.mockImplementation(() => Promise.resolve('v1alpha3'))
|
||||
vi.spyOn(routeTester, 'routeBlueGreenForDeploy').mockImplementation(
|
||||
() => Promise.resolve(mockBgDeployment)
|
||||
)
|
||||
vi.spyOn(TSutils, 'getTrafficSplitAPIVersion').mockImplementation(
|
||||
() => Promise.resolve('v1alpha3')
|
||||
)
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -125,24 +126,24 @@ describe('deploy tests', () => {
|
||||
fn: () =>
|
||||
deployBlueGreen(kubectl, ingressFilepath, RouteStrategy.SERVICE),
|
||||
setup: () => {
|
||||
jest
|
||||
.spyOn(routeTester, 'routeBlueGreenForDeploy')
|
||||
.mockImplementation(() => Promise.resolve(mockBgDeployment))
|
||||
jest
|
||||
.spyOn(TSutils, 'getTrafficSplitAPIVersion')
|
||||
.mockImplementation(() => Promise.resolve('v1alpha3'))
|
||||
vi.spyOn(routeTester, 'routeBlueGreenForDeploy').mockImplementation(
|
||||
() => Promise.resolve(mockBgDeployment)
|
||||
)
|
||||
vi.spyOn(TSutils, 'getTrafficSplitAPIVersion').mockImplementation(
|
||||
() => Promise.resolve('v1alpha3')
|
||||
)
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'should throw error when kubectl apply fails during blue/green deployment with SMI strategy',
|
||||
fn: () => deployBlueGreen(kubectl, ingressFilepath, RouteStrategy.SMI),
|
||||
setup: () => {
|
||||
jest
|
||||
.spyOn(routeTester, 'routeBlueGreenForDeploy')
|
||||
.mockImplementation(() => Promise.resolve(mockBgDeployment))
|
||||
jest
|
||||
.spyOn(TSutils, 'getTrafficSplitAPIVersion')
|
||||
.mockImplementation(() => Promise.resolve('v1alpha3'))
|
||||
vi.spyOn(routeTester, 'routeBlueGreenForDeploy').mockImplementation(
|
||||
() => Promise.resolve(mockBgDeployment)
|
||||
)
|
||||
vi.spyOn(TSutils, 'getTrafficSplitAPIVersion').mockImplementation(
|
||||
() => Promise.resolve('v1alpha3')
|
||||
)
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -181,8 +182,7 @@ describe('deploy timeout tests', () => {
|
||||
let kubectl: Kubectl
|
||||
|
||||
beforeEach(() => {
|
||||
//@ts-ignore
|
||||
Kubectl.mockClear()
|
||||
vi.mocked(Kubectl).mockClear()
|
||||
kubectl = new Kubectl('')
|
||||
})
|
||||
|
||||
@ -190,16 +190,16 @@ describe('deploy timeout tests', () => {
|
||||
const timeout = '300s'
|
||||
|
||||
// Mock the helper functions that are actually called
|
||||
const deployWithLabelSpy = jest
|
||||
const deployWithLabelSpy = vi
|
||||
.spyOn(bgHelper, 'deployWithLabel')
|
||||
.mockResolvedValue(mockBgDeployment)
|
||||
const deployObjectsSpy = jest
|
||||
const deployObjectsSpy = vi
|
||||
.spyOn(bgHelper, 'deployObjects')
|
||||
.mockResolvedValue(mockDeployResult)
|
||||
const setupSMISpy = jest
|
||||
const setupSMISpy = vi
|
||||
.spyOn(smiHelper, 'setupSMI')
|
||||
.mockResolvedValue(mockBgDeployment)
|
||||
const routeSpy = jest
|
||||
const routeSpy = vi
|
||||
.spyOn(routeTester, 'routeBlueGreenForDeploy')
|
||||
.mockResolvedValue(mockBgDeployment)
|
||||
|
||||
@ -258,10 +258,10 @@ describe('deploy timeout tests', () => {
|
||||
const timeout = '240s'
|
||||
|
||||
// Mock the dependencies
|
||||
const deployWithLabelSpy = jest
|
||||
const deployWithLabelSpy = vi
|
||||
.spyOn(bgHelper, 'deployWithLabel')
|
||||
.mockResolvedValue(mockBgDeployment)
|
||||
const deployObjectsSpy = jest
|
||||
const deployObjectsSpy = vi
|
||||
.spyOn(bgHelper, 'deployObjects')
|
||||
.mockResolvedValue(mockDeployResult)
|
||||
|
||||
@ -290,10 +290,10 @@ describe('deploy timeout tests', () => {
|
||||
const timeout = '180s'
|
||||
|
||||
// Mock the dependencies
|
||||
const deployWithLabelSpy = jest
|
||||
const deployWithLabelSpy = vi
|
||||
.spyOn(bgHelper, 'deployWithLabel')
|
||||
.mockResolvedValue(mockBgDeployment)
|
||||
const deployObjectsSpy = jest
|
||||
const deployObjectsSpy = vi
|
||||
.spyOn(bgHelper, 'deployObjects')
|
||||
.mockResolvedValue(mockDeployResult)
|
||||
|
||||
@ -322,13 +322,13 @@ describe('deploy timeout tests', () => {
|
||||
const timeout = '360s'
|
||||
|
||||
// Mock the dependencies
|
||||
const setupSMISpy = jest
|
||||
const setupSMISpy = vi
|
||||
.spyOn(smiHelper, 'setupSMI')
|
||||
.mockResolvedValue(mockBgDeployment)
|
||||
const deployObjectsSpy = jest
|
||||
const deployObjectsSpy = vi
|
||||
.spyOn(bgHelper, 'deployObjects')
|
||||
.mockResolvedValue(mockDeployResult)
|
||||
const deployWithLabelSpy = jest
|
||||
const deployWithLabelSpy = vi
|
||||
.spyOn(bgHelper, 'deployWithLabel')
|
||||
.mockResolvedValue(mockBgDeployment)
|
||||
|
||||
@ -354,10 +354,10 @@ describe('deploy timeout tests', () => {
|
||||
})
|
||||
|
||||
test('deploy functions without timeout should pass undefined', async () => {
|
||||
const deployWithLabelSpy = jest
|
||||
const deployWithLabelSpy = vi
|
||||
.spyOn(bgHelper, 'deployWithLabel')
|
||||
.mockResolvedValue(mockBgDeployment)
|
||||
const deployObjectsSpy = jest
|
||||
const deployObjectsSpy = vi
|
||||
.spyOn(bgHelper, 'deployObjects')
|
||||
.mockResolvedValue(mockDeployResult)
|
||||
|
||||
|
||||
@ -1,23 +1,23 @@
|
||||
import * as core from '@actions/core'
|
||||
|
||||
import {Kubectl} from '../../types/kubectl'
|
||||
import {Kubectl} from '../../types/kubectl.js'
|
||||
import {
|
||||
BlueGreenDeployment,
|
||||
BlueGreenManifests
|
||||
} from '../../types/blueGreenTypes'
|
||||
} from '../../types/blueGreenTypes.js'
|
||||
|
||||
import {RouteStrategy} from '../../types/routeStrategy'
|
||||
import {RouteStrategy} from '../../types/routeStrategy.js'
|
||||
|
||||
import {
|
||||
deployWithLabel,
|
||||
getManifestObjects,
|
||||
GREEN_LABEL_VALUE,
|
||||
deployObjects
|
||||
} from './blueGreenHelper'
|
||||
import {setupSMI} from './smiBlueGreenHelper'
|
||||
} from './blueGreenHelper.js'
|
||||
import {setupSMI} from './smiBlueGreenHelper.js'
|
||||
|
||||
import {routeBlueGreenForDeploy} from './route'
|
||||
import {DeployResult} from '../../types/deployResult'
|
||||
import {routeBlueGreenForDeploy} from './route.js'
|
||||
import {DeployResult} from '../../types/deployResult.js'
|
||||
|
||||
export async function deployBlueGreen(
|
||||
kubectl: Kubectl,
|
||||
|
||||
@ -1,27 +1,27 @@
|
||||
import {getManifestObjects, GREEN_LABEL_VALUE} from './blueGreenHelper'
|
||||
import * as bgHelper from './blueGreenHelper'
|
||||
import {vi} from 'vitest'
|
||||
import {getManifestObjects, GREEN_LABEL_VALUE} from './blueGreenHelper.js'
|
||||
import * as bgHelper from './blueGreenHelper.js'
|
||||
import {
|
||||
getUpdatedBlueGreenIngress,
|
||||
isIngressRouted,
|
||||
validateIngresses
|
||||
} from './ingressBlueGreenHelper'
|
||||
import {Kubectl} from '../../types/kubectl'
|
||||
import * as fileHelper from '../../utilities/fileUtils'
|
||||
} from './ingressBlueGreenHelper.js'
|
||||
import {Kubectl} from '../../types/kubectl.js'
|
||||
import * as fileHelper from '../../utilities/fileUtils.js'
|
||||
|
||||
const betaFilepath = ['test/unit/manifests/test-ingress.yml']
|
||||
const ingressFilepath = ['test/unit/manifests/test-ingress-new.yml']
|
||||
const kubectl = new Kubectl('')
|
||||
jest.mock('../../types/kubectl')
|
||||
vi.mock('../../types/kubectl')
|
||||
|
||||
describe('ingress blue green helpers', () => {
|
||||
let testObjects
|
||||
beforeEach(() => {
|
||||
//@ts-ignore
|
||||
Kubectl.mockClear()
|
||||
vi.mocked(Kubectl).mockClear()
|
||||
testObjects = getManifestObjects(ingressFilepath)
|
||||
jest
|
||||
.spyOn(fileHelper, 'writeObjectsToFile')
|
||||
.mockImplementationOnce(() => [''])
|
||||
vi.spyOn(fileHelper, 'writeObjectsToFile').mockImplementationOnce(() => [
|
||||
''
|
||||
])
|
||||
})
|
||||
|
||||
test('it should correctly classify ingresses', () => {
|
||||
@ -72,7 +72,7 @@ describe('ingress blue green helpers', () => {
|
||||
|
||||
test('it should validate ingresses', async () => {
|
||||
// what if nothing gets returned from fetchResource?
|
||||
jest.spyOn(bgHelper, 'fetchResource').mockImplementation()
|
||||
vi.spyOn(bgHelper, 'fetchResource').mockResolvedValue(null)
|
||||
let validResponse = await validateIngresses(
|
||||
kubectl,
|
||||
testObjects.ingressEntityList,
|
||||
@ -89,9 +89,9 @@ describe('ingress blue green helpers', () => {
|
||||
const mockLabels = new Map<string, string>()
|
||||
mockLabels[bgHelper.BLUE_GREEN_VERSION_LABEL] = GREEN_LABEL_VALUE
|
||||
mockIngress.metadata.labels = mockLabels
|
||||
jest
|
||||
.spyOn(bgHelper, 'fetchResource')
|
||||
.mockImplementation(() => Promise.resolve(mockIngress))
|
||||
vi.spyOn(bgHelper, 'fetchResource').mockImplementation(() =>
|
||||
Promise.resolve(mockIngress)
|
||||
)
|
||||
validResponse = await validateIngresses(
|
||||
kubectl,
|
||||
testObjects.ingressEntityList,
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
import * as core from '@actions/core'
|
||||
import {K8sIngress} from '../../types/k8sObject'
|
||||
import {K8sIngress} from '../../types/k8sObject.js'
|
||||
import {
|
||||
addBlueGreenLabelsAndAnnotations,
|
||||
BLUE_GREEN_VERSION_LABEL,
|
||||
GREEN_LABEL_VALUE,
|
||||
fetchResource
|
||||
} from './blueGreenHelper'
|
||||
import {Kubectl} from '../../types/kubectl'
|
||||
} from './blueGreenHelper.js'
|
||||
import {Kubectl} from '../../types/kubectl.js'
|
||||
|
||||
const BACKEND = 'backend'
|
||||
|
||||
|
||||
@ -1,20 +1,22 @@
|
||||
import {getManifestObjects} from './blueGreenHelper'
|
||||
import {vi} from 'vitest'
|
||||
import type {MockInstance} from 'vitest'
|
||||
import {getManifestObjects} from './blueGreenHelper.js'
|
||||
import {
|
||||
promoteBlueGreenIngress,
|
||||
promoteBlueGreenService,
|
||||
promoteBlueGreenSMI
|
||||
} from './promote'
|
||||
import {TrafficSplitObject} from '../../types/k8sObject'
|
||||
import * as servicesTester from './serviceBlueGreenHelper'
|
||||
import {Kubectl} from '../../types/kubectl'
|
||||
import {MAX_VAL, MIN_VAL, TRAFFIC_SPLIT_OBJECT} from './smiBlueGreenHelper'
|
||||
import * as smiTester from './smiBlueGreenHelper'
|
||||
import * as bgHelper from './blueGreenHelper'
|
||||
} from './promote.js'
|
||||
import {TrafficSplitObject} from '../../types/k8sObject.js'
|
||||
import * as servicesTester from './serviceBlueGreenHelper.js'
|
||||
import {Kubectl} from '../../types/kubectl.js'
|
||||
import {MAX_VAL, MIN_VAL, TRAFFIC_SPLIT_OBJECT} from './smiBlueGreenHelper.js'
|
||||
import * as smiTester from './smiBlueGreenHelper.js'
|
||||
import * as bgHelper from './blueGreenHelper.js'
|
||||
import {ExecOutput} from '@actions/exec'
|
||||
|
||||
const ingressFilepath = ['test/unit/manifests/test-ingress-new.yml']
|
||||
|
||||
jest.mock('../../types/kubectl')
|
||||
vi.mock('../../types/kubectl')
|
||||
|
||||
// Shared variables used across all test suites
|
||||
let testObjects: any
|
||||
@ -42,13 +44,12 @@ const mockBgDeployment = {
|
||||
}
|
||||
|
||||
describe('promote tests', () => {
|
||||
let kubectlApplySpy: jest.SpyInstance
|
||||
let kubectlApplySpy: MockInstance
|
||||
|
||||
beforeEach(() => {
|
||||
//@ts-ignore
|
||||
Kubectl.mockClear()
|
||||
vi.mocked(Kubectl).mockClear()
|
||||
testObjects = getManifestObjects(ingressFilepath)
|
||||
kubectlApplySpy = jest.spyOn(kubectl, 'apply')
|
||||
kubectlApplySpy = vi.spyOn(kubectl, 'apply')
|
||||
})
|
||||
|
||||
test('promote blue/green ingress', async () => {
|
||||
@ -57,7 +58,7 @@ describe('promote tests', () => {
|
||||
const mockLabels = new Map<string, string>()
|
||||
mockLabels[bgHelper.BLUE_GREEN_VERSION_LABEL] = bgHelper.GREEN_LABEL_VALUE
|
||||
|
||||
jest.spyOn(bgHelper, 'fetchResource').mockImplementation(() =>
|
||||
vi.spyOn(bgHelper, 'fetchResource').mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
kind: 'Ingress',
|
||||
spec: {},
|
||||
@ -82,7 +83,7 @@ describe('promote tests', () => {
|
||||
test('fail to promote invalid blue/green ingress', async () => {
|
||||
const mockLabels = new Map<string, string>()
|
||||
mockLabels[bgHelper.BLUE_GREEN_VERSION_LABEL] = bgHelper.NONE_LABEL_VALUE
|
||||
jest.spyOn(bgHelper, 'fetchResource').mockImplementation(() =>
|
||||
vi.spyOn(bgHelper, 'fetchResource').mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
kind: 'Ingress',
|
||||
spec: {},
|
||||
@ -100,7 +101,7 @@ describe('promote tests', () => {
|
||||
|
||||
const mockLabels = new Map<string, string>()
|
||||
mockLabels[bgHelper.BLUE_GREEN_VERSION_LABEL] = bgHelper.GREEN_LABEL_VALUE
|
||||
jest.spyOn(bgHelper, 'fetchResource').mockImplementation(() =>
|
||||
vi.spyOn(bgHelper, 'fetchResource').mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
kind: 'Service',
|
||||
spec: {selector: mockLabels},
|
||||
@ -120,16 +121,16 @@ describe('promote tests', () => {
|
||||
test('fail to promote invalid blue/green service', async () => {
|
||||
const mockLabels = new Map<string, string>()
|
||||
mockLabels[bgHelper.BLUE_GREEN_VERSION_LABEL] = bgHelper.NONE_LABEL_VALUE
|
||||
jest.spyOn(bgHelper, 'fetchResource').mockImplementation(() =>
|
||||
vi.spyOn(bgHelper, 'fetchResource').mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
kind: 'Service',
|
||||
spec: {},
|
||||
metadata: {labels: mockLabels, name: 'nginx-ingress-green'}
|
||||
})
|
||||
)
|
||||
jest
|
||||
.spyOn(servicesTester, 'validateServicesState')
|
||||
.mockImplementationOnce(() => Promise.resolve(false))
|
||||
vi.spyOn(servicesTester, 'validateServicesState').mockImplementationOnce(
|
||||
() => Promise.resolve(false)
|
||||
)
|
||||
|
||||
await expect(
|
||||
promoteBlueGreenService(kubectl, testObjects)
|
||||
@ -164,9 +165,9 @@ describe('promote tests', () => {
|
||||
]
|
||||
}
|
||||
}
|
||||
jest
|
||||
.spyOn(bgHelper, 'fetchResource')
|
||||
.mockImplementation(() => Promise.resolve(mockTsObject))
|
||||
vi.spyOn(bgHelper, 'fetchResource').mockImplementation(() =>
|
||||
Promise.resolve(mockTsObject)
|
||||
)
|
||||
|
||||
const deployResult = await promoteBlueGreenSMI(kubectl, testObjects)
|
||||
|
||||
@ -182,11 +183,11 @@ describe('promote tests', () => {
|
||||
test('promote blue/green SMI with bad trafficsplit', async () => {
|
||||
const mockLabels = new Map<string, string>()
|
||||
mockLabels[bgHelper.BLUE_GREEN_VERSION_LABEL] = bgHelper.NONE_LABEL_VALUE
|
||||
jest
|
||||
.spyOn(smiTester, 'validateTrafficSplitsState')
|
||||
.mockImplementation(() => Promise.resolve(false))
|
||||
vi.spyOn(smiTester, 'validateTrafficSplitsState').mockImplementation(() =>
|
||||
Promise.resolve(false)
|
||||
)
|
||||
|
||||
expect(promoteBlueGreenSMI(kubectl, testObjects)).rejects.toThrow()
|
||||
await expect(promoteBlueGreenSMI(kubectl, testObjects)).rejects.toThrow()
|
||||
})
|
||||
|
||||
// Consolidated error tests
|
||||
@ -198,7 +199,7 @@ describe('promote tests', () => {
|
||||
const mockLabels = new Map<string, string>()
|
||||
mockLabels[bgHelper.BLUE_GREEN_VERSION_LABEL] =
|
||||
bgHelper.GREEN_LABEL_VALUE
|
||||
jest.spyOn(bgHelper, 'fetchResource').mockImplementation(() =>
|
||||
vi.spyOn(bgHelper, 'fetchResource').mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
kind: 'Ingress',
|
||||
spec: {},
|
||||
@ -214,16 +215,16 @@ describe('promote tests', () => {
|
||||
const mockLabels = new Map<string, string>()
|
||||
mockLabels[bgHelper.BLUE_GREEN_VERSION_LABEL] =
|
||||
bgHelper.GREEN_LABEL_VALUE
|
||||
jest.spyOn(bgHelper, 'fetchResource').mockImplementation(() =>
|
||||
vi.spyOn(bgHelper, 'fetchResource').mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
kind: 'Service',
|
||||
spec: {selector: mockLabels},
|
||||
metadata: {labels: mockLabels, name: 'nginx-service-green'}
|
||||
})
|
||||
)
|
||||
jest
|
||||
.spyOn(servicesTester, 'validateServicesState')
|
||||
.mockResolvedValue(true)
|
||||
vi.spyOn(servicesTester, 'validateServicesState').mockResolvedValue(
|
||||
true
|
||||
)
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -246,12 +247,10 @@ describe('promote tests', () => {
|
||||
]
|
||||
}
|
||||
}
|
||||
jest
|
||||
.spyOn(bgHelper, 'fetchResource')
|
||||
.mockResolvedValue(mockTsObject)
|
||||
jest
|
||||
.spyOn(smiTester, 'validateTrafficSplitsState')
|
||||
.mockResolvedValue(true)
|
||||
vi.spyOn(bgHelper, 'fetchResource').mockResolvedValue(mockTsObject)
|
||||
vi.spyOn(smiTester, 'validateTrafficSplitsState').mockResolvedValue(
|
||||
true
|
||||
)
|
||||
}
|
||||
}
|
||||
])('$name', async ({fn, setup}) => {
|
||||
@ -279,15 +278,12 @@ describe('promote tests', () => {
|
||||
// Timeout tests
|
||||
describe('promote timeout tests', () => {
|
||||
beforeEach(() => {
|
||||
// @ts-ignore
|
||||
Kubectl.mockClear()
|
||||
vi.mocked(Kubectl).mockClear()
|
||||
testObjects = getManifestObjects(ingressFilepath)
|
||||
})
|
||||
|
||||
const mockDeployWithLabel = () =>
|
||||
jest
|
||||
.spyOn(bgHelper, 'deployWithLabel')
|
||||
.mockResolvedValue(mockBgDeployment)
|
||||
vi.spyOn(bgHelper, 'deployWithLabel').mockResolvedValue(mockBgDeployment)
|
||||
|
||||
const setupFetchResource = (
|
||||
kind: string,
|
||||
@ -297,7 +293,7 @@ describe('promote timeout tests', () => {
|
||||
const mockLabels = new Map<string, string>()
|
||||
mockLabels[bgHelper.BLUE_GREEN_VERSION_LABEL] = labelValue
|
||||
|
||||
jest.spyOn(bgHelper, 'fetchResource').mockResolvedValue({
|
||||
vi.spyOn(bgHelper, 'fetchResource').mockResolvedValue({
|
||||
kind,
|
||||
spec: {},
|
||||
metadata: {labels: mockLabels, name}
|
||||
@ -330,9 +326,9 @@ describe('promote timeout tests', () => {
|
||||
'nginx-service-green',
|
||||
bgHelper.GREEN_LABEL_VALUE
|
||||
)
|
||||
jest
|
||||
.spyOn(servicesTester, 'validateServicesState')
|
||||
.mockResolvedValue(true)
|
||||
vi.spyOn(servicesTester, 'validateServicesState').mockResolvedValue(
|
||||
true
|
||||
)
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -359,12 +355,10 @@ describe('promote timeout tests', () => {
|
||||
}
|
||||
}
|
||||
|
||||
jest
|
||||
.spyOn(bgHelper, 'fetchResource')
|
||||
.mockResolvedValue(mockTsObject)
|
||||
jest
|
||||
.spyOn(smiTester, 'validateTrafficSplitsState')
|
||||
.mockResolvedValue(true)
|
||||
vi.spyOn(bgHelper, 'fetchResource').mockResolvedValue(mockTsObject)
|
||||
vi.spyOn(smiTester, 'validateTrafficSplitsState').mockResolvedValue(
|
||||
true
|
||||
)
|
||||
}
|
||||
}
|
||||
])('$name', async ({fn, timeout, setup}) => {
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
import * as core from '@actions/core'
|
||||
|
||||
import {Kubectl} from '../../types/kubectl'
|
||||
import {Kubectl} from '../../types/kubectl.js'
|
||||
|
||||
import {BlueGreenDeployment} from '../../types/blueGreenTypes'
|
||||
import {deployWithLabel, NONE_LABEL_VALUE} from './blueGreenHelper'
|
||||
import {BlueGreenDeployment} from '../../types/blueGreenTypes.js'
|
||||
import {deployWithLabel, NONE_LABEL_VALUE} from './blueGreenHelper.js'
|
||||
|
||||
import {validateIngresses} from './ingressBlueGreenHelper'
|
||||
import {validateServicesState} from './serviceBlueGreenHelper'
|
||||
import {validateTrafficSplitsState} from './smiBlueGreenHelper'
|
||||
import {validateIngresses} from './ingressBlueGreenHelper.js'
|
||||
import {validateServicesState} from './serviceBlueGreenHelper.js'
|
||||
import {validateTrafficSplitsState} from './smiBlueGreenHelper.js'
|
||||
|
||||
export async function promoteBlueGreenIngress(
|
||||
kubectl: Kubectl,
|
||||
|
||||
@ -1,21 +1,23 @@
|
||||
import {getManifestObjects} from './blueGreenHelper'
|
||||
import {Kubectl} from '../../types/kubectl'
|
||||
import {vi} from 'vitest'
|
||||
import type {MockInstance} from 'vitest'
|
||||
import {getManifestObjects} from './blueGreenHelper.js'
|
||||
import {Kubectl} from '../../types/kubectl.js'
|
||||
|
||||
import * as TSutils from '../../utilities/trafficSplitUtils'
|
||||
import * as TSutils from '../../utilities/trafficSplitUtils.js'
|
||||
import {
|
||||
rejectBlueGreenIngress,
|
||||
rejectBlueGreenService,
|
||||
rejectBlueGreenSMI
|
||||
} from './reject'
|
||||
import * as bgHelper from './blueGreenHelper'
|
||||
import * as routeHelper from './route'
|
||||
} from './reject.js'
|
||||
import * as bgHelper from './blueGreenHelper.js'
|
||||
import * as routeHelper from './route.js'
|
||||
|
||||
const ingressFilepath = ['test/unit/manifests/test-ingress-new.yml']
|
||||
const kubectl = new Kubectl('')
|
||||
const TEST_TIMEOUT_SHORT = '60s'
|
||||
const TEST_TIMEOUT_LONG = '120s'
|
||||
|
||||
jest.mock('../../types/kubectl')
|
||||
vi.mock('../../types/kubectl')
|
||||
|
||||
// Shared mock objects following DRY principle
|
||||
const mockSuccessResult = {
|
||||
@ -54,14 +56,13 @@ const mockDeleteResult = [
|
||||
|
||||
describe('reject tests', () => {
|
||||
let testObjects: any
|
||||
let kubectlApplySpy: jest.SpyInstance
|
||||
let kubectlApplySpy: MockInstance
|
||||
|
||||
beforeEach(() => {
|
||||
//@ts-ignore
|
||||
Kubectl.mockClear()
|
||||
jest.restoreAllMocks()
|
||||
vi.mocked(Kubectl).mockClear()
|
||||
vi.restoreAllMocks()
|
||||
testObjects = getManifestObjects(ingressFilepath)
|
||||
kubectlApplySpy = jest.spyOn(kubectl, 'apply')
|
||||
kubectlApplySpy = vi.spyOn(kubectl, 'apply')
|
||||
})
|
||||
|
||||
test('reject blue/green ingress', async () => {
|
||||
@ -89,13 +90,13 @@ describe('reject tests', () => {
|
||||
|
||||
test('reject blue/green ingress with timeout', async () => {
|
||||
// Mock routeBlueGreenIngressUnchanged and deleteGreenObjects
|
||||
jest
|
||||
.spyOn(routeHelper, 'routeBlueGreenIngressUnchanged')
|
||||
.mockResolvedValue(mockBgDeployment)
|
||||
vi.spyOn(routeHelper, 'routeBlueGreenIngressUnchanged').mockResolvedValue(
|
||||
mockBgDeployment
|
||||
)
|
||||
|
||||
jest
|
||||
.spyOn(bgHelper, 'deleteGreenObjects')
|
||||
.mockResolvedValue(mockDeleteResult)
|
||||
vi.spyOn(bgHelper, 'deleteGreenObjects').mockResolvedValue(
|
||||
mockDeleteResult
|
||||
)
|
||||
|
||||
const value = await rejectBlueGreenIngress(
|
||||
kubectl,
|
||||
@ -138,9 +139,9 @@ describe('reject tests', () => {
|
||||
|
||||
test('reject blue/green service', async () => {
|
||||
kubectlApplySpy.mockResolvedValue(mockSuccessResult)
|
||||
jest
|
||||
.spyOn(bgHelper, 'deleteGreenObjects')
|
||||
.mockResolvedValue(mockDeleteResult)
|
||||
vi.spyOn(bgHelper, 'deleteGreenObjects').mockResolvedValue(
|
||||
mockDeleteResult
|
||||
)
|
||||
|
||||
const value = await rejectBlueGreenService(
|
||||
kubectl,
|
||||
@ -163,7 +164,7 @@ describe('reject tests', () => {
|
||||
|
||||
test('reject blue/green service with timeout', async () => {
|
||||
// Mock routeBlueGreenService and deleteGreenObjects
|
||||
jest.spyOn(routeHelper, 'routeBlueGreenService').mockResolvedValue({
|
||||
vi.spyOn(routeHelper, 'routeBlueGreenService').mockResolvedValue({
|
||||
deployResult: {
|
||||
execResult: {stdout: '', stderr: '', exitCode: 0},
|
||||
manifestFiles: []
|
||||
@ -180,11 +181,9 @@ describe('reject tests', () => {
|
||||
]
|
||||
})
|
||||
|
||||
jest
|
||||
.spyOn(bgHelper, 'deleteGreenObjects')
|
||||
.mockResolvedValue([
|
||||
{name: 'nginx-deployment-green', kind: 'Deployment'}
|
||||
])
|
||||
vi.spyOn(bgHelper, 'deleteGreenObjects').mockResolvedValue([
|
||||
{name: 'nginx-deployment-green', kind: 'Deployment'}
|
||||
])
|
||||
|
||||
const value = await rejectBlueGreenService(
|
||||
kubectl,
|
||||
@ -213,9 +212,9 @@ describe('reject tests', () => {
|
||||
// Mock kubectl.apply to return successful result
|
||||
kubectlApplySpy.mockResolvedValue(mockSuccessResult)
|
||||
|
||||
jest
|
||||
.spyOn(TSutils, 'getTrafficSplitAPIVersion')
|
||||
.mockImplementation(() => Promise.resolve('v1alpha3'))
|
||||
vi.spyOn(TSutils, 'getTrafficSplitAPIVersion').mockImplementation(() =>
|
||||
Promise.resolve('v1alpha3')
|
||||
)
|
||||
const rejectResult = await rejectBlueGreenSMI(kubectl, testObjects)
|
||||
expect(rejectResult.deleteResult).toHaveLength(2)
|
||||
})
|
||||
@ -226,27 +225,27 @@ describe('reject tests', () => {
|
||||
name: 'should throw error when kubectl apply fails during blue/green ingress rejection',
|
||||
fn: () => rejectBlueGreenIngress(kubectl, testObjects),
|
||||
setup: () => {
|
||||
jest
|
||||
.spyOn(bgHelper, 'deleteGreenObjects')
|
||||
.mockResolvedValue(mockDeleteResult)
|
||||
vi.spyOn(bgHelper, 'deleteGreenObjects').mockResolvedValue(
|
||||
mockDeleteResult
|
||||
)
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'should throw error when kubectl apply fails during blue/green service rejection',
|
||||
fn: () => rejectBlueGreenService(kubectl, testObjects),
|
||||
setup: () => {
|
||||
jest
|
||||
.spyOn(bgHelper, 'deleteGreenObjects')
|
||||
.mockResolvedValue(mockDeleteResult)
|
||||
vi.spyOn(bgHelper, 'deleteGreenObjects').mockResolvedValue(
|
||||
mockDeleteResult
|
||||
)
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'should throw error when kubectl apply fails during blue/green SMI rejection',
|
||||
fn: () => rejectBlueGreenSMI(kubectl, testObjects),
|
||||
setup: () => {
|
||||
jest
|
||||
.spyOn(TSutils, 'getTrafficSplitAPIVersion')
|
||||
.mockImplementation(() => Promise.resolve('v1alpha3'))
|
||||
vi.spyOn(TSutils, 'getTrafficSplitAPIVersion').mockImplementation(
|
||||
() => Promise.resolve('v1alpha3')
|
||||
)
|
||||
}
|
||||
}
|
||||
])('$name', async ({fn, setup}) => {
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
import {K8sDeleteObject} from '../../types/k8sObject'
|
||||
import {Kubectl} from '../../types/kubectl'
|
||||
import {K8sDeleteObject} from '../../types/k8sObject.js'
|
||||
import {Kubectl} from '../../types/kubectl.js'
|
||||
import {
|
||||
BlueGreenDeployment,
|
||||
BlueGreenManifests,
|
||||
BlueGreenRejectResult
|
||||
} from '../../types/blueGreenTypes'
|
||||
import {deleteGreenObjects, NONE_LABEL_VALUE} from './blueGreenHelper'
|
||||
import {routeBlueGreenSMI} from './route'
|
||||
import {cleanupSMI} from './smiBlueGreenHelper'
|
||||
import {routeBlueGreenIngressUnchanged, routeBlueGreenService} from './route'
|
||||
} from '../../types/blueGreenTypes.js'
|
||||
import {deleteGreenObjects, NONE_LABEL_VALUE} from './blueGreenHelper.js'
|
||||
import {routeBlueGreenSMI} from './route.js'
|
||||
import {cleanupSMI} from './smiBlueGreenHelper.js'
|
||||
import {routeBlueGreenIngressUnchanged, routeBlueGreenService} from './route.js'
|
||||
|
||||
export async function rejectBlueGreenIngress(
|
||||
kubectl: Kubectl,
|
||||
|
||||
@ -1,24 +1,28 @@
|
||||
import {K8sIngress, TrafficSplitObject} from '../../types/k8sObject'
|
||||
import {Kubectl} from '../../types/kubectl'
|
||||
import * as fileHelper from '../../utilities/fileUtils'
|
||||
import * as TSutils from '../../utilities/trafficSplitUtils'
|
||||
import {RouteStrategy} from '../../types/routeStrategy'
|
||||
import {BlueGreenManifests} from '../../types/blueGreenTypes'
|
||||
import {vi} from 'vitest'
|
||||
import type {MockInstance} from 'vitest'
|
||||
import {K8sIngress, TrafficSplitObject} from '../../types/k8sObject.js'
|
||||
import {Kubectl} from '../../types/kubectl.js'
|
||||
import * as fileHelper from '../../utilities/fileUtils.js'
|
||||
import * as TSutils from '../../utilities/trafficSplitUtils.js'
|
||||
import {RouteStrategy} from '../../types/routeStrategy.js'
|
||||
import {BlueGreenManifests} from '../../types/blueGreenTypes.js'
|
||||
|
||||
import {
|
||||
BLUE_GREEN_VERSION_LABEL,
|
||||
getManifestObjects,
|
||||
GREEN_LABEL_VALUE
|
||||
} from './blueGreenHelper'
|
||||
} from './blueGreenHelper.js'
|
||||
import * as bgHelper from './blueGreenHelper.js'
|
||||
import * as smiHelper from './smiBlueGreenHelper.js'
|
||||
import {
|
||||
routeBlueGreenIngress,
|
||||
routeBlueGreenService,
|
||||
routeBlueGreenForDeploy,
|
||||
routeBlueGreenSMI,
|
||||
routeBlueGreenIngressUnchanged
|
||||
} from './route'
|
||||
} from './route.js'
|
||||
|
||||
jest.mock('../../types/kubectl')
|
||||
vi.mock('../../types/kubectl')
|
||||
const ingressFilepath = ['test/unit/manifests/test-ingress-new.yml']
|
||||
const kc = new Kubectl('')
|
||||
|
||||
@ -37,16 +41,15 @@ const mockFailureResult = {
|
||||
|
||||
describe('route function tests', () => {
|
||||
let testObjects: BlueGreenManifests
|
||||
let kubectlApplySpy: jest.SpyInstance
|
||||
let kubectlApplySpy: MockInstance
|
||||
|
||||
beforeEach(() => {
|
||||
//@ts-ignore
|
||||
Kubectl.mockClear()
|
||||
vi.mocked(Kubectl).mockClear()
|
||||
testObjects = getManifestObjects(ingressFilepath)
|
||||
kubectlApplySpy = jest.spyOn(kc, 'apply')
|
||||
jest
|
||||
.spyOn(fileHelper, 'writeObjectsToFile')
|
||||
.mockImplementationOnce(() => [''])
|
||||
kubectlApplySpy = vi.spyOn(kc, 'apply')
|
||||
vi.spyOn(fileHelper, 'writeObjectsToFile').mockImplementationOnce(() => [
|
||||
''
|
||||
])
|
||||
})
|
||||
|
||||
test('correctly prepares blue/green ingresses for deployment', async () => {
|
||||
@ -96,9 +99,9 @@ describe('route function tests', () => {
|
||||
})
|
||||
|
||||
test('correctly identifies route pattern and acts accordingly', async () => {
|
||||
jest
|
||||
.spyOn(TSutils, 'getTrafficSplitAPIVersion')
|
||||
.mockImplementation(() => Promise.resolve('v1alpha3'))
|
||||
vi.spyOn(TSutils, 'getTrafficSplitAPIVersion').mockImplementation(() =>
|
||||
Promise.resolve('v1alpha3')
|
||||
)
|
||||
|
||||
const ingressResult = await routeBlueGreenForDeploy(
|
||||
kc,
|
||||
@ -164,9 +167,9 @@ describe('route function tests', () => {
|
||||
testObjects.serviceEntityList
|
||||
),
|
||||
setup: () => {
|
||||
jest
|
||||
.spyOn(TSutils, 'getTrafficSplitAPIVersion')
|
||||
.mockImplementation(() => Promise.resolve('v1alpha3'))
|
||||
vi.spyOn(TSutils, 'getTrafficSplitAPIVersion').mockImplementation(
|
||||
() => Promise.resolve('v1alpha3')
|
||||
)
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -194,24 +197,23 @@ describe('route timeout tests', () => {
|
||||
let testObjects: BlueGreenManifests
|
||||
|
||||
beforeEach(() => {
|
||||
//@ts-ignore
|
||||
Kubectl.mockClear()
|
||||
vi.mocked(Kubectl).mockClear()
|
||||
testObjects = getManifestObjects(ingressFilepath)
|
||||
jest
|
||||
.spyOn(fileHelper, 'writeObjectsToFile')
|
||||
.mockImplementationOnce(() => [''])
|
||||
vi.spyOn(fileHelper, 'writeObjectsToFile').mockImplementationOnce(() => [
|
||||
''
|
||||
])
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks()
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
test('routeBlueGreenService with timeout', async () => {
|
||||
const timeout = '240s'
|
||||
|
||||
// Mock deployObjects to capture timeout parameter
|
||||
const deployObjectsSpy = jest
|
||||
.spyOn(require('./blueGreenHelper'), 'deployObjects')
|
||||
const deployObjectsSpy = vi
|
||||
.spyOn(bgHelper, 'deployObjects')
|
||||
.mockResolvedValue({
|
||||
execResult: mockSuccessResult,
|
||||
manifestFiles: []
|
||||
@ -237,23 +239,29 @@ describe('route timeout tests', () => {
|
||||
test('routeBlueGreenSMI with timeout', async () => {
|
||||
const timeout = '300s'
|
||||
|
||||
jest
|
||||
.spyOn(TSutils, 'getTrafficSplitAPIVersion')
|
||||
.mockImplementation(() => Promise.resolve('v1alpha3'))
|
||||
vi.spyOn(TSutils, 'getTrafficSplitAPIVersion').mockImplementation(() =>
|
||||
Promise.resolve('v1alpha3')
|
||||
)
|
||||
|
||||
// Mock deployObjects and createTrafficSplitObject to capture timeout parameter
|
||||
const deployObjectsSpy = jest
|
||||
.spyOn(require('./blueGreenHelper'), 'deployObjects')
|
||||
const deployObjectsSpy = vi
|
||||
.spyOn(bgHelper, 'deployObjects')
|
||||
.mockResolvedValue({
|
||||
execResult: mockSuccessResult,
|
||||
manifestFiles: []
|
||||
})
|
||||
|
||||
const createTrafficSplitSpy = jest
|
||||
.spyOn(require('./smiBlueGreenHelper'), 'createTrafficSplitObject')
|
||||
const createTrafficSplitSpy = vi
|
||||
.spyOn(smiHelper, 'createTrafficSplitObject')
|
||||
.mockResolvedValue({
|
||||
metadata: {name: 'nginx-service-trafficsplit'},
|
||||
spec: {backends: []}
|
||||
apiVersion: 'split.smi-spec.io/v1alpha3',
|
||||
kind: 'TrafficSplit',
|
||||
metadata: {
|
||||
name: 'nginx-service-trafficsplit',
|
||||
labels: new Map(),
|
||||
annotations: new Map()
|
||||
},
|
||||
spec: {service: 'nginx-service', backends: []}
|
||||
})
|
||||
|
||||
const value = await routeBlueGreenSMI(
|
||||
@ -284,8 +292,8 @@ describe('route timeout tests', () => {
|
||||
const timeout = '180s'
|
||||
|
||||
// Mock deployObjects to capture timeout parameter
|
||||
const deployObjectsSpy = jest
|
||||
.spyOn(require('./blueGreenHelper'), 'deployObjects')
|
||||
const deployObjectsSpy = vi
|
||||
.spyOn(bgHelper, 'deployObjects')
|
||||
.mockResolvedValue({
|
||||
execResult: mockSuccessResult,
|
||||
manifestFiles: []
|
||||
@ -309,8 +317,8 @@ describe('route timeout tests', () => {
|
||||
})
|
||||
|
||||
test('route functions without timeout should pass undefined', async () => {
|
||||
const deployObjectsSpy = jest
|
||||
.spyOn(require('./blueGreenHelper'), 'deployObjects')
|
||||
const deployObjectsSpy = vi
|
||||
.spyOn(bgHelper, 'deployObjects')
|
||||
.mockResolvedValue({
|
||||
execResult: mockSuccessResult,
|
||||
manifestFiles: []
|
||||
|
||||
@ -1,26 +1,26 @@
|
||||
import {sleep} from '../../utilities/timeUtils'
|
||||
import {RouteStrategy} from '../../types/routeStrategy'
|
||||
import {Kubectl} from '../../types/kubectl'
|
||||
import {sleep} from '../../utilities/timeUtils.js'
|
||||
import {RouteStrategy} from '../../types/routeStrategy.js'
|
||||
import {Kubectl} from '../../types/kubectl.js'
|
||||
import {
|
||||
BlueGreenDeployment,
|
||||
BlueGreenManifests
|
||||
} from '../../types/blueGreenTypes'
|
||||
} from '../../types/blueGreenTypes.js'
|
||||
import {
|
||||
getManifestObjects,
|
||||
GREEN_LABEL_VALUE,
|
||||
deployObjects
|
||||
} from './blueGreenHelper'
|
||||
} from './blueGreenHelper.js'
|
||||
|
||||
import {
|
||||
getUpdatedBlueGreenIngress,
|
||||
isIngressRouted
|
||||
} from './ingressBlueGreenHelper'
|
||||
import {getUpdatedBlueGreenService} from './serviceBlueGreenHelper'
|
||||
import {createTrafficSplitObject} from './smiBlueGreenHelper'
|
||||
} from './ingressBlueGreenHelper.js'
|
||||
import {getUpdatedBlueGreenService} from './serviceBlueGreenHelper.js'
|
||||
import {createTrafficSplitObject} from './smiBlueGreenHelper.js'
|
||||
|
||||
import * as core from '@actions/core'
|
||||
import {K8sObject, TrafficSplitObject} from '../../types/k8sObject'
|
||||
import {getBufferTime} from '../../inputUtils'
|
||||
import {K8sObject, TrafficSplitObject} from '../../types/k8sObject.js'
|
||||
import {getBufferTime} from '../../inputUtils.js'
|
||||
|
||||
export async function routeBlueGreenForDeploy(
|
||||
kubectl: Kubectl,
|
||||
|
||||
@ -1,26 +1,26 @@
|
||||
import {vi} from 'vitest'
|
||||
import * as core from '@actions/core'
|
||||
import {
|
||||
BLUE_GREEN_VERSION_LABEL,
|
||||
getManifestObjects,
|
||||
GREEN_LABEL_VALUE
|
||||
} from './blueGreenHelper'
|
||||
import * as bgHelper from './blueGreenHelper'
|
||||
import {Kubectl} from '../../types/kubectl'
|
||||
} from './blueGreenHelper.js'
|
||||
import * as bgHelper from './blueGreenHelper.js'
|
||||
import {Kubectl} from '../../types/kubectl.js'
|
||||
import {
|
||||
getServiceSpecLabel,
|
||||
getUpdatedBlueGreenService,
|
||||
validateServicesState
|
||||
} from './serviceBlueGreenHelper'
|
||||
} from './serviceBlueGreenHelper.js'
|
||||
|
||||
let testObjects
|
||||
const ingressFilepath = ['test/unit/manifests/test-ingress-new.yml']
|
||||
jest.mock('../../types/kubectl')
|
||||
vi.mock('../../types/kubectl')
|
||||
const kubectl = new Kubectl('')
|
||||
|
||||
describe('blue/green service helper tests', () => {
|
||||
beforeEach(() => {
|
||||
//@ts-ignore
|
||||
Kubectl.mockClear()
|
||||
vi.mocked(Kubectl).mockClear()
|
||||
testObjects = getManifestObjects(ingressFilepath)
|
||||
})
|
||||
|
||||
@ -42,7 +42,7 @@ describe('blue/green service helper tests', () => {
|
||||
mockLabels[BLUE_GREEN_VERSION_LABEL] = bgHelper.GREEN_LABEL_VALUE
|
||||
const mockSelectors = new Map<string, string>()
|
||||
mockSelectors[BLUE_GREEN_VERSION_LABEL] = GREEN_LABEL_VALUE
|
||||
jest.spyOn(bgHelper, 'fetchResource').mockImplementation(() =>
|
||||
vi.spyOn(bgHelper, 'fetchResource').mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
kind: 'Service',
|
||||
spec: {selector: mockSelectors},
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
import * as core from '@actions/core'
|
||||
import {K8sServiceObject} from '../../types/k8sObject'
|
||||
import {Kubectl} from '../../types/kubectl'
|
||||
import {K8sServiceObject} from '../../types/k8sObject.js'
|
||||
import {Kubectl} from '../../types/kubectl.js'
|
||||
import {
|
||||
addBlueGreenLabelsAndAnnotations,
|
||||
BLUE_GREEN_VERSION_LABEL,
|
||||
fetchResource,
|
||||
GREEN_LABEL_VALUE
|
||||
} from './blueGreenHelper'
|
||||
} from './blueGreenHelper.js'
|
||||
|
||||
// add green labels to configure existing service
|
||||
export function getUpdatedBlueGreenService(
|
||||
|
||||
@ -1,15 +1,16 @@
|
||||
import {TrafficSplitObject} from '../../types/k8sObject'
|
||||
import {Kubectl} from '../../types/kubectl'
|
||||
import * as fileHelper from '../../utilities/fileUtils'
|
||||
import * as TSutils from '../../utilities/trafficSplitUtils'
|
||||
import {vi} from 'vitest'
|
||||
import {TrafficSplitObject} from '../../types/k8sObject.js'
|
||||
import {Kubectl} from '../../types/kubectl.js'
|
||||
import * as fileHelper from '../../utilities/fileUtils.js'
|
||||
import * as TSutils from '../../utilities/trafficSplitUtils.js'
|
||||
|
||||
import {BlueGreenManifests} from '../../types/blueGreenTypes'
|
||||
import {BlueGreenManifests} from '../../types/blueGreenTypes.js'
|
||||
import {
|
||||
BLUE_GREEN_VERSION_LABEL,
|
||||
getManifestObjects,
|
||||
GREEN_LABEL_VALUE,
|
||||
NONE_LABEL_VALUE
|
||||
} from './blueGreenHelper'
|
||||
} from './blueGreenHelper.js'
|
||||
|
||||
import {
|
||||
cleanupSMI,
|
||||
@ -21,10 +22,10 @@ import {
|
||||
setupSMI,
|
||||
TRAFFIC_SPLIT_OBJECT,
|
||||
validateTrafficSplitsState
|
||||
} from './smiBlueGreenHelper'
|
||||
import * as bgHelper from './blueGreenHelper'
|
||||
} from './smiBlueGreenHelper.js'
|
||||
import * as bgHelper from './blueGreenHelper.js'
|
||||
|
||||
jest.mock('../../types/kubectl')
|
||||
vi.mock('../../types/kubectl')
|
||||
|
||||
const kc = new Kubectl('')
|
||||
const ingressFilepath = ['test/unit/manifests/test-ingress-new.yml']
|
||||
@ -68,21 +69,20 @@ const mockTsObject: TrafficSplitObject = {
|
||||
describe('SMI Helper tests', () => {
|
||||
let testObjects: BlueGreenManifests
|
||||
beforeEach(() => {
|
||||
//@ts-ignore
|
||||
Kubectl.mockClear()
|
||||
vi.mocked(Kubectl).mockClear()
|
||||
|
||||
jest
|
||||
.spyOn(TSutils, 'getTrafficSplitAPIVersion')
|
||||
.mockImplementation(() => Promise.resolve(''))
|
||||
vi.spyOn(TSutils, 'getTrafficSplitAPIVersion').mockImplementation(() =>
|
||||
Promise.resolve('')
|
||||
)
|
||||
|
||||
testObjects = getManifestObjects(ingressFilepath)
|
||||
jest
|
||||
.spyOn(fileHelper, 'writeObjectsToFile')
|
||||
.mockImplementationOnce(() => [''])
|
||||
vi.spyOn(fileHelper, 'writeObjectsToFile').mockImplementationOnce(() => [
|
||||
''
|
||||
])
|
||||
})
|
||||
|
||||
test('setupSMI tests', async () => {
|
||||
jest.spyOn(kc, 'apply').mockResolvedValue(mockSuccessResult)
|
||||
vi.spyOn(kc, 'apply').mockResolvedValue(mockSuccessResult)
|
||||
|
||||
const smiResults = await setupSMI(kc, testObjects.serviceEntityList)
|
||||
|
||||
@ -174,9 +174,9 @@ describe('SMI Helper tests', () => {
|
||||
})
|
||||
|
||||
test('validateTrafficSplitsState', async () => {
|
||||
jest
|
||||
.spyOn(bgHelper, 'fetchResource')
|
||||
.mockImplementation(() => Promise.resolve(mockTsObject))
|
||||
vi.spyOn(bgHelper, 'fetchResource').mockImplementation(() =>
|
||||
Promise.resolve(mockTsObject)
|
||||
)
|
||||
|
||||
let valResult = await validateTrafficSplitsState(
|
||||
kc,
|
||||
@ -187,9 +187,9 @@ describe('SMI Helper tests', () => {
|
||||
|
||||
const mockTsCopy = JSON.parse(JSON.stringify(mockTsObject))
|
||||
mockTsCopy.spec.backends[0].weight = MAX_VAL
|
||||
jest
|
||||
.spyOn(bgHelper, 'fetchResource')
|
||||
.mockImplementation(() => Promise.resolve(mockTsCopy))
|
||||
vi.spyOn(bgHelper, 'fetchResource').mockImplementation(() =>
|
||||
Promise.resolve(mockTsCopy)
|
||||
)
|
||||
|
||||
valResult = await validateTrafficSplitsState(
|
||||
kc,
|
||||
@ -197,7 +197,7 @@ describe('SMI Helper tests', () => {
|
||||
)
|
||||
expect(valResult).toBe(false)
|
||||
|
||||
jest.spyOn(bgHelper, 'fetchResource').mockImplementation()
|
||||
vi.spyOn(bgHelper, 'fetchResource').mockResolvedValue(null)
|
||||
valResult = await validateTrafficSplitsState(
|
||||
kc,
|
||||
testObjects.serviceEntityList
|
||||
@ -218,7 +218,7 @@ describe('SMI Helper tests', () => {
|
||||
name: 'should throw error when kubectl apply fails during SMI setup',
|
||||
fn: () => setupSMI(kc, testObjects.serviceEntityList),
|
||||
setup: () => {
|
||||
jest.spyOn(kc, 'apply').mockResolvedValue(mockFailureResult)
|
||||
vi.spyOn(kc, 'apply').mockResolvedValue(mockFailureResult)
|
||||
}
|
||||
}
|
||||
])('$name', async ({fn, setup}) => {
|
||||
@ -229,7 +229,7 @@ describe('SMI Helper tests', () => {
|
||||
|
||||
// Timeout-specific tests
|
||||
test('setupSMI with timeout test', async () => {
|
||||
const deployObjectsSpy = jest
|
||||
const deployObjectsSpy = vi
|
||||
.spyOn(bgHelper, 'deployObjects')
|
||||
.mockResolvedValue({
|
||||
execResult: mockSuccessResult,
|
||||
@ -257,7 +257,7 @@ describe('SMI Helper tests', () => {
|
||||
})
|
||||
|
||||
test('createTrafficSplitObject with timeout test', async () => {
|
||||
const deleteObjectsSpy = jest
|
||||
const deleteObjectsSpy = vi
|
||||
.spyOn(bgHelper, 'deleteObjects')
|
||||
.mockResolvedValue()
|
||||
|
||||
@ -288,7 +288,7 @@ describe('SMI Helper tests', () => {
|
||||
})
|
||||
|
||||
test('createTrafficSplitObject with GREEN_LABEL_VALUE and timeout test', async () => {
|
||||
const deleteObjectsSpy = jest
|
||||
const deleteObjectsSpy = vi
|
||||
.spyOn(bgHelper, 'deleteObjects')
|
||||
.mockResolvedValue()
|
||||
|
||||
@ -321,7 +321,7 @@ describe('SMI Helper tests', () => {
|
||||
})
|
||||
|
||||
test('cleanupSMI with timeout test', async () => {
|
||||
const deleteObjectsSpy = jest
|
||||
const deleteObjectsSpy = vi
|
||||
.spyOn(bgHelper, 'deleteObjects')
|
||||
.mockResolvedValue()
|
||||
|
||||
@ -352,7 +352,7 @@ describe('SMI Helper tests', () => {
|
||||
})
|
||||
|
||||
test('setupSMI without timeout test', async () => {
|
||||
const deployObjectsSpy = jest
|
||||
const deployObjectsSpy = vi
|
||||
.spyOn(bgHelper, 'deployObjects')
|
||||
.mockResolvedValue({
|
||||
execResult: mockSuccessResult,
|
||||
@ -375,7 +375,7 @@ describe('SMI Helper tests', () => {
|
||||
})
|
||||
|
||||
test('createTrafficSplitObject without timeout test', async () => {
|
||||
const deleteObjectsSpy = jest
|
||||
const deleteObjectsSpy = vi
|
||||
.spyOn(bgHelper, 'deleteObjects')
|
||||
.mockResolvedValue()
|
||||
|
||||
@ -398,7 +398,7 @@ describe('SMI Helper tests', () => {
|
||||
})
|
||||
|
||||
test('cleanupSMI without timeout test', async () => {
|
||||
const deleteObjectsSpy = jest
|
||||
const deleteObjectsSpy = vi
|
||||
.spyOn(bgHelper, 'deleteObjects')
|
||||
.mockResolvedValue()
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import * as core from '@actions/core'
|
||||
import {Kubectl} from '../../types/kubectl'
|
||||
import * as kubectlUtils from '../../utilities/trafficSplitUtils'
|
||||
import {Kubectl} from '../../types/kubectl.js'
|
||||
import * as kubectlUtils from '../../utilities/trafficSplitUtils.js'
|
||||
import {
|
||||
deleteObjects,
|
||||
deployObjects,
|
||||
@ -11,15 +11,15 @@ import {
|
||||
GREEN_SUFFIX,
|
||||
NONE_LABEL_VALUE,
|
||||
STABLE_SUFFIX
|
||||
} from './blueGreenHelper'
|
||||
import {BlueGreenDeployment} from '../../types/blueGreenTypes'
|
||||
} from './blueGreenHelper.js'
|
||||
import {BlueGreenDeployment} from '../../types/blueGreenTypes.js'
|
||||
import {
|
||||
K8sDeleteObject,
|
||||
K8sObject,
|
||||
TrafficSplitObject
|
||||
} from '../../types/k8sObject'
|
||||
import {DeployResult} from '../../types/deployResult'
|
||||
import {inputAnnotations} from '../../inputUtils'
|
||||
} from '../../types/k8sObject.js'
|
||||
import {DeployResult} from '../../types/deployResult.js'
|
||||
import {inputAnnotations} from '../../inputUtils.js'
|
||||
|
||||
export const TRAFFIC_SPLIT_OBJECT_NAME_SUFFIX = '-trafficsplit'
|
||||
export const TRAFFIC_SPLIT_OBJECT = 'TrafficSplit'
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import {Kubectl} from '../../types/kubectl'
|
||||
import {Kubectl} from '../../types/kubectl.js'
|
||||
import * as fs from 'fs'
|
||||
import * as yaml from 'js-yaml'
|
||||
import * as core from '@actions/core'
|
||||
@ -7,15 +7,15 @@ import {
|
||||
isDeploymentEntity,
|
||||
isServiceEntity,
|
||||
KubernetesWorkload
|
||||
} from '../../types/kubernetesTypes'
|
||||
import * as utils from '../../utilities/manifestUpdateUtils'
|
||||
} from '../../types/kubernetesTypes.js'
|
||||
import * as utils from '../../utilities/manifestUpdateUtils.js'
|
||||
import {
|
||||
updateObjectAnnotations,
|
||||
updateObjectLabels,
|
||||
updateSelectorLabels
|
||||
} from '../../utilities/manifestUpdateUtils'
|
||||
import {updateSpecLabels} from '../../utilities/manifestSpecLabelUtils'
|
||||
import {checkForErrors} from '../../utilities/kubectlUtils'
|
||||
} from '../../utilities/manifestUpdateUtils.js'
|
||||
import {updateSpecLabels} from '../../utilities/manifestSpecLabelUtils.js'
|
||||
import {checkForErrors} from '../../utilities/kubectlUtils.js'
|
||||
|
||||
export const CANARY_VERSION_LABEL = 'workflow/version'
|
||||
const BASELINE_SUFFIX = '-baseline'
|
||||
|
||||
@ -1,11 +1,15 @@
|
||||
import {vi} from 'vitest'
|
||||
import type {MockInstance} from 'vitest'
|
||||
vi.mock('@actions/core')
|
||||
|
||||
import * as core from '@actions/core'
|
||||
import {Kubectl} from '../../types/kubectl'
|
||||
import {Kubectl} from '../../types/kubectl.js'
|
||||
import {
|
||||
deployPodCanary,
|
||||
calculateReplicaCountForCanary
|
||||
} from './podCanaryHelper'
|
||||
} from './podCanaryHelper.js'
|
||||
|
||||
jest.mock('../../types/kubectl')
|
||||
vi.mock('../../types/kubectl')
|
||||
|
||||
const kc = new Kubectl('')
|
||||
|
||||
@ -35,18 +39,17 @@ const TIMEOUT_300S = '300s'
|
||||
|
||||
describe('Pod Canary Helper tests', () => {
|
||||
let mockFilePaths: string[]
|
||||
let kubectlApplySpy: jest.SpyInstance
|
||||
let kubectlApplySpy: MockInstance
|
||||
|
||||
beforeEach(() => {
|
||||
//@ts-ignore
|
||||
Kubectl.mockClear()
|
||||
jest.restoreAllMocks()
|
||||
vi.mocked(Kubectl).mockClear()
|
||||
vi.restoreAllMocks()
|
||||
|
||||
mockFilePaths = testManifestFiles
|
||||
kubectlApplySpy = jest.spyOn(kc, 'apply')
|
||||
kubectlApplySpy = vi.spyOn(kc, 'apply')
|
||||
|
||||
// Mock core.getInput with default values
|
||||
jest.spyOn(core, 'getInput').mockImplementation((name: string) => {
|
||||
vi.spyOn(core, 'getInput').mockImplementation((name: string) => {
|
||||
switch (name) {
|
||||
case 'percentage':
|
||||
return VALID_PERCENTAGE.toString()
|
||||
@ -61,7 +64,7 @@ describe('Pod Canary Helper tests', () => {
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks()
|
||||
vi.restoreAllMocks()
|
||||
kubectlApplySpy.mockClear()
|
||||
})
|
||||
|
||||
@ -114,7 +117,7 @@ describe('Pod Canary Helper tests', () => {
|
||||
})
|
||||
|
||||
test('should throw error for invalid low percentage', async () => {
|
||||
jest.spyOn(core, 'getInput').mockImplementation((name: string) => {
|
||||
vi.spyOn(core, 'getInput').mockImplementation((name: string) => {
|
||||
if (name === 'percentage') return INVALID_LOW_PERCENTAGE.toString()
|
||||
return ''
|
||||
})
|
||||
@ -127,7 +130,7 @@ describe('Pod Canary Helper tests', () => {
|
||||
})
|
||||
|
||||
test('should throw error for invalid high percentage', async () => {
|
||||
jest.spyOn(core, 'getInput').mockImplementation((name: string) => {
|
||||
vi.spyOn(core, 'getInput').mockImplementation((name: string) => {
|
||||
if (name === 'percentage') return INVALID_HIGH_PERCENTAGE.toString()
|
||||
return ''
|
||||
})
|
||||
@ -143,7 +146,7 @@ describe('Pod Canary Helper tests', () => {
|
||||
kubectlApplySpy.mockResolvedValue(mockSuccessResult)
|
||||
|
||||
// Test minimum valid percentage
|
||||
jest.spyOn(core, 'getInput').mockImplementation((name: string) => {
|
||||
vi.spyOn(core, 'getInput').mockImplementation((name: string) => {
|
||||
if (name === 'percentage') return MIN_PERCENTAGE.toString()
|
||||
return ''
|
||||
})
|
||||
@ -152,7 +155,7 @@ describe('Pod Canary Helper tests', () => {
|
||||
expect(resultMin.execResult).toEqual(mockSuccessResult)
|
||||
|
||||
// Test maximum valid percentage
|
||||
jest.spyOn(core, 'getInput').mockImplementation((name: string) => {
|
||||
vi.spyOn(core, 'getInput').mockImplementation((name: string) => {
|
||||
if (name === 'percentage') return MAX_PERCENTAGE.toString()
|
||||
return ''
|
||||
})
|
||||
@ -162,7 +165,7 @@ describe('Pod Canary Helper tests', () => {
|
||||
})
|
||||
|
||||
test('should handle force deployment option', async () => {
|
||||
jest.spyOn(core, 'getInput').mockImplementation((name: string) => {
|
||||
vi.spyOn(core, 'getInput').mockImplementation((name: string) => {
|
||||
switch (name) {
|
||||
case 'percentage':
|
||||
return VALID_PERCENTAGE.toString()
|
||||
@ -186,7 +189,7 @@ describe('Pod Canary Helper tests', () => {
|
||||
})
|
||||
|
||||
test('should handle server-side apply option', async () => {
|
||||
jest.spyOn(core, 'getInput').mockImplementation((name: string) => {
|
||||
vi.spyOn(core, 'getInput').mockImplementation((name: string) => {
|
||||
switch (name) {
|
||||
case 'percentage':
|
||||
return VALID_PERCENTAGE.toString()
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
import {Kubectl} from '../../types/kubectl'
|
||||
import {Kubectl} from '../../types/kubectl.js'
|
||||
import * as core from '@actions/core'
|
||||
import * as fs from 'fs'
|
||||
import * as yaml from 'js-yaml'
|
||||
|
||||
import * as fileHelper from '../../utilities/fileUtils'
|
||||
import * as canaryDeploymentHelper from './canaryHelper'
|
||||
import {isDeploymentEntity} from '../../types/kubernetesTypes'
|
||||
import {getReplicaCount} from '../../utilities/manifestUpdateUtils'
|
||||
import {DeployResult} from '../../types/deployResult'
|
||||
import {K8sObject} from '../../types/k8sObject'
|
||||
import {checkForErrors} from '../../utilities/kubectlUtils'
|
||||
import * as fileHelper from '../../utilities/fileUtils.js'
|
||||
import * as canaryDeploymentHelper from './canaryHelper.js'
|
||||
import {isDeploymentEntity} from '../../types/kubernetesTypes.js'
|
||||
import {getReplicaCount} from '../../utilities/manifestUpdateUtils.js'
|
||||
import {DeployResult} from '../../types/deployResult.js'
|
||||
import {K8sObject} from '../../types/k8sObject.js'
|
||||
import {checkForErrors} from '../../utilities/kubectlUtils.js'
|
||||
|
||||
export async function deployPodCanary(
|
||||
filePaths: string[],
|
||||
|
||||
@ -1,13 +1,34 @@
|
||||
import {vi} from 'vitest'
|
||||
import type {MockInstance} from 'vitest'
|
||||
vi.mock('@actions/core', async (importOriginal) => {
|
||||
const actual: any = await importOriginal()
|
||||
return {
|
||||
...actual,
|
||||
getInput: vi.fn().mockReturnValue(''),
|
||||
debug: vi.fn(),
|
||||
info: vi.fn(),
|
||||
warning: vi.fn(),
|
||||
error: vi.fn(),
|
||||
setFailed: vi.fn(),
|
||||
setOutput: vi.fn(),
|
||||
group: vi
|
||||
.fn()
|
||||
.mockImplementation(
|
||||
async (_name: string, fn: () => Promise<void>) => await fn()
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
import * as core from '@actions/core'
|
||||
import * as fs from 'fs'
|
||||
import {Kubectl} from '../../types/kubectl'
|
||||
import {Kubectl} from '../../types/kubectl.js'
|
||||
import {
|
||||
deploySMICanary,
|
||||
redirectTrafficToCanaryDeployment,
|
||||
redirectTrafficToStableDeployment
|
||||
} from './smiCanaryHelper'
|
||||
} from './smiCanaryHelper.js'
|
||||
|
||||
jest.mock('../../types/kubectl')
|
||||
vi.mock('../../types/kubectl')
|
||||
|
||||
const kc = new Kubectl('')
|
||||
|
||||
@ -40,22 +61,21 @@ const TIMEOUT_240S = '240s'
|
||||
|
||||
describe('SMI Canary Helper tests', () => {
|
||||
let mockFilePaths: string[]
|
||||
let kubectlApplySpy: jest.SpyInstance
|
||||
let kubectlExecuteCommandSpy: jest.SpyInstance
|
||||
let kubectlApplySpy: MockInstance
|
||||
let kubectlExecuteCommandSpy: MockInstance
|
||||
|
||||
beforeEach(() => {
|
||||
//@ts-ignore
|
||||
Kubectl.mockClear()
|
||||
jest.restoreAllMocks()
|
||||
vi.mocked(Kubectl).mockClear()
|
||||
vi.restoreAllMocks()
|
||||
|
||||
mockFilePaths = testManifestFiles
|
||||
kubectlApplySpy = jest.spyOn(kc, 'apply')
|
||||
kubectlExecuteCommandSpy = jest
|
||||
kubectlApplySpy = vi.spyOn(kc, 'apply')
|
||||
kubectlExecuteCommandSpy = vi
|
||||
.spyOn(kc, 'executeCommand')
|
||||
.mockResolvedValue(mockExecuteCommandResult)
|
||||
|
||||
// Mock core.getInput with default values
|
||||
jest.spyOn(core, 'getInput').mockImplementation((name: string) => {
|
||||
vi.spyOn(core, 'getInput').mockImplementation((name: string) => {
|
||||
switch (name) {
|
||||
case 'percentage':
|
||||
return '50'
|
||||
@ -72,7 +92,7 @@ describe('SMI Canary Helper tests', () => {
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks()
|
||||
vi.restoreAllMocks()
|
||||
kubectlApplySpy.mockClear()
|
||||
})
|
||||
|
||||
@ -106,7 +126,7 @@ describe('SMI Canary Helper tests', () => {
|
||||
})
|
||||
|
||||
test('should handle custom replica count from input', async () => {
|
||||
jest.spyOn(core, 'getInput').mockImplementation((name: string) => {
|
||||
vi.spyOn(core, 'getInput').mockImplementation((name: string) => {
|
||||
switch (name) {
|
||||
case 'baseline-and-canary-replicas':
|
||||
return VALID_REPLICA_COUNT.toString()
|
||||
|
||||
@ -1,17 +1,20 @@
|
||||
import {Kubectl} from '../../types/kubectl'
|
||||
import {Kubectl} from '../../types/kubectl.js'
|
||||
import * as core from '@actions/core'
|
||||
import * as fs from 'fs'
|
||||
import * as yaml from 'js-yaml'
|
||||
|
||||
import * as fileHelper from '../../utilities/fileUtils'
|
||||
import * as kubectlUtils from '../../utilities/trafficSplitUtils'
|
||||
import * as canaryDeploymentHelper from './canaryHelper'
|
||||
import * as podCanaryHelper from './podCanaryHelper'
|
||||
import {isDeploymentEntity, isServiceEntity} from '../../types/kubernetesTypes'
|
||||
import {checkForErrors} from '../../utilities/kubectlUtils'
|
||||
import {inputAnnotations} from '../../inputUtils'
|
||||
import {DeployResult} from '../../types/deployResult'
|
||||
import {K8sObject} from '../../types/k8sObject'
|
||||
import * as fileHelper from '../../utilities/fileUtils.js'
|
||||
import * as kubectlUtils from '../../utilities/trafficSplitUtils.js'
|
||||
import * as canaryDeploymentHelper from './canaryHelper.js'
|
||||
import * as podCanaryHelper from './podCanaryHelper.js'
|
||||
import {
|
||||
isDeploymentEntity,
|
||||
isServiceEntity
|
||||
} from '../../types/kubernetesTypes.js'
|
||||
import {checkForErrors} from '../../utilities/kubectlUtils.js'
|
||||
import {inputAnnotations} from '../../inputUtils.js'
|
||||
import {DeployResult} from '../../types/deployResult.js'
|
||||
import {K8sObject} from '../../types/k8sObject.js'
|
||||
|
||||
const TRAFFIC_SPLIT_OBJECT_NAME_SUFFIX = '-workflow-rollout'
|
||||
const TRAFFIC_SPLIT_OBJECT = 'TrafficSplit'
|
||||
|
||||
@ -1,41 +1,41 @@
|
||||
import * as fs from 'fs'
|
||||
import * as yaml from 'js-yaml'
|
||||
import * as canaryDeploymentHelper from './canary/canaryHelper'
|
||||
import * as models from '../types/kubernetesTypes'
|
||||
import {isDeploymentEntity} from '../types/kubernetesTypes'
|
||||
import * as fileHelper from '../utilities/fileUtils'
|
||||
import * as KubernetesManifestUtility from '../utilities/manifestStabilityUtils'
|
||||
import {Kubectl, Resource} from '../types/kubectl'
|
||||
import * as canaryDeploymentHelper from './canary/canaryHelper.js'
|
||||
import * as models from '../types/kubernetesTypes.js'
|
||||
import {isDeploymentEntity} from '../types/kubernetesTypes.js'
|
||||
import * as fileHelper from '../utilities/fileUtils.js'
|
||||
import * as KubernetesManifestUtility from '../utilities/manifestStabilityUtils.js'
|
||||
import {Kubectl, Resource} from '../types/kubectl.js'
|
||||
|
||||
import {deployPodCanary} from './canary/podCanaryHelper'
|
||||
import {deploySMICanary} from './canary/smiCanaryHelper'
|
||||
import {DeploymentConfig} from '../types/deploymentConfig'
|
||||
import {deployBlueGreen} from './blueGreen/deploy'
|
||||
import {DeploymentStrategy} from '../types/deploymentStrategy'
|
||||
import {deployPodCanary} from './canary/podCanaryHelper.js'
|
||||
import {deploySMICanary} from './canary/smiCanaryHelper.js'
|
||||
import {DeploymentConfig} from '../types/deploymentConfig.js'
|
||||
import {deployBlueGreen} from './blueGreen/deploy.js'
|
||||
import {DeploymentStrategy} from '../types/deploymentStrategy.js'
|
||||
import * as core from '@actions/core'
|
||||
import {
|
||||
parseTrafficSplitMethod,
|
||||
TrafficSplitMethod
|
||||
} from '../types/trafficSplitMethod'
|
||||
import {parseRouteStrategy} from '../types/routeStrategy'
|
||||
} from '../types/trafficSplitMethod.js'
|
||||
import {parseRouteStrategy} from '../types/routeStrategy.js'
|
||||
import {ExecOutput} from '@actions/exec'
|
||||
import {
|
||||
getWorkflowAnnotationKeyLabel,
|
||||
getWorkflowAnnotations,
|
||||
cleanLabel
|
||||
} from '../utilities/workflowAnnotationUtils'
|
||||
} from '../utilities/workflowAnnotationUtils.js'
|
||||
import {
|
||||
annotateChildPods,
|
||||
checkForErrors,
|
||||
getLastSuccessfulRunSha
|
||||
} from '../utilities/kubectlUtils'
|
||||
} from '../utilities/kubectlUtils.js'
|
||||
import {
|
||||
getWorkflowFilePath,
|
||||
normalizeWorkflowStrLabel
|
||||
} from '../utilities/githubUtils'
|
||||
import {getDeploymentConfig} from '../utilities/dockerUtils'
|
||||
import {DeployResult} from '../types/deployResult'
|
||||
import {ClusterType} from '../inputUtils'
|
||||
} from '../utilities/githubUtils.js'
|
||||
import {getDeploymentConfig} from '../utilities/dockerUtils.js'
|
||||
import {DeployResult} from '../types/deployResult.js'
|
||||
import {ClusterType} from '../inputUtils.js'
|
||||
|
||||
export async function deployManifests(
|
||||
files: string[],
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import {Action, parseAction} from './action'
|
||||
import {Action, parseAction} from './action.js'
|
||||
|
||||
describe('Action type', () => {
|
||||
test('it has required values', () => {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import {DeployResult} from './deployResult'
|
||||
import {K8sObject, K8sDeleteObject} from './k8sObject'
|
||||
import {DeployResult} from './deployResult.js'
|
||||
import {K8sObject, K8sDeleteObject} from './k8sObject.js'
|
||||
|
||||
export interface BlueGreenDeployment {
|
||||
deployResult: DeployResult
|
||||
|
||||
@ -1,4 +1,7 @@
|
||||
import {DeploymentStrategy, parseDeploymentStrategy} from './deploymentStrategy'
|
||||
import {
|
||||
DeploymentStrategy,
|
||||
parseDeploymentStrategy
|
||||
} from './deploymentStrategy.js'
|
||||
|
||||
describe('Deployment strategy type', () => {
|
||||
test('it has required values', () => {
|
||||
|
||||
@ -1,4 +1,7 @@
|
||||
import {DockerExec} from './docker'
|
||||
import {vi} from 'vitest'
|
||||
vi.mock('@actions/exec')
|
||||
|
||||
import {DockerExec} from './docker.js'
|
||||
import * as actions from '@actions/exec'
|
||||
|
||||
const dockerPath = 'dockerPath'
|
||||
@ -12,7 +15,7 @@ describe('Docker class', () => {
|
||||
const execReturn = {exitCode: 0, stdout: 'Output', stderr: ''}
|
||||
|
||||
beforeEach(() => {
|
||||
jest.spyOn(actions, 'getExecOutput').mockImplementation(async () => {
|
||||
vi.spyOn(actions, 'getExecOutput').mockImplementation(async () => {
|
||||
return execReturn
|
||||
})
|
||||
})
|
||||
@ -60,7 +63,7 @@ describe('Docker class', () => {
|
||||
const execReturn = {exitCode: 3, stdout: '', stderr: ''}
|
||||
|
||||
beforeEach(() => {
|
||||
jest.spyOn(actions, 'getExecOutput').mockImplementation(async () => {
|
||||
vi.spyOn(actions, 'getExecOutput').mockImplementation(async () => {
|
||||
return execReturn
|
||||
})
|
||||
})
|
||||
@ -80,7 +83,7 @@ describe('Docker class', () => {
|
||||
const execReturn = {exitCode: 0, stdout: '', stderr: 'Output'}
|
||||
|
||||
beforeEach(() => {
|
||||
jest.spyOn(actions, 'getExecOutput').mockImplementation(async () => {
|
||||
vi.spyOn(actions, 'getExecOutput').mockImplementation(async () => {
|
||||
return execReturn
|
||||
})
|
||||
})
|
||||
|
||||
@ -1,4 +1,10 @@
|
||||
import {getKubectlPath, Kubectl} from './kubectl'
|
||||
import {vi} from 'vitest'
|
||||
vi.mock('@actions/exec')
|
||||
vi.mock('@actions/io')
|
||||
vi.mock('@actions/core')
|
||||
vi.mock('@actions/tool-cache')
|
||||
|
||||
import {getKubectlPath, Kubectl} from './kubectl.js'
|
||||
import * as exec from '@actions/exec'
|
||||
import * as io from '@actions/io'
|
||||
import * as core from '@actions/core'
|
||||
@ -9,27 +15,27 @@ describe('Kubectl path', () => {
|
||||
const path = 'path'
|
||||
|
||||
it('gets the kubectl path', async () => {
|
||||
jest.spyOn(core, 'getInput').mockImplementationOnce(() => '')
|
||||
jest.spyOn(io, 'which').mockImplementationOnce(async () => path)
|
||||
vi.spyOn(core, 'getInput').mockImplementationOnce(() => '')
|
||||
vi.spyOn(io, 'which').mockImplementationOnce(async () => path)
|
||||
|
||||
expect(await getKubectlPath()).toBe(path)
|
||||
})
|
||||
|
||||
it('gets the kubectl path with version', async () => {
|
||||
jest.spyOn(core, 'getInput').mockImplementationOnce(() => version)
|
||||
jest.spyOn(toolCache, 'find').mockImplementationOnce(() => path)
|
||||
vi.spyOn(core, 'getInput').mockImplementationOnce(() => version)
|
||||
vi.spyOn(toolCache, 'find').mockImplementationOnce(() => path)
|
||||
|
||||
expect(await getKubectlPath()).toBe(path)
|
||||
})
|
||||
|
||||
it('throws if kubectl not found', async () => {
|
||||
// without version
|
||||
jest.spyOn(io, 'which').mockImplementationOnce(async () => '')
|
||||
vi.spyOn(io, 'which').mockImplementationOnce(async () => '')
|
||||
await expect(() => getKubectlPath()).rejects.toThrow()
|
||||
|
||||
// with verision
|
||||
jest.spyOn(core, 'getInput').mockImplementationOnce(() => '')
|
||||
jest.spyOn(io, 'which').mockImplementationOnce(async () => '')
|
||||
vi.spyOn(core, 'getInput').mockImplementationOnce(() => '')
|
||||
vi.spyOn(io, 'which').mockImplementationOnce(async () => '')
|
||||
await expect(() => getKubectlPath()).rejects.toThrow()
|
||||
})
|
||||
})
|
||||
@ -46,7 +52,7 @@ describe('Kubectl class', () => {
|
||||
const mockExecReturn = {exitCode: 0, stdout: 'Output', stderr: ''}
|
||||
|
||||
beforeEach(() => {
|
||||
jest.spyOn(exec, 'getExecOutput').mockImplementation(async () => {
|
||||
vi.spyOn(exec, 'getExecOutput').mockImplementation(async () => {
|
||||
return mockExecReturn
|
||||
})
|
||||
})
|
||||
@ -637,7 +643,7 @@ describe('Kubectl class', () => {
|
||||
stderr: ''
|
||||
}
|
||||
|
||||
jest.spyOn(exec, 'getExecOutput').mockImplementationOnce(async () => {
|
||||
vi.spyOn(exec, 'getExecOutput').mockImplementationOnce(async () => {
|
||||
return describeReturn
|
||||
})
|
||||
|
||||
@ -650,7 +656,7 @@ describe('Kubectl class', () => {
|
||||
const skipTls = true
|
||||
const kubectl = new Kubectl(kubectlPath, testNamespace, skipTls)
|
||||
|
||||
jest.spyOn(exec, 'getExecOutput').mockImplementation(async () => {
|
||||
vi.spyOn(exec, 'getExecOutput').mockImplementation(async () => {
|
||||
return {exitCode: 0, stderr: '', stdout: ''}
|
||||
})
|
||||
|
||||
@ -677,7 +683,7 @@ describe('Kubectl namespace handling', () => {
|
||||
const execReturn = {exitCode: 0, stdout: 'Output', stderr: ''}
|
||||
|
||||
beforeEach(() => {
|
||||
jest.spyOn(exec, 'getExecOutput').mockResolvedValue(execReturn)
|
||||
vi.spyOn(exec, 'getExecOutput').mockResolvedValue(execReturn)
|
||||
})
|
||||
|
||||
const runApply = async (namespace?: string) => {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import {ExecOutput, getExecOutput} from '@actions/exec'
|
||||
import {createInlineArray} from '../utilities/arrayUtils'
|
||||
import {createInlineArray} from '../utilities/arrayUtils.js'
|
||||
import * as core from '@actions/core'
|
||||
import * as toolCache from '@actions/tool-cache'
|
||||
import * as io from '@actions/io'
|
||||
|
||||
@ -10,7 +10,7 @@ import {
|
||||
ServiceTypes,
|
||||
WORKLOAD_TYPES,
|
||||
WORKLOAD_TYPES_WITH_ROLLOUT_STATUS
|
||||
} from './kubernetesTypes'
|
||||
} from './kubernetesTypes.js'
|
||||
|
||||
describe('Kubernetes types', () => {
|
||||
it('contains kubernetes workloads', () => {
|
||||
|
||||
@ -1,10 +1,13 @@
|
||||
import * as fileUtils from '../utilities/fileUtils'
|
||||
import {vi} from 'vitest'
|
||||
vi.mock('@actions/exec')
|
||||
|
||||
import * as fileUtils from '../utilities/fileUtils.js'
|
||||
import fs from 'node:fs'
|
||||
import {
|
||||
PrivateKubectl,
|
||||
extractFileNames,
|
||||
replaceFileNamesWithShallowNamesRelativeToTemp
|
||||
} from './privatekubectl'
|
||||
} from './privatekubectl.js'
|
||||
import * as exec from '@actions/exec'
|
||||
|
||||
describe('Private kubectl', () => {
|
||||
@ -17,14 +20,14 @@ describe('Private kubectl', () => {
|
||||
'resourceName'
|
||||
)
|
||||
|
||||
const spy = jest
|
||||
const spy = vi
|
||||
.spyOn(fileUtils, 'getTempDirectory')
|
||||
.mockImplementation(() => {
|
||||
return '/tmp'
|
||||
})
|
||||
|
||||
jest.spyOn(fs, 'writeFileSync').mockImplementation(() => {})
|
||||
jest.spyOn(fs, 'readFileSync').mockImplementation((filename) => {
|
||||
vi.spyOn(fs, 'writeFileSync').mockImplementation(() => {})
|
||||
vi.spyOn(fs, 'readFileSync').mockImplementation((filename) => {
|
||||
return 'test contents'
|
||||
})
|
||||
|
||||
@ -48,7 +51,7 @@ describe('Private kubectl', () => {
|
||||
|
||||
test('Should throw well defined Error on error from Azure', async () => {
|
||||
const errorMsg = 'An error message'
|
||||
jest.spyOn(exec, 'getExecOutput').mockImplementation(async () => {
|
||||
vi.spyOn(exec, 'getExecOutput').mockImplementation(async () => {
|
||||
return {exitCode: 1, stdout: '', stderr: errorMsg}
|
||||
})
|
||||
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import {Kubectl} from './kubectl'
|
||||
import {Kubectl} from './kubectl.js'
|
||||
import minimist from 'minimist'
|
||||
import {ExecOptions, ExecOutput, getExecOutput} from '@actions/exec'
|
||||
import * as core from '@actions/core'
|
||||
import fs from 'node:fs'
|
||||
import * as path from 'path'
|
||||
import {getTempDirectory} from '../utilities/fileUtils'
|
||||
import {getTempDirectory} from '../utilities/fileUtils.js'
|
||||
|
||||
export class PrivateKubectl extends Kubectl {
|
||||
protected async execute(args: string[], silent: boolean = false) {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import {parseRouteStrategy, RouteStrategy} from './routeStrategy'
|
||||
import {parseRouteStrategy, RouteStrategy} from './routeStrategy.js'
|
||||
|
||||
describe('Route strategy type', () => {
|
||||
test('it has required values', () => {
|
||||
|
||||
@ -1,4 +1,7 @@
|
||||
import {parseTrafficSplitMethod, TrafficSplitMethod} from './trafficSplitMethod'
|
||||
import {
|
||||
parseTrafficSplitMethod,
|
||||
TrafficSplitMethod
|
||||
} from './trafficSplitMethod.js'
|
||||
|
||||
describe('Traffic split method type', () => {
|
||||
test('it has required values', () => {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import {createInlineArray} from './arrayUtils'
|
||||
import {createInlineArray} from './arrayUtils.js'
|
||||
|
||||
describe('array utilities', () => {
|
||||
it('creates an inline array', () => {
|
||||
|
||||
@ -1,15 +1,18 @@
|
||||
import {vi} from 'vitest'
|
||||
vi.mock('@actions/io')
|
||||
|
||||
import * as io from '@actions/io'
|
||||
import {checkDockerPath} from './dockerUtils'
|
||||
import {checkDockerPath} from './dockerUtils.js'
|
||||
|
||||
describe('docker utilities', () => {
|
||||
it('checks if docker is installed', async () => {
|
||||
// docker installed
|
||||
const path = 'path'
|
||||
jest.spyOn(io, 'which').mockImplementationOnce(async () => path)
|
||||
vi.spyOn(io, 'which').mockImplementationOnce(async () => path)
|
||||
expect(() => checkDockerPath()).not.toThrow()
|
||||
|
||||
// docker not installed
|
||||
jest.spyOn(io, 'which').mockImplementationOnce(async () => {
|
||||
vi.spyOn(io, 'which').mockImplementationOnce(async () => {
|
||||
throw new Error('not found')
|
||||
})
|
||||
await expect(() => checkDockerPath()).rejects.toThrow()
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import * as io from '@actions/io'
|
||||
import {DeploymentConfig} from '../types/deploymentConfig'
|
||||
import {DeploymentConfig} from '../types/deploymentConfig.js'
|
||||
import * as core from '@actions/core'
|
||||
import {DockerExec} from '../types/docker'
|
||||
import {getNormalizedPath} from './githubUtils'
|
||||
import {DockerExec} from '../types/docker.js'
|
||||
import {getNormalizedPath} from './githubUtils.js'
|
||||
|
||||
export async function getDeploymentConfig(): Promise<DeploymentConfig> {
|
||||
let helmChartPaths: string[] =
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
import {parseDuration} from './durationUtils'
|
||||
import {vi, type Mocked} from 'vitest'
|
||||
import {parseDuration} from './durationUtils.js'
|
||||
import * as core from '@actions/core'
|
||||
|
||||
// Mock core.debug
|
||||
jest.mock('@actions/core')
|
||||
const mockCore = core as jest.Mocked<typeof core>
|
||||
vi.mock('@actions/core')
|
||||
const mockCore = core as Mocked<typeof core>
|
||||
|
||||
// Test data constants
|
||||
const VALID_TIMEOUTS = {
|
||||
@ -46,7 +47,7 @@ const expectInvalidTimeout = (input: string, expectedError: string) => {
|
||||
|
||||
describe('validateTimeoutDuration', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks()
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
describe('valid timeout formats', () => {
|
||||
@ -90,7 +91,7 @@ describe('validateTimeoutDuration', () => {
|
||||
'No unit specified for timeout "5", assuming minutes'
|
||||
)
|
||||
|
||||
jest.clearAllMocks()
|
||||
vi.clearAllMocks()
|
||||
|
||||
parseDuration('30s')
|
||||
expect(mockCore.debug).not.toHaveBeenCalled()
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
import * as fileUtils from './fileUtils'
|
||||
import {vi} from 'vitest'
|
||||
import * as fileUtils from './fileUtils.js'
|
||||
|
||||
import * as yaml from 'js-yaml'
|
||||
import fs from 'node:fs'
|
||||
import * as path from 'path'
|
||||
import {K8sObject} from '../types/k8sObject'
|
||||
import {K8sObject} from '../types/k8sObject.js'
|
||||
|
||||
const sampleYamlUrl =
|
||||
'https://raw.githubusercontent.com/kubernetes/website/main/content/en/examples/controllers/nginx-deployment.yaml'
|
||||
@ -69,7 +70,7 @@ describe('File utils', () => {
|
||||
'manifest_test_dir'
|
||||
)
|
||||
|
||||
expect(
|
||||
await expect(
|
||||
fileUtils.getFilesFromDirectoriesAndURLs([badPath, goodPath])
|
||||
).rejects.toThrow()
|
||||
})
|
||||
@ -108,8 +109,8 @@ describe('File utils', () => {
|
||||
|
||||
describe('moving files to temp', () => {
|
||||
it('correctly moves the contents of a file to the temporary directory', () => {
|
||||
jest.spyOn(fs, 'writeFileSync').mockImplementation(() => {})
|
||||
jest.spyOn(fs, 'readFileSync').mockImplementation((filename) => {
|
||||
vi.spyOn(fs, 'writeFileSync').mockImplementation(() => {})
|
||||
vi.spyOn(fs, 'readFileSync').mockImplementation((filename) => {
|
||||
return 'test contents'
|
||||
})
|
||||
const originalFilePath = path.join('path', 'in', 'repo')
|
||||
|
||||
@ -4,10 +4,10 @@ import * as path from 'path'
|
||||
import * as core from '@actions/core'
|
||||
import * as os from 'os'
|
||||
import * as yaml from 'js-yaml'
|
||||
import {Errorable, succeeded, failed, Failed} from '../types/errorable'
|
||||
import {getCurrentTime} from './timeUtils'
|
||||
import {isHttpUrl} from './githubUtils'
|
||||
import {K8sObject} from '../types/k8sObject'
|
||||
import {Errorable, succeeded, failed, Failed} from '../types/errorable.js'
|
||||
import {getCurrentTime} from './timeUtils.js'
|
||||
import {isHttpUrl} from './githubUtils.js'
|
||||
import {K8sObject} from '../types/k8sObject.js'
|
||||
|
||||
export const urlFileKind = 'urlfile'
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ import {
|
||||
getNormalizedPath,
|
||||
isHttpUrl,
|
||||
normalizeWorkflowStrLabel
|
||||
} from './githubUtils'
|
||||
} from './githubUtils.js'
|
||||
|
||||
describe('Github utils', () => {
|
||||
it('normalizes workflow string labels', () => {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import {GitHubClient, OkStatusCode} from '../types/githubClient'
|
||||
import {GitHubClient, OkStatusCode} from '../types/githubClient.js'
|
||||
import * as core from '@actions/core'
|
||||
|
||||
export async function getWorkflowFilePath(
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
import {vi} from 'vitest'
|
||||
vi.mock('@actions/core')
|
||||
|
||||
import * as core from '@actions/core'
|
||||
import {ExecOutput} from '@actions/exec'
|
||||
import {checkForErrors} from './kubectlUtils'
|
||||
import {checkForErrors} from './kubectlUtils.js'
|
||||
|
||||
describe('Kubectl utils', () => {
|
||||
it('checks for errors', () => {
|
||||
@ -39,7 +42,8 @@ describe('Kubectl utils', () => {
|
||||
).toThrow()
|
||||
|
||||
// with warn behavior
|
||||
jest.spyOn(core, 'warning').mockImplementation(() => {})
|
||||
const warnSpy = vi.spyOn(core, 'warning').mockImplementation(() => {})
|
||||
warnSpy.mockClear()
|
||||
let warningCalls = 0
|
||||
expect(() => checkForErrors([success], true)).not.toThrow()
|
||||
expect(core.warning).toHaveBeenCalledTimes(warningCalls)
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import * as core from '@actions/core'
|
||||
import {ExecOutput} from '@actions/exec'
|
||||
import {Kubectl} from '../types/kubectl'
|
||||
import {Kubectl} from '../types/kubectl.js'
|
||||
|
||||
const NAMESPACE = 'namespace'
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import {KubernetesWorkload} from '../types/kubernetesTypes'
|
||||
import {KubernetesWorkload} from '../types/kubernetesTypes.js'
|
||||
|
||||
export function getImagePullSecrets(inputObject: any) {
|
||||
const kind = inputObject?.kind?.toLowerCase()
|
||||
|
||||
@ -3,7 +3,7 @@ import {
|
||||
isServiceEntity,
|
||||
KubernetesWorkload,
|
||||
NullInputObjectError
|
||||
} from '../types/kubernetesTypes'
|
||||
} from '../types/kubernetesTypes.js'
|
||||
|
||||
export function updateSpecLabels(
|
||||
inputObject: any,
|
||||
|
||||
@ -1,10 +1,29 @@
|
||||
import * as manifestStabilityUtils from './manifestStabilityUtils'
|
||||
import {Kubectl} from '../types/kubectl'
|
||||
import {ResourceTypeFleet, ResourceTypeManagedCluster} from '../actions/deploy'
|
||||
import {vi} from 'vitest'
|
||||
import type {MockInstance} from 'vitest'
|
||||
vi.mock('@actions/core', async (importOriginal) => {
|
||||
const actual: any = await importOriginal()
|
||||
return {
|
||||
...actual,
|
||||
getInput: vi.fn().mockReturnValue(''),
|
||||
debug: vi.fn(),
|
||||
info: vi.fn(),
|
||||
warning: vi.fn(),
|
||||
error: vi.fn(),
|
||||
setFailed: vi.fn(),
|
||||
setOutput: vi.fn()
|
||||
}
|
||||
})
|
||||
|
||||
import * as manifestStabilityUtils from './manifestStabilityUtils.js'
|
||||
import {Kubectl} from '../types/kubectl.js'
|
||||
import {
|
||||
ResourceTypeFleet,
|
||||
ResourceTypeManagedCluster
|
||||
} from '../actions/deploy.js'
|
||||
import {ExecOutput} from '@actions/exec'
|
||||
import {exitCode, stdout} from 'process'
|
||||
import * as core from '@actions/core'
|
||||
import * as timeUtils from './timeUtils'
|
||||
import * as timeUtils from './timeUtils.js'
|
||||
|
||||
describe('manifestStabilityUtils', () => {
|
||||
const kc = new Kubectl('')
|
||||
@ -17,8 +36,8 @@ describe('manifestStabilityUtils', () => {
|
||||
]
|
||||
|
||||
it('should return immediately if the resource type is fleet', async () => {
|
||||
const spy = jest.spyOn(manifestStabilityUtils, 'checkManifestStability')
|
||||
const checkRolloutStatusSpy = jest.spyOn(kc, 'checkRolloutStatus')
|
||||
const spy = vi.spyOn(manifestStabilityUtils, 'checkManifestStability')
|
||||
const checkRolloutStatusSpy = vi.spyOn(kc, 'checkRolloutStatus')
|
||||
await manifestStabilityUtils.checkManifestStability(
|
||||
kc,
|
||||
resources,
|
||||
@ -30,8 +49,8 @@ describe('manifestStabilityUtils', () => {
|
||||
})
|
||||
|
||||
it('should run fully if the resource type is managedCluster', async () => {
|
||||
const spy = jest.spyOn(manifestStabilityUtils, 'checkManifestStability')
|
||||
const checkRolloutStatusSpy = jest
|
||||
const spy = vi.spyOn(manifestStabilityUtils, 'checkManifestStability')
|
||||
const checkRolloutStatusSpy = vi
|
||||
.spyOn(kc, 'checkRolloutStatus')
|
||||
.mockImplementation(() => {
|
||||
return new Promise<ExecOutput>((resolve, reject) => {
|
||||
@ -54,7 +73,7 @@ describe('manifestStabilityUtils', () => {
|
||||
|
||||
it('should pass timeout to checkRolloutStatus when provided', async () => {
|
||||
const timeout = '300s'
|
||||
const checkRolloutStatusSpy = jest
|
||||
const checkRolloutStatusSpy = vi
|
||||
.spyOn(kc, 'checkRolloutStatus')
|
||||
.mockImplementation(() => {
|
||||
return new Promise<ExecOutput>((resolve, reject) => {
|
||||
@ -82,7 +101,7 @@ describe('manifestStabilityUtils', () => {
|
||||
})
|
||||
|
||||
it('should call checkRolloutStatus without timeout when not provided', async () => {
|
||||
const checkRolloutStatusSpy = jest
|
||||
const checkRolloutStatusSpy = vi
|
||||
.spyOn(kc, 'checkRolloutStatus')
|
||||
.mockImplementation(() => {
|
||||
return new Promise<ExecOutput>((resolve, reject) => {
|
||||
@ -111,19 +130,19 @@ describe('manifestStabilityUtils', () => {
|
||||
|
||||
describe('checkManifestStability failure and resource-specific scenarios', () => {
|
||||
let kc: Kubectl
|
||||
let coreErrorSpy: jest.SpyInstance
|
||||
let coreInfoSpy: jest.SpyInstance
|
||||
let coreWarningSpy: jest.SpyInstance
|
||||
let coreErrorSpy: MockInstance
|
||||
let coreInfoSpy: MockInstance
|
||||
let coreWarningSpy: MockInstance
|
||||
|
||||
beforeEach(() => {
|
||||
kc = new Kubectl('', 'default')
|
||||
coreErrorSpy = jest.spyOn(core, 'error').mockImplementation()
|
||||
coreInfoSpy = jest.spyOn(core, 'info').mockImplementation()
|
||||
coreWarningSpy = jest.spyOn(core, 'warning').mockImplementation()
|
||||
coreErrorSpy = vi.spyOn(core, 'error').mockImplementation(() => {})
|
||||
coreInfoSpy = vi.spyOn(core, 'info').mockImplementation(() => {})
|
||||
coreWarningSpy = vi.spyOn(core, 'warning').mockImplementation(() => {})
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks()
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
it('should call describe and collect errors when a rollout fails', async () => {
|
||||
@ -135,10 +154,10 @@ describe('checkManifestStability failure and resource-specific scenarios', () =>
|
||||
'Events:\n Type\tReason\tMessage\n Normal\tScalingReplicaSet\tScaled up replica set failing-app-123 to 1'
|
||||
|
||||
// Arrange: Mock rollout to fail and describe to succeed
|
||||
const checkRolloutStatusSpy = jest
|
||||
const checkRolloutStatusSpy = vi
|
||||
.spyOn(kc, 'checkRolloutStatus')
|
||||
.mockRejectedValue(rolloutError)
|
||||
const describeSpy = jest.spyOn(kc, 'describe').mockResolvedValue({
|
||||
const describeSpy = vi.spyOn(kc, 'describe').mockResolvedValue({
|
||||
stdout: describeOutput,
|
||||
stderr: '',
|
||||
exitCode: 0
|
||||
@ -177,10 +196,10 @@ describe('checkManifestStability failure and resource-specific scenarios', () =>
|
||||
'Events:\n Type\tReason\tMessage\n Normal\tScalingReplicaSet\tScaled up replica set failing-app-123 to 1'
|
||||
|
||||
// Arrange: Mock rollout to fail and describe to succeed
|
||||
const checkRolloutStatusSpy = jest
|
||||
const checkRolloutStatusSpy = vi
|
||||
.spyOn(kc, 'checkRolloutStatus')
|
||||
.mockRejectedValue(rolloutError)
|
||||
const describeSpy = jest.spyOn(kc, 'describe').mockResolvedValue({
|
||||
const describeSpy = vi.spyOn(kc, 'describe').mockResolvedValue({
|
||||
stdout: describeOutput,
|
||||
stderr: '',
|
||||
exitCode: 0
|
||||
@ -216,10 +235,10 @@ describe('checkManifestStability failure and resource-specific scenarios', () =>
|
||||
const resources = [{type: 'Pod', name: 'test-pod', namespace: 'default'}]
|
||||
|
||||
// Arrange: Spy on checkPodStatus and checkRolloutStatus
|
||||
const checkPodStatusSpy = jest
|
||||
const checkPodStatusSpy = vi
|
||||
.spyOn(manifestStabilityUtils, 'checkPodStatus')
|
||||
.mockResolvedValue() // Assume pod becomes ready
|
||||
const checkRolloutStatusSpy = jest.spyOn(kc, 'checkRolloutStatus')
|
||||
const checkRolloutStatusSpy = vi.spyOn(kc, 'checkRolloutStatus')
|
||||
|
||||
// Act
|
||||
await manifestStabilityUtils.checkManifestStability(
|
||||
@ -240,10 +259,10 @@ describe('checkManifestStability failure and resource-specific scenarios', () =>
|
||||
const podError = new Error('Pod rollout failed')
|
||||
|
||||
// Arrange: Mock checkPodStatus to fail
|
||||
const checkPodStatusSpy = jest
|
||||
const checkPodStatusSpy = vi
|
||||
.spyOn(manifestStabilityUtils, 'checkPodStatus')
|
||||
.mockRejectedValue(podError)
|
||||
const describeSpy = jest.spyOn(kc, 'describe').mockResolvedValue({
|
||||
const describeSpy = vi.spyOn(kc, 'describe').mockResolvedValue({
|
||||
stdout: 'describe output',
|
||||
stderr: '',
|
||||
exitCode: 0
|
||||
@ -271,7 +290,7 @@ describe('checkManifestStability failure and resource-specific scenarios', () =>
|
||||
|
||||
it('should wait for external IP for a LoadBalancer service', async () => {
|
||||
//Spying on sleep to avoid actual delays in tests
|
||||
jest.spyOn(timeUtils, 'sleep').mockResolvedValue(undefined)
|
||||
vi.spyOn(timeUtils, 'sleep').mockResolvedValue(undefined)
|
||||
const resources = [
|
||||
{type: 'service', name: 'test-svc', namespace: 'default'}
|
||||
]
|
||||
@ -285,7 +304,7 @@ describe('checkManifestStability failure and resource-specific scenarios', () =>
|
||||
}
|
||||
|
||||
// Arrange: Mock getResource to simulate the IP being assigned on the second poll
|
||||
const getResourceSpy = jest
|
||||
const getResourceSpy = vi
|
||||
.spyOn(kc, 'getResource')
|
||||
// First call: Initial service check
|
||||
.mockResolvedValueOnce({
|
||||
@ -328,10 +347,10 @@ describe('checkManifestStability failure and resource-specific scenarios', () =>
|
||||
|
||||
// Arrange: Mock getService to fail, and describe to succeed
|
||||
// Note: We mock getResource because getService is a private helper
|
||||
const getResourceSpy = jest
|
||||
const getResourceSpy = vi
|
||||
.spyOn(kc, 'getResource')
|
||||
.mockRejectedValue(getServiceError)
|
||||
const describeSpy = jest.spyOn(kc, 'describe').mockResolvedValue({
|
||||
const describeSpy = vi.spyOn(kc, 'describe').mockResolvedValue({
|
||||
stdout: 'describe output',
|
||||
stderr: '',
|
||||
exitCode: 0
|
||||
@ -369,7 +388,7 @@ describe('checkManifestStability failure and resource-specific scenarios', () =>
|
||||
}
|
||||
|
||||
// Arrange
|
||||
const getResourceSpy = jest.spyOn(kc, 'getResource').mockResolvedValue({
|
||||
const getResourceSpy = vi.spyOn(kc, 'getResource').mockResolvedValue({
|
||||
stdout: JSON.stringify(clusterIpService),
|
||||
stderr: '',
|
||||
exitCode: 0
|
||||
@ -392,19 +411,19 @@ describe('checkManifestStability failure and resource-specific scenarios', () =>
|
||||
|
||||
describe('checkManifestStability additional scenarios', () => {
|
||||
let kc: Kubectl
|
||||
let coreErrorSpy: jest.SpyInstance
|
||||
let coreInfoSpy: jest.SpyInstance
|
||||
let coreWarningSpy: jest.SpyInstance
|
||||
let coreErrorSpy: MockInstance
|
||||
let coreInfoSpy: MockInstance
|
||||
let coreWarningSpy: MockInstance
|
||||
|
||||
beforeEach(() => {
|
||||
kc = new Kubectl('')
|
||||
coreErrorSpy = jest.spyOn(core, 'error').mockImplementation()
|
||||
coreInfoSpy = jest.spyOn(core, 'info').mockImplementation()
|
||||
coreWarningSpy = jest.spyOn(core, 'warning').mockImplementation()
|
||||
coreErrorSpy = vi.spyOn(core, 'error').mockImplementation(() => {})
|
||||
coreInfoSpy = vi.spyOn(core, 'info').mockImplementation(() => {})
|
||||
coreWarningSpy = vi.spyOn(core, 'warning').mockImplementation(() => {})
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks()
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
it('should aggregate errors from deployment and pod failures', async () => {
|
||||
@ -416,15 +435,15 @@ describe('checkManifestStability additional scenarios', () => {
|
||||
const podError = new Error('Pod not ready in time')
|
||||
|
||||
// Arrange: Mock failures
|
||||
const checkRolloutStatusSpy = jest
|
||||
const checkRolloutStatusSpy = vi
|
||||
.spyOn(kc, 'checkRolloutStatus')
|
||||
.mockRejectedValue(deploymentError)
|
||||
// For pod: simulate a pod check failure
|
||||
const checkPodStatusSpy = jest
|
||||
const checkPodStatusSpy = vi
|
||||
.spyOn(manifestStabilityUtils, 'checkPodStatus')
|
||||
.mockRejectedValue(podError)
|
||||
// For both, simulate a successful describe call to provide additional details
|
||||
const describeSpy = jest.spyOn(kc, 'describe').mockResolvedValue({
|
||||
const describeSpy = vi.spyOn(kc, 'describe').mockResolvedValue({
|
||||
stdout: 'describe aggregated output',
|
||||
stderr: '',
|
||||
exitCode: 0
|
||||
@ -463,25 +482,25 @@ describe('checkManifestStability additional scenarios', () => {
|
||||
|
||||
// Arrange:
|
||||
// Deployment rollout succeeds
|
||||
jest.spyOn(kc, 'checkRolloutStatus').mockResolvedValue({
|
||||
vi.spyOn(kc, 'checkRolloutStatus').mockResolvedValue({
|
||||
exitCode: 0,
|
||||
stderr: '',
|
||||
stdout: ''
|
||||
})
|
||||
// Pod becomes ready
|
||||
jest.spyOn(manifestStabilityUtils, 'checkPodStatus').mockResolvedValue()
|
||||
vi.spyOn(manifestStabilityUtils, 'checkPodStatus').mockResolvedValue()
|
||||
// Simulate a LoadBalancer service that already has an external IP
|
||||
const stableService = {
|
||||
spec: {type: 'LoadBalancer'},
|
||||
status: {loadBalancer: {ingress: [{ip: '1.2.3.4'}]}}
|
||||
}
|
||||
jest.spyOn(kc, 'getResource').mockResolvedValue({
|
||||
vi.spyOn(kc, 'getResource').mockResolvedValue({
|
||||
stdout: JSON.stringify(stableService),
|
||||
stderr: '',
|
||||
exitCode: 0
|
||||
})
|
||||
// Provide a describe result to avoid warnings
|
||||
jest.spyOn(kc, 'describe').mockResolvedValue({
|
||||
vi.spyOn(kc, 'describe').mockResolvedValue({
|
||||
stdout: 'describe output stable',
|
||||
stderr: '',
|
||||
exitCode: 0
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as KubernetesConstants from '../types/kubernetesTypes'
|
||||
import {Kubectl, Resource} from '../types/kubectl'
|
||||
import {checkForErrors} from './kubectlUtils'
|
||||
import {sleep} from './timeUtils'
|
||||
import {ResourceTypeFleet} from '../actions/deploy'
|
||||
import {ClusterType} from '../inputUtils'
|
||||
import * as KubernetesConstants from '../types/kubernetesTypes.js'
|
||||
import {Kubectl, Resource} from '../types/kubectl.js'
|
||||
import {checkForErrors} from './kubectlUtils.js'
|
||||
import {sleep} from './timeUtils.js'
|
||||
import {ResourceTypeFleet} from '../actions/deploy.js'
|
||||
import {ClusterType} from '../inputUtils.js'
|
||||
|
||||
const IS_SILENT = false
|
||||
const POD = 'pod'
|
||||
|
||||
@ -1,14 +1,17 @@
|
||||
import * as fileUtils from './fileUtils'
|
||||
import * as manifestUpdateUtils from './manifestUpdateUtils'
|
||||
import {vi} from 'vitest'
|
||||
vi.mock('fs')
|
||||
|
||||
import * as fileUtils from './fileUtils.js'
|
||||
import * as manifestUpdateUtils from './manifestUpdateUtils.js'
|
||||
import * as path from 'path'
|
||||
import * as fs from 'fs'
|
||||
|
||||
describe('manifestUpdateUtils', () => {
|
||||
jest.spyOn(fileUtils, 'moveFileToTmpDir').mockImplementation((filename) => {
|
||||
vi.spyOn(fileUtils, 'moveFileToTmpDir').mockImplementation((filename) => {
|
||||
return path.join('/tmp', filename)
|
||||
})
|
||||
jest.spyOn(fs, 'writeFileSync').mockImplementation(() => {})
|
||||
jest.spyOn(fs, 'readFileSync').mockImplementation((filename) => {
|
||||
vi.spyOn(fs, 'writeFileSync').mockImplementation(() => {})
|
||||
vi.spyOn(fs, 'readFileSync').mockImplementation((filename) => {
|
||||
return 'test contents'
|
||||
})
|
||||
|
||||
|
||||
@ -2,25 +2,25 @@ import * as core from '@actions/core'
|
||||
import * as fs from 'fs'
|
||||
import * as yaml from 'js-yaml'
|
||||
import * as path from 'path'
|
||||
import * as fileHelper from './fileUtils'
|
||||
import {moveFileToTmpDir} from './fileUtils'
|
||||
import * as fileHelper from './fileUtils.js'
|
||||
import {moveFileToTmpDir} from './fileUtils.js'
|
||||
import {
|
||||
InputObjectKindNotDefinedError,
|
||||
InputObjectMetadataNotDefinedError,
|
||||
isWorkloadEntity,
|
||||
KubernetesWorkload,
|
||||
NullInputObjectError
|
||||
} from '../types/kubernetesTypes'
|
||||
} from '../types/kubernetesTypes.js'
|
||||
import {
|
||||
getSpecSelectorLabels,
|
||||
setSpecSelectorLabels
|
||||
} from './manifestSpecLabelUtils'
|
||||
} from './manifestSpecLabelUtils.js'
|
||||
import {
|
||||
getImagePullSecrets,
|
||||
setImagePullSecrets
|
||||
} from './manifestPullSecretUtils'
|
||||
import {Resource} from '../types/kubectl'
|
||||
import {K8sObject} from '../types/k8sObject'
|
||||
} from './manifestPullSecretUtils.js'
|
||||
import {Resource} from '../types/kubectl.js'
|
||||
import {K8sObject} from '../types/k8sObject.js'
|
||||
|
||||
export function updateManifestFiles(manifestFilePaths: string[]) {
|
||||
if (manifestFilePaths?.length === 0) {
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
import {
|
||||
getImagePullSecrets,
|
||||
setImagePullSecrets
|
||||
} from './manifestPullSecretUtils'
|
||||
import {updateSpecLabels} from './manifestSpecLabelUtils'
|
||||
import {getReplicaCount} from './manifestUpdateUtils'
|
||||
} from './manifestPullSecretUtils.js'
|
||||
import {updateSpecLabels} from './manifestSpecLabelUtils.js'
|
||||
import {getReplicaCount} from './manifestUpdateUtils.js'
|
||||
import * as yaml from 'js-yaml'
|
||||
import * as fs from 'fs'
|
||||
import {isWorkloadEntity, isDeploymentEntity} from '../types/kubernetesTypes.js'
|
||||
|
||||
describe('ScaledJob Support', () => {
|
||||
let scaledJobObject: any
|
||||
@ -57,13 +58,11 @@ describe('ScaledJob Support', () => {
|
||||
|
||||
describe('Workload Classification', () => {
|
||||
it('should classify ScaledJob as workload entity', () => {
|
||||
const {isWorkloadEntity} = require('../types/kubernetesTypes')
|
||||
expect(isWorkloadEntity('ScaledJob')).toBe(true)
|
||||
expect(isWorkloadEntity('scaledjob')).toBe(true)
|
||||
})
|
||||
|
||||
it('should not classify ScaledJob as deployment entity', () => {
|
||||
const {isDeploymentEntity} = require('../types/kubernetesTypes')
|
||||
expect(isDeploymentEntity('scaledjob')).toBe(false)
|
||||
expect(isDeploymentEntity('ScaledJob')).toBe(false)
|
||||
})
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import {Kubectl} from '../types/kubectl'
|
||||
import {Kubectl} from '../types/kubectl.js'
|
||||
|
||||
const trafficSplitAPIVersionPrefix = 'split.smi-spec.io'
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ import {
|
||||
cleanLabel,
|
||||
removeInvalidLabelCharacters,
|
||||
VALID_LABEL_REGEX
|
||||
} from '../utilities/workflowAnnotationUtils'
|
||||
} from '../utilities/workflowAnnotationUtils.js'
|
||||
|
||||
describe('WorkflowAnnotationUtils', () => {
|
||||
describe('cleanLabel', () => {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import {DeploymentConfig} from '../types/deploymentConfig'
|
||||
import {DeploymentConfig} from '../types/deploymentConfig.js'
|
||||
|
||||
const ANNOTATION_PREFIX = 'actions.github.com'
|
||||
|
||||
|
||||
@ -1,8 +1,15 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES6",
|
||||
"module": "commonjs",
|
||||
"esModuleInterop": true
|
||||
"target": "ES2020",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"types": ["vitest/globals"],
|
||||
"esModuleInterop": true,
|
||||
"strict": false,
|
||||
"skipLibCheck": true,
|
||||
"resolveJsonModule": true,
|
||||
"declaration": false,
|
||||
"sourceMap": true
|
||||
},
|
||||
"exclude": ["node_modules", "test", "src/**/*.test.ts"]
|
||||
"exclude": ["node_modules", "test", "lib"]
|
||||
}
|
||||
|
||||
11
vitest.config.ts
Normal file
11
vitest.config.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import {defineConfig} from 'vitest/config'
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
globals: true,
|
||||
environment: 'node',
|
||||
include: ['**/*.test.ts'],
|
||||
testTimeout: 9000,
|
||||
clearMocks: true
|
||||
}
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user