mirror of
https://github.com/Azure/k8s-set-context.git
synced 2026-06-22 23:09:31 +08:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 787b48379f | |||
| 16f33d5a55 | |||
| 9d027c90e0 | |||
| eb220500b5 | |||
| 999ddc4def | |||
| fc3887264c | |||
| 55f8f705e4 | |||
| 2220ef0140 | |||
| 1b2b1d4a34 | |||
| 7d5d1039d9 |
@@ -59,7 +59,7 @@ jobs:
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@89a39a4e59826350b863aa6b6252a07ad50cf83e # v3.29.5
|
||||
uses: github/codeql-action/init@38697555549f1db7851b81482ff19f1fa5c4fedc # v3.29.5
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
build-mode: ${{ matrix.build-mode }}
|
||||
@@ -86,6 +86,6 @@ jobs:
|
||||
echo ' make release'
|
||||
exit 1
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@89a39a4e59826350b863aa6b6252a07ad50cf83e # v3.29.5
|
||||
uses: github/codeql-action/analyze@38697555549f1db7851b81482ff19f1fa5c4fedc # v3.29.5
|
||||
with:
|
||||
category: '/language:${{matrix.language}}'
|
||||
|
||||
@@ -13,7 +13,7 @@ jobs:
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
|
||||
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
|
||||
with:
|
||||
node-version: 'lts/*'
|
||||
cache: 'npm'
|
||||
|
||||
@@ -107,7 +107,3 @@ provided by the bot. You will only need to do this once across all repos using o
|
||||
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
|
||||
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
|
||||
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
|
||||
|
||||
### Local development
|
||||
|
||||
Use `npm run build` to bundle the action with esbuild (output is `lib/index.cjs`, referenced by `action.yml`) and `npm run test` to execute the Vitest suite, including an integration test that runs the built action.
|
||||
|
||||
+2
-2
@@ -39,5 +39,5 @@ inputs:
|
||||
branding:
|
||||
color: 'blue'
|
||||
runs:
|
||||
using: 'node20'
|
||||
main: 'lib/index.cjs'
|
||||
using: 'node24'
|
||||
main: 'lib/index.js'
|
||||
|
||||
Generated
+874
-1839
File diff suppressed because it is too large
Load Diff
+8
-8
@@ -2,10 +2,11 @@
|
||||
"name": "k8s-set-context-action",
|
||||
"version": "4.0.2",
|
||||
"private": true,
|
||||
"main": "lib/index.cjs",
|
||||
"main": "lib/index.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "tsc --noEmit && node ./scripts/build.mjs",
|
||||
"build": "tsc --noEmit && 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",
|
||||
"test-coverage": "vitest run --coverage",
|
||||
"format": "prettier --write .",
|
||||
@@ -20,9 +21,9 @@
|
||||
"author": "GitHub",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^2.0.2",
|
||||
"@actions/exec": "^2.0.0",
|
||||
"@actions/io": "^2.0.0",
|
||||
"@actions/core": "^3.0.0",
|
||||
"@actions/exec": "^3.0.0",
|
||||
"@actions/io": "^3.0.2",
|
||||
"@kubernetes/client-node": "^1.4.0",
|
||||
"husky": "^9.1.7",
|
||||
"js-yaml": "^4.1.1"
|
||||
@@ -30,10 +31,9 @@
|
||||
"devDependencies": {
|
||||
"@types/js-yaml": "^4.0.9",
|
||||
"@types/node": "^25.0.9",
|
||||
"@vitest/coverage-v8": "^2.0.4",
|
||||
"esbuild": "^0.24.0",
|
||||
"esbuild": "^0.27.4",
|
||||
"prettier": "^3.8.0",
|
||||
"typescript": "^5.9.3",
|
||||
"vitest": "^2.0.4"
|
||||
"vitest": "^4.1.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import {build} from 'esbuild'
|
||||
import {mkdir} from 'fs/promises'
|
||||
import {dirname} from 'path'
|
||||
|
||||
const outFile = 'lib/index.cjs'
|
||||
|
||||
const main = async () => {
|
||||
await mkdir(dirname(outFile), {recursive: true})
|
||||
await build({
|
||||
entryPoints: ['src/run.ts'],
|
||||
bundle: true,
|
||||
platform: 'node',
|
||||
target: 'node20',
|
||||
format: 'cjs',
|
||||
sourcemap: true,
|
||||
outfile: outFile,
|
||||
legalComments: 'none'
|
||||
})
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
console.error(err)
|
||||
process.exit(1)
|
||||
})
|
||||
+18
-41
@@ -1,56 +1,33 @@
|
||||
import {getRequiredInputError} from '../tests/util'
|
||||
import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest'
|
||||
import {run} from './action'
|
||||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
import os from 'os'
|
||||
import * as utils from './utils'
|
||||
import * as core from '@actions/core'
|
||||
import {vi, describe, it, expect} from 'vitest'
|
||||
import {getRequiredInputError} from '../tests/util.js'
|
||||
import {run} from './action.js'
|
||||
|
||||
vi.mock('fs')
|
||||
vi.mock('./utils.js')
|
||||
|
||||
describe('Run', () => {
|
||||
const initialEnv = {...process.env}
|
||||
const tempDirs: string[] = []
|
||||
|
||||
beforeEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
process.env = {...initialEnv}
|
||||
vi.spyOn(core, 'warning').mockImplementation(() => {})
|
||||
vi.spyOn(core, 'debug').mockImplementation(() => {})
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
tempDirs.forEach((dir) => {
|
||||
try {
|
||||
fs.rmSync(dir, {recursive: true, force: true})
|
||||
} catch {}
|
||||
})
|
||||
tempDirs.length = 0
|
||||
})
|
||||
|
||||
it('throws error without cluster type', async () => {
|
||||
await expect(run()).rejects.toThrow(getRequiredInputError('cluster-type'))
|
||||
})
|
||||
|
||||
it('writes kubeconfig and sets context', async () => {
|
||||
const {getKubeconfig, setContext} = await import('./utils.js')
|
||||
const fs = await import('fs')
|
||||
const kubeconfig = 'kubeconfig'
|
||||
const fixedTimestamp = 42
|
||||
|
||||
process.env['INPUT_CLUSTER-TYPE'] = 'default'
|
||||
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'kubeconfig-test-'))
|
||||
tempDirs.push(tmpDir)
|
||||
process.env['RUNNER_TEMP'] = tmpDir
|
||||
process.env['RUNNER_TEMP'] = '/sample/path'
|
||||
|
||||
vi.spyOn(Date, 'now').mockReturnValue(fixedTimestamp)
|
||||
vi.spyOn(utils, 'getKubeconfig').mockResolvedValue(kubeconfig)
|
||||
vi.spyOn(utils, 'setContext').mockImplementation(() => kubeconfig)
|
||||
vi.mocked(getKubeconfig).mockResolvedValue(kubeconfig)
|
||||
vi.mocked(setContext).mockReturnValue(kubeconfig)
|
||||
vi.mocked(fs.writeFileSync).mockImplementation(() => {})
|
||||
vi.mocked(fs.chmodSync).mockImplementation(() => {})
|
||||
|
||||
await expect(run()).resolves.toBeUndefined()
|
||||
await run()
|
||||
|
||||
const outputPath = path.join(tmpDir, `kubeconfig_${fixedTimestamp}`)
|
||||
expect(fs.existsSync(outputPath)).toBe(true)
|
||||
expect(fs.readFileSync(outputPath, 'utf-8')).toBe(kubeconfig)
|
||||
expect(process.env['KUBECONFIG']).toBe(outputPath)
|
||||
expect(utils.getKubeconfig).toHaveBeenCalled()
|
||||
expect(utils.setContext).toHaveBeenCalledWith(kubeconfig)
|
||||
expect(getKubeconfig).toHaveBeenCalled()
|
||||
expect(fs.writeFileSync).toHaveBeenCalled()
|
||||
expect(fs.chmodSync).toHaveBeenCalled()
|
||||
expect(setContext).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
+3
-3
@@ -1,8 +1,8 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as path from 'path'
|
||||
import * as fs from 'fs'
|
||||
import {Cluster, parseCluster} from './types/cluster'
|
||||
import {setContext, getKubeconfig} from './utils'
|
||||
import {Cluster, parseCluster} from './types/cluster.js'
|
||||
import {setContext, getKubeconfig} from './utils.js'
|
||||
|
||||
/**
|
||||
* Sets the Kubernetes context based on supplied action inputs
|
||||
@@ -14,7 +14,7 @@ export async function run() {
|
||||
required: true
|
||||
})
|
||||
)
|
||||
const runnerTempDirectory: string = process.env['RUNNER_TEMP']
|
||||
const runnerTempDirectory: string = process.env['RUNNER_TEMP'] ?? ''
|
||||
const kubeconfigPath: string = path.join(
|
||||
runnerTempDirectory,
|
||||
`kubeconfig_${Date.now()}`
|
||||
|
||||
+10
-15
@@ -1,18 +1,13 @@
|
||||
import {beforeEach, describe, expect, it, test, vi} from 'vitest'
|
||||
import * as core from '@actions/core'
|
||||
import * as actions from '@actions/exec'
|
||||
import {vi, describe, test, it, expect, beforeEach} from 'vitest'
|
||||
import * as io from '@actions/io'
|
||||
import {getRequiredInputError} from '../../tests/util'
|
||||
import {getArcKubeconfig, KUBECONFIG_LOCATION} from './arc'
|
||||
import * as az from './azCommands'
|
||||
import {getRequiredInputError} from '../../tests/util.js'
|
||||
import {getArcKubeconfig, KUBECONFIG_LOCATION} from './arc.js'
|
||||
import * as az from './azCommands.js'
|
||||
|
||||
vi.mock('@actions/io')
|
||||
vi.mock('./azCommands.js')
|
||||
|
||||
describe('Arc kubeconfig', () => {
|
||||
beforeEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
vi.spyOn(core, 'warning').mockImplementation(() => {})
|
||||
vi.spyOn(core, 'debug').mockImplementation(() => {})
|
||||
})
|
||||
|
||||
test('it throws error without resource group', async () => {
|
||||
await expect(getArcKubeconfig()).rejects.toThrow(
|
||||
getRequiredInputError('resource-group')
|
||||
@@ -36,9 +31,9 @@ describe('Arc kubeconfig', () => {
|
||||
process.env['INPUT_RESOURCE-GROUP'] = group
|
||||
process.env['INPUT_CLUSTER-NAME'] = name
|
||||
|
||||
vi.spyOn(io, 'which').mockResolvedValue(path)
|
||||
vi.spyOn(az, 'runAzCliCommand').mockResolvedValue()
|
||||
vi.spyOn(az, 'runAzKubeconfigCommandBlocking').mockResolvedValue(
|
||||
vi.mocked(io.which).mockResolvedValue(path)
|
||||
vi.mocked(az.runAzCliCommand).mockResolvedValue(undefined)
|
||||
vi.mocked(az.runAzKubeconfigCommandBlocking).mockResolvedValue(
|
||||
kubeconfig
|
||||
)
|
||||
})
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as io from '@actions/io'
|
||||
import {Method, parseMethod} from '../types/method'
|
||||
import {Method, parseMethod} from '../types/method.js'
|
||||
import * as path from 'path'
|
||||
import {runAzCliCommand, runAzKubeconfigCommandBlocking} from './azCommands'
|
||||
import {runAzCliCommand, runAzKubeconfigCommandBlocking} from './azCommands.js'
|
||||
|
||||
const RUNNER_TEMP: string = process.env['RUNNER_TEMP'] || ''
|
||||
export const KUBECONFIG_LOCATION: string = path.join(
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import {describe, expect, test, vi} from 'vitest'
|
||||
import * as core from '@actions/core'
|
||||
import {vi, describe, test, expect, beforeEach} from 'vitest'
|
||||
import * as actions from '@actions/exec'
|
||||
import {runAzCliCommand} from './azCommands'
|
||||
import {runAzCliCommand} from './azCommands.js'
|
||||
|
||||
vi.mock('@actions/exec')
|
||||
|
||||
describe('Az commands', () => {
|
||||
test('it runs an az cli command', async () => {
|
||||
vi.spyOn(core, 'debug').mockImplementation(() => {})
|
||||
const path = 'path'
|
||||
const args = ['args']
|
||||
|
||||
vi.spyOn(actions, 'exec').mockResolvedValue(0)
|
||||
vi.mocked(actions.exec).mockResolvedValue(0)
|
||||
|
||||
expect(await runAzCliCommand(path, args))
|
||||
await runAzCliCommand(path, args)
|
||||
expect(actions.exec).toHaveBeenCalledWith(path, args, {})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import * as fs from 'fs'
|
||||
import {ExecOptions} from '@actions/exec/lib/interfaces'
|
||||
import {exec} from '@actions/exec'
|
||||
import {ExecOptions, exec} from '@actions/exec'
|
||||
import {spawn} from 'child_process'
|
||||
|
||||
const AZ_TIMEOUT_SECONDS: number = 120
|
||||
|
||||
@@ -1,22 +1,9 @@
|
||||
import {afterEach, beforeEach, describe, expect, test, vi} from 'vitest'
|
||||
import {vi, describe, test, expect, beforeEach, afterEach} from 'vitest'
|
||||
import * as fs from 'fs'
|
||||
import * as core from '@actions/core'
|
||||
import {getRequiredInputError} from '../../tests/util'
|
||||
import {createKubeconfig, getDefaultKubeconfig} from './default'
|
||||
import {getRequiredInputError} from '../../tests/util.js'
|
||||
import {createKubeconfig, getDefaultKubeconfig} from './default.js'
|
||||
|
||||
describe('Default kubeconfig', () => {
|
||||
const originalEnv = {...process.env}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
vi.spyOn(core, 'warning').mockImplementation(() => {})
|
||||
vi.spyOn(core, 'debug').mockImplementation(() => {})
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
process.env = {...originalEnv}
|
||||
})
|
||||
|
||||
test('it creates a kubeconfig with proper format', () => {
|
||||
const certAuth = 'certAuth'
|
||||
const token = 'token'
|
||||
@@ -64,6 +51,11 @@ describe('Default kubeconfig', () => {
|
||||
process.env['INPUT_METHOD'] = 'default'
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
delete process.env['INPUT_KUBECONFIG']
|
||||
delete process.env['INPUT_KUBECONFIG-ENCODING']
|
||||
})
|
||||
|
||||
test('it throws error without kubeconfig', () => {
|
||||
expect(() => getDefaultKubeconfig()).toThrow(
|
||||
getRequiredInputError('kubeconfig')
|
||||
@@ -79,39 +71,25 @@ describe('Default kubeconfig', () => {
|
||||
|
||||
test('returns kubeconfig as plaintext when encoding is plaintext', () => {
|
||||
const kc = 'example kc'
|
||||
vi.spyOn(core, 'getInput').mockImplementation((name: string) => {
|
||||
if (name === 'method') return 'default'
|
||||
if (name === 'kubeconfig-encoding') return 'plaintext'
|
||||
if (name === 'kubeconfig') return kc
|
||||
return ''
|
||||
})
|
||||
process.env['INPUT_KUBECONFIG'] = kc
|
||||
process.env['INPUT_KUBECONFIG-ENCODING'] = 'plaintext'
|
||||
|
||||
expect(getDefaultKubeconfig()).toBe(kc)
|
||||
})
|
||||
|
||||
test('it gets default config through base64 kubeconfig input', () => {
|
||||
const kc = 'example kc'
|
||||
const base64Kc = Buffer.from(kc, 'utf-8').toString('base64')
|
||||
|
||||
vi.spyOn(core, 'getInput').mockImplementation((name: string) => {
|
||||
if (name === 'method') return 'default'
|
||||
if (name === 'kubeconfig-encoding') return 'base64'
|
||||
if (name === 'kubeconfig') return base64Kc
|
||||
return ''
|
||||
})
|
||||
process.env['INPUT_KUBECONFIG'] = base64Kc
|
||||
process.env['INPUT_KUBECONFIG-ENCODING'] = 'base64'
|
||||
|
||||
expect(getDefaultKubeconfig()).toBe(kc)
|
||||
})
|
||||
|
||||
test('it throws error for unknown kubeconfig-encoding', () => {
|
||||
const kc = 'example kc'
|
||||
const unknownEncoding = 'foobar'
|
||||
|
||||
vi.spyOn(core, 'getInput').mockImplementation((name: string) => {
|
||||
if (name === 'method') return 'default'
|
||||
if (name === 'kubeconfig-encoding') return unknownEncoding
|
||||
if (name === 'kubeconfig') return kc
|
||||
return ''
|
||||
})
|
||||
process.env['INPUT_KUBECONFIG'] = kc
|
||||
process.env['INPUT_KUBECONFIG-ENCODING'] = 'foobar'
|
||||
|
||||
expect(() => getDefaultKubeconfig()).toThrow(
|
||||
"Invalid kubeconfig-encoding: 'foobar'. Must be 'plaintext' or 'base64'."
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as jsyaml from 'js-yaml'
|
||||
import {KubeConfig} from '@kubernetes/client-node'
|
||||
import {K8sSecret, parseK8sSecret} from '../types/k8sSecret'
|
||||
import {Method, parseMethod} from '../types/method'
|
||||
import {K8sSecret, parseK8sSecret} from '../types/k8sSecret.js'
|
||||
import {Method, parseMethod} from '../types/method.js'
|
||||
|
||||
/**
|
||||
* Gets the kubeconfig based on provided method for a default Kubernetes cluster
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
import {run} from './action'
|
||||
import {run} from './action.js'
|
||||
import * as core from '@actions/core'
|
||||
|
||||
// Run the application
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import {describe, expect, test} from 'vitest'
|
||||
import {Cluster, parseCluster} from './cluster'
|
||||
import {describe, test, expect} from 'vitest'
|
||||
import {Cluster, parseCluster} from './cluster.js'
|
||||
|
||||
describe('Cluster type', () => {
|
||||
test('it has required values', () => {
|
||||
const vals = <any>Object.values(Cluster)
|
||||
const vals = Object.values(Cluster) as string[]
|
||||
expect(vals.includes('arc')).toBe(true)
|
||||
expect(vals.includes('generic')).toBe(true)
|
||||
})
|
||||
|
||||
@@ -8,9 +8,10 @@ export enum Cluster {
|
||||
* @param str The cluster type (case insensitive)
|
||||
* @returns The Cluster enum or undefined if it can't be parsed
|
||||
*/
|
||||
export const parseCluster = (str: string): Cluster | undefined =>
|
||||
Cluster[
|
||||
Object.keys(Cluster).filter(
|
||||
(k) => Cluster[k].toString().toLowerCase() === str.toLowerCase()
|
||||
)[0] as keyof typeof Cluster
|
||||
]
|
||||
export const parseCluster = (str: string): Cluster | undefined => {
|
||||
const key = Object.keys(Cluster).find(
|
||||
(k) =>
|
||||
Cluster[k as keyof typeof Cluster].toLowerCase() === str.toLowerCase()
|
||||
) as keyof typeof Cluster | undefined
|
||||
return key !== undefined ? Cluster[key] : undefined
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {describe, expect, test} from 'vitest'
|
||||
import {parseK8sSecret, K8sSecret} from './k8sSecret'
|
||||
import {describe, test, expect} from 'vitest'
|
||||
import {parseK8sSecret} from './k8sSecret.js'
|
||||
|
||||
describe('K8sSecret type', () => {
|
||||
describe('Parsing from any', () => {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import {describe, expect, test} from 'vitest'
|
||||
import {Method, parseMethod} from './method'
|
||||
import {describe, test, expect} from 'vitest'
|
||||
import {Method, parseMethod} from './method.js'
|
||||
|
||||
describe('Method type', () => {
|
||||
test('it has required values', () => {
|
||||
const vals = <any>Object.values(Method)
|
||||
const vals = Object.values(Method) as string[]
|
||||
expect(vals.includes('kubeconfig')).toBe(true)
|
||||
expect(vals.includes('service-account')).toBe(true)
|
||||
expect(vals.includes('service-principal')).toBe(true)
|
||||
|
||||
+7
-6
@@ -9,9 +9,10 @@ export enum Method {
|
||||
* @param str The method (case insensitive)
|
||||
* @returns The Method enum or undefined if it can't be parsed
|
||||
*/
|
||||
export const parseMethod = (str: string): Method | undefined =>
|
||||
Method[
|
||||
Object.keys(Method).filter(
|
||||
(k) => Method[k].toString().toLowerCase() === str.toLowerCase()
|
||||
)[0] as keyof typeof Method
|
||||
]
|
||||
export const parseMethod = (str: string): Method | undefined => {
|
||||
const key = Object.keys(Method).find(
|
||||
(k) =>
|
||||
Method[k as keyof typeof Method].toLowerCase() === str.toLowerCase()
|
||||
) as keyof typeof Method | undefined
|
||||
return key !== undefined ? Method[key] : undefined
|
||||
}
|
||||
|
||||
+8
-13
@@ -1,22 +1,17 @@
|
||||
import {beforeEach, describe, expect, test, vi} from 'vitest'
|
||||
import {vi, describe, test, expect} from 'vitest'
|
||||
import fs from 'fs'
|
||||
import * as arc from './kubeconfigs/arc'
|
||||
import * as def from './kubeconfigs/default'
|
||||
import {Cluster} from './types/cluster'
|
||||
import {getKubeconfig, setContext} from './utils'
|
||||
import * as core from '@actions/core'
|
||||
import * as arc from './kubeconfigs/arc.js'
|
||||
import * as def from './kubeconfigs/default.js'
|
||||
import {Cluster} from './types/cluster.js'
|
||||
import {getKubeconfig, setContext} from './utils.js'
|
||||
|
||||
describe('Utils', () => {
|
||||
beforeEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
vi.spyOn(core, 'warning').mockImplementation(() => {})
|
||||
vi.spyOn(core, 'debug').mockImplementation(() => {})
|
||||
})
|
||||
|
||||
describe('get kubeconfig', () => {
|
||||
test('it gets arc kubeconfig when type is arc', async () => {
|
||||
const arcKubeconfig = 'arckubeconfig'
|
||||
vi.spyOn(arc, 'getArcKubeconfig').mockResolvedValue(arcKubeconfig)
|
||||
vi.spyOn(arc, 'getArcKubeconfig').mockImplementation(
|
||||
async () => arcKubeconfig
|
||||
)
|
||||
|
||||
expect(await getKubeconfig(Cluster.ARC)).toBe(arcKubeconfig)
|
||||
})
|
||||
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as fs from 'fs'
|
||||
import {KubeConfig} from '@kubernetes/client-node'
|
||||
import {getDefaultKubeconfig} from './kubeconfigs/default'
|
||||
import {getArcKubeconfig} from './kubeconfigs/arc'
|
||||
import {Cluster} from './types/cluster'
|
||||
import {getDefaultKubeconfig} from './kubeconfigs/default.js'
|
||||
import {getArcKubeconfig} from './kubeconfigs/arc.js'
|
||||
import {Cluster} from './types/cluster.js'
|
||||
|
||||
/**
|
||||
* Gets the kubeconfig based on Kubernetes cluster type
|
||||
|
||||
+1
-1
@@ -3,5 +3,5 @@
|
||||
* @param inputName Name of input
|
||||
* @returns Error with explanation message
|
||||
*/
|
||||
export const getRequiredInputError = (inputName: string): Error =>
|
||||
export const getRequiredInputError = (inputName) =>
|
||||
Error(`Input required and not supplied: ${inputName}`)
|
||||
|
||||
+9
-10
@@ -1,15 +1,14 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"module": "ESNext", // or "NodeNext" depending on your setup
|
||||
"moduleResolution": "node",
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"target": "ES2020",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"rootDir": "./src",
|
||||
"outDir": "./lib",
|
||||
"noImplicitAny": false,
|
||||
"skipLibCheck": true,
|
||||
"paths": {
|
||||
"@actions/core": ["node_modules/@actions/core"],
|
||||
"@kubernetes/client-node": ["node_modules/@kubernetes/client-node"]
|
||||
}
|
||||
"noEmit": true,
|
||||
"types": ["node", "vitest/globals"]
|
||||
},
|
||||
"exclude": ["node_modules", "lib"]
|
||||
"exclude": ["node_modules", "**/*.test.ts", "vitest.config.ts", "tests/"]
|
||||
}
|
||||
|
||||
+2
-12
@@ -2,19 +2,9 @@ import {defineConfig} from 'vitest/config'
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
globals: true,
|
||||
environment: 'node',
|
||||
include: ['**/*.test.ts'],
|
||||
restoreMocks: true,
|
||||
clearMocks: true,
|
||||
mockReset: true,
|
||||
coverage: {
|
||||
provider: 'v8',
|
||||
thresholds: {
|
||||
statements: 22,
|
||||
branches: 0,
|
||||
functions: 40,
|
||||
lines: 22
|
||||
}
|
||||
}
|
||||
clearMocks: true
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user