Skip to content

Commit

Permalink
resolved dir not existing and UTs
Browse files Browse the repository at this point in the history
  • Loading branch information
jaiveerk committed Jul 31, 2024
1 parent f70d289 commit 3c4dde9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
10 changes: 0 additions & 10 deletions src/types/privatekubectl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,6 @@ export class PrivateKubectl extends Kubectl {
const tempDirectory = getTempDirectory()
eo.cwd = tempDirectory
privateClusterArgs.push(...['--file', '.'])

for (const filename of filenames) {
try {
this.moveFileToTempManifestDir(filename)
} catch (e) {
core.debug(
`Error moving file ${filename} to temp directory: ${e}`
)
}
}
}

core.debug(
Expand Down
7 changes: 7 additions & 0 deletions src/utilities/fileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ export function moveFileToTmpDir(originalFilepath: string) {

core.debug(`reading original contents from path: ${originalFilepath}`)
const contents = fs.readFileSync(originalFilepath).toString()

const dirName = path.dirname(newPath)
if (!fs.existsSync(dirName)) {
core.debug(`path ${dirName} doesn't exist yet, making new dir...`)
fs.mkdirSync(dirName, {recursive: true})
}
core.debug(`writing contents to new path ${newPath}`)
fs.writeFileSync(path.join(newPath), contents)
core.debug(`moved contents from ${originalFilepath} to ${newPath}`)

Expand Down
5 changes: 5 additions & 0 deletions src/utilities/manifestUpdateUtils.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import * as fileUtils from './fileUtils'
import * as manifestUpdateUtils from './manifestUpdateUtils'
import * as fs from 'fs'

describe('manifestUpdateUtils', () => {
jest.spyOn(fileUtils, 'getTempDirectory').mockImplementation(() => {
return '/tmp'
})
jest.spyOn(fs, 'writeFileSync').mockImplementation(() => {})
jest.spyOn(fs, 'readFileSync').mockImplementation((filename) => {
return 'test contents'
})

it('should place all files within the temp dir with the same path that they have in the repo', () => {
const originalFilePaths: string[] = [
Expand Down

0 comments on commit 3c4dde9

Please sign in to comment.