mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-04-06 04:52:17 +08:00
* Bump the actions group across 1 directory with 7 updates Bumps the actions group with 7 updates in the / directory: | Package | From | To | | --- | --- | --- | | [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core) | `1.10.1` | `1.11.1` | | [@octokit/core](https://github.com/octokit/core.js) | `3.6.0` | `6.1.2` | | [@octokit/plugin-retry](https://github.com/octokit/plugin-retry.js) | `3.0.9` | `7.1.2` | | [@types/jest](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/jest) | `29.5.13` | `29.5.14` | | [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) | `22.7.4` | `22.8.7` | | [prettier](https://github.com/prettier/prettier) | `2.8.8` | `3.3.3` | | [typescript](https://github.com/microsoft/TypeScript) | `5.6.2` | `5.6.3` | Updates `@actions/core` from 1.10.1 to 1.11.1 - [Changelog](https://github.com/actions/toolkit/blob/main/packages/core/RELEASES.md) - [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/core) Updates `@octokit/core` from 3.6.0 to 6.1.2 - [Release notes](https://github.com/octokit/core.js/releases) - [Commits](https://github.com/octokit/core.js/compare/v3.6.0...v6.1.2) Updates `@octokit/plugin-retry` from 3.0.9 to 7.1.2 - [Release notes](https://github.com/octokit/plugin-retry.js/releases) - [Commits](https://github.com/octokit/plugin-retry.js/compare/v3.0.9...v7.1.2) Updates `@types/jest` from 29.5.13 to 29.5.14 - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/jest) Updates `@types/node` from 22.7.4 to 22.8.7 - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) Updates `prettier` from 2.8.8 to 3.3.3 - [Release notes](https://github.com/prettier/prettier/releases) - [Changelog](https://github.com/prettier/prettier/blob/main/CHANGELOG.md) - [Commits](https://github.com/prettier/prettier/compare/2.8.8...3.3.3) Updates `typescript` from 5.6.2 to 5.6.3 - [Release notes](https://github.com/microsoft/TypeScript/releases) - [Changelog](https://github.com/microsoft/TypeScript/blob/main/azure-pipelines.release.yml) - [Commits](https://github.com/microsoft/TypeScript/compare/v5.6.2...v5.6.3) --- updated-dependencies: - dependency-name: "@actions/core" dependency-type: direct:production update-type: version-update:semver-minor dependency-group: actions - dependency-name: "@octokit/core" dependency-type: direct:production update-type: version-update:semver-major dependency-group: actions - dependency-name: "@octokit/plugin-retry" dependency-type: direct:production update-type: version-update:semver-major dependency-group: actions - dependency-name: "@types/jest" dependency-type: direct:development update-type: version-update:semver-patch dependency-group: actions - dependency-name: "@types/node" dependency-type: direct:development update-type: version-update:semver-minor dependency-group: actions - dependency-name: prettier dependency-type: direct:development update-type: version-update:semver-major dependency-group: actions - dependency-name: typescript dependency-type: direct:development update-type: version-update:semver-patch dependency-group: actions ... Signed-off-by: dependabot[bot] <support@github.com> * fixed octokit imports * fix fs imports * prettier * babel config * format * format action update --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: David Gamero <david340804@gmail.com>
123 lines
4.0 KiB
TypeScript
123 lines
4.0 KiB
TypeScript
import * as fileUtils from './fileUtils'
|
|
|
|
import * as yaml from 'js-yaml'
|
|
import fs from 'node:fs'
|
|
import * as path from 'path'
|
|
import {K8sObject} from '../types/k8sObject'
|
|
|
|
const sampleYamlUrl =
|
|
'https://raw.githubusercontent.com/kubernetes/website/main/content/en/examples/controllers/nginx-deployment.yaml'
|
|
describe('File utils', () => {
|
|
test('correctly parses a yaml file from a URL', async () => {
|
|
const tempFile = await fileUtils.writeYamlFromURLToFile(sampleYamlUrl, 0)
|
|
const fileContents = fs.readFileSync(tempFile).toString()
|
|
const inputObjects: K8sObject[] = yaml.loadAll(
|
|
fileContents
|
|
) as K8sObject[]
|
|
expect(inputObjects).toHaveLength(1)
|
|
|
|
for (const obj of inputObjects) {
|
|
expect(obj.metadata.name).toBe('nginx-deployment')
|
|
expect(obj.kind).toBe('Deployment')
|
|
}
|
|
})
|
|
|
|
it('fails when a bad URL is given among other files', async () => {
|
|
const badUrl = 'https://www.github.com'
|
|
|
|
const testPath = path.join('test', 'unit', 'manifests')
|
|
await expect(
|
|
fileUtils.getFilesFromDirectoriesAndURLs([testPath, badUrl])
|
|
).rejects.toThrow()
|
|
})
|
|
|
|
it('detects files in nested directories with the same name and ignores non-manifest files and empty dirs', async () => {
|
|
const testPath = path.join('test', 'unit', 'manifests')
|
|
const testSearch: string[] =
|
|
await fileUtils.getFilesFromDirectoriesAndURLs([
|
|
testPath,
|
|
sampleYamlUrl
|
|
])
|
|
|
|
const expectedManifests = [
|
|
'test/unit/manifests/manifest_test_dir/another_layer/test-ingress.yaml',
|
|
'test/unit/manifests/manifest_test_dir/another_layer/nested-test-service.yaml',
|
|
'test/unit/manifests/manifest_test_dir/nested-test-service.yaml',
|
|
'test/unit/manifests/test-ingress.yml',
|
|
'test/unit/manifests/test-ingress-new.yml',
|
|
'test/unit/manifests/test-service.yml'
|
|
]
|
|
|
|
expect(testSearch).toHaveLength(8)
|
|
expectedManifests.forEach((fileName) => {
|
|
if (fileName.startsWith('test/unit')) {
|
|
expect(testSearch).toContain(fileName)
|
|
} else {
|
|
expect(fileName.includes(fileUtils.urlFileKind)).toBe(true)
|
|
expect(fileName.startsWith(fileUtils.getTempDirectory()))
|
|
}
|
|
})
|
|
})
|
|
|
|
it('crashes when an invalid file is provided', async () => {
|
|
const badPath = path.join('test', 'unit', 'manifests', 'nonexistent.yaml')
|
|
const goodPath = path.join(
|
|
'test',
|
|
'unit',
|
|
'manifests',
|
|
'manifest_test_dir'
|
|
)
|
|
|
|
expect(
|
|
fileUtils.getFilesFromDirectoriesAndURLs([badPath, goodPath])
|
|
).rejects.toThrowError()
|
|
})
|
|
|
|
it("doesn't duplicate files when nested dir included", async () => {
|
|
const outerPath = path.join('test', 'unit', 'manifests')
|
|
const fileAtOuter = path.join(
|
|
'test',
|
|
'unit',
|
|
'manifests',
|
|
'test-service.yml'
|
|
)
|
|
const innerPath = path.join(
|
|
'test',
|
|
'unit',
|
|
'manifests',
|
|
'manifest_test_dir'
|
|
)
|
|
|
|
expect(
|
|
await fileUtils.getFilesFromDirectoriesAndURLs([
|
|
outerPath,
|
|
fileAtOuter,
|
|
innerPath
|
|
])
|
|
).toHaveLength(7)
|
|
})
|
|
|
|
it('throws an error for an invalid URL', async () => {
|
|
const badUrl = 'https://www.github.com'
|
|
await expect(
|
|
fileUtils.writeYamlFromURLToFile(badUrl, 0)
|
|
).rejects.toBeTruthy()
|
|
})
|
|
})
|
|
|
|
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) => {
|
|
return 'test contents'
|
|
})
|
|
const originalFilePath = path.join('path', 'in', 'repo')
|
|
|
|
const output = fileUtils.moveFileToTmpDir(originalFilePath)
|
|
|
|
expect(output).toEqual(
|
|
path.join(fileUtils.getTempDirectory(), '/path/in/repo')
|
|
)
|
|
})
|
|
})
|