Compare commits
36 Commits
v4
...
dependabot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
66668f767a | ||
|
|
fa3df0f1e2 | ||
|
|
4d5f3eda74 | ||
|
|
393d232f65 | ||
|
|
a0d66424c8 | ||
|
|
a76651a0e0 | ||
|
|
cf5fdd749b | ||
|
|
de1d5ec5de | ||
|
|
e6e81bbc41 | ||
|
|
30d747582d | ||
|
|
f4440b5470 | ||
|
|
0fd96d6276 | ||
|
|
4ef821e7ca | ||
|
|
95e0936d6e | ||
|
|
87e53e3f71 | ||
|
|
13bef3ca00 | ||
|
|
023f859e5d | ||
|
|
6bd1f0daf1 | ||
|
|
574933e749 | ||
|
|
46ce001b45 | ||
|
|
f7a3237edf | ||
|
|
9c31f8cc61 | ||
|
|
eaac930c67 | ||
|
|
8e9b27e666 | ||
|
|
fd493af03c | ||
|
|
304c023ca5 | ||
|
|
2d66d6bef6 | ||
|
|
3b0a9a4ae3 | ||
|
|
66e812b74c | ||
|
|
fc19d5430f | ||
|
|
5f6d890454 | ||
|
|
27d304ebf8 | ||
|
|
b5a36385a8 | ||
|
|
0b4bd0b42d | ||
|
|
2a0a121944 | ||
|
|
619a3634cc |
18
.github/dependabot.yml
vendored
Normal file
18
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: npm
|
||||
directory: /
|
||||
schedule:
|
||||
interval: weekly
|
||||
groups:
|
||||
actions:
|
||||
patterns:
|
||||
- '*'
|
||||
- package-ecosystem: github-actions
|
||||
directory: .github/workflows
|
||||
schedule:
|
||||
interval: weekly
|
||||
groups:
|
||||
actions:
|
||||
patterns:
|
||||
- '*'
|
||||
91
.github/workflows/codeql.yml
vendored
Normal file
91
.github/workflows/codeql.yml
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
# For most projects, this workflow file will not need changing; you simply need
|
||||
# to commit it to your repository.
|
||||
#
|
||||
# You may wish to alter this file to override the set of languages analyzed,
|
||||
# or to provide custom queries or build logic.
|
||||
#
|
||||
# ******** NOTE ********
|
||||
# We have attempted to detect the languages in your repository. Please check
|
||||
# the `language` matrix defined below to confirm you have the correct set of
|
||||
# supported CodeQL languages.
|
||||
#
|
||||
name: 'CodeQL Advanced'
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ['main']
|
||||
pull_request:
|
||||
branches: ['main']
|
||||
schedule:
|
||||
- cron: '15 9 * * 0'
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze (${{ matrix.language }})
|
||||
# Runner size impacts CodeQL analysis time. To learn more, please see:
|
||||
# - https://gh.io/recommended-hardware-resources-for-running-codeql
|
||||
# - https://gh.io/supported-runners-and-hardware-resources
|
||||
# - https://gh.io/using-larger-runners (GitHub.com only)
|
||||
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
|
||||
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
|
||||
permissions:
|
||||
# required for all workflows
|
||||
security-events: write
|
||||
|
||||
# required to fetch internal or private CodeQL packs
|
||||
packages: read
|
||||
|
||||
# only required for workflows in private repositories
|
||||
actions: read
|
||||
contents: read
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- language: javascript-typescript
|
||||
build-mode: none
|
||||
# CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
|
||||
# Use `c-cpp` to analyze code written in C, C++ or both
|
||||
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
|
||||
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
|
||||
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
|
||||
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
|
||||
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
|
||||
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
build-mode: ${{ matrix.build-mode }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
# By default, queries listed here will override any specified in a config file.
|
||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||
|
||||
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
|
||||
# queries: security-extended,security-and-quality
|
||||
|
||||
# If the analyze step fails for one of the languages you are analyzing with
|
||||
# "We were unable to automatically build your code", modify the matrix above
|
||||
# to set the build mode to "manual" for that language. Then modify this step
|
||||
# to build your code.
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
|
||||
- if: matrix.build-mode == 'manual'
|
||||
shell: bash
|
||||
run: |
|
||||
echo 'If you are using a "manual" build mode for one or more of the' \
|
||||
'languages you are analyzing, replace this with the commands to build' \
|
||||
'your code, for example:'
|
||||
echo ' make bootstrap'
|
||||
echo ' make release'
|
||||
exit 1
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18
|
||||
with:
|
||||
category: '/language:${{matrix.language}}'
|
||||
4
.github/workflows/defaultLabels.yml
vendored
4
.github/workflows/defaultLabels.yml
vendored
@@ -8,7 +8,7 @@ jobs:
|
||||
label-issues:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/stale@v3
|
||||
- uses: actions/stale@5bef64f19d7facfb25b37b414482c7164d639639 # v9.1.0
|
||||
name: Setting issue as idle
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -19,7 +19,7 @@ jobs:
|
||||
operations-per-run: 100
|
||||
exempt-issue-labels: 'backlog'
|
||||
|
||||
- uses: actions/stale@v3
|
||||
- uses: actions/stale@5bef64f19d7facfb25b37b414482c7164d639639 # v9.1.0
|
||||
name: Setting PR as idle
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
13
.github/workflows/integration-tests.yml
vendored
13
.github/workflows/integration-tests.yml
vendored
@@ -17,7 +17,7 @@ jobs:
|
||||
KUBECONFIG: /home/runner/.kube/config
|
||||
PR_BASE_REF: ${{ github.event.pull_request.base.ref }}
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
name: Checkout from PR branch
|
||||
|
||||
- id: action-npm-build
|
||||
@@ -29,7 +29,7 @@ jobs:
|
||||
npm run build
|
||||
fi
|
||||
|
||||
- uses: actions/setup-python@v2
|
||||
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
|
||||
name: Install Python
|
||||
with:
|
||||
python-version: '3.x'
|
||||
@@ -37,13 +37,18 @@ jobs:
|
||||
- name: Install requests library
|
||||
run: pip install requests
|
||||
|
||||
- name: Setup kubectl latest
|
||||
uses: ./
|
||||
with:
|
||||
version: 'latest'
|
||||
|
||||
- name: Validate kubectl setup
|
||||
run: python test/validate-kubectl.py latest
|
||||
|
||||
- name: Setup kubectl
|
||||
- name: Setup kubectl old version
|
||||
uses: ./
|
||||
with:
|
||||
version: 'v1.15.1'
|
||||
|
||||
- name: Validate kubectl setup
|
||||
- name: Validate kubectl setup old version
|
||||
run: python test/validate-kubectl.py 'v1.15.1'
|
||||
|
||||
15
.github/workflows/prettify-code.yml
vendored
15
.github/workflows/prettify-code.yml
vendored
@@ -10,9 +10,16 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
|
||||
- name: Enforce Prettier
|
||||
uses: actionsx/prettier@v2
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
|
||||
with:
|
||||
args: --check .
|
||||
node-version: 'lts/*'
|
||||
cache: 'npm'
|
||||
|
||||
- name: Install Dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Run Prettier Check
|
||||
run: npx prettier --check .
|
||||
|
||||
2
.github/workflows/release-pr.yml
vendored
2
.github/workflows/release-pr.yml
vendored
@@ -13,6 +13,6 @@ jobs:
|
||||
permissions:
|
||||
actions: read
|
||||
contents: write
|
||||
uses: Azure/action-release-workflows/.github/workflows/release_js_project.yaml@a705b2ab6a3ee889f2b0d925ad0bd2f9eb733ce6
|
||||
uses: Azure/action-release-workflows/.github/workflows/release_js_project.yaml@v1
|
||||
with:
|
||||
changelogPath: ./CHANGELOG.md
|
||||
|
||||
2
.github/workflows/unit-tests.yml
vendored
2
.github/workflows/unit-tests.yml
vendored
@@ -13,7 +13,7 @@ jobs:
|
||||
build: # make sure build/ci works properly
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
|
||||
- name: Build and run L0 tests.
|
||||
run: |
|
||||
|
||||
@@ -4,4 +4,4 @@
|
||||
|
||||
### Changed
|
||||
|
||||
- #90 Migrate to node 20 as node 16 is deprecated
|
||||
- #90 Migrate to node 20 as node 16 is deprecated
|
||||
|
||||
@@ -4,6 +4,6 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
|
||||
|
||||
Resources:
|
||||
|
||||
- [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/)
|
||||
- [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
|
||||
- Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns
|
||||
- [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/)
|
||||
- [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
|
||||
- Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
Acceptable values are latest or any semantic version string like `v1.15.0`. Use this action in workflow to define which version of kubectl will be used.
|
||||
|
||||
```yaml
|
||||
- uses: azure/setup-kubectl@v3
|
||||
- uses: azure/setup-kubectl@v4
|
||||
with:
|
||||
version: '<version>' # default is latest stable
|
||||
id: install
|
||||
|
||||
14
SECURITY.md
14
SECURITY.md
@@ -14,13 +14,13 @@ You should receive a response within 24 hours. If for some reason you do not, pl
|
||||
|
||||
Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
|
||||
|
||||
- Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
|
||||
- Full paths of source file(s) related to the manifestation of the issue
|
||||
- The location of the affected source code (tag/branch/commit or direct URL)
|
||||
- Any special configuration required to reproduce the issue
|
||||
- Step-by-step instructions to reproduce the issue
|
||||
- Proof-of-concept or exploit code (if possible)
|
||||
- Impact of the issue, including how an attacker might exploit the issue
|
||||
- Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
|
||||
- Full paths of source file(s) related to the manifestation of the issue
|
||||
- The location of the affected source code (tag/branch/commit or direct URL)
|
||||
- Any special configuration required to reproduce the issue
|
||||
- Step-by-step instructions to reproduce the issue
|
||||
- Proof-of-concept or exploit code (if possible)
|
||||
- Impact of the issue, including how an attacker might exploit the issue
|
||||
|
||||
This information will help us triage your report more quickly.
|
||||
|
||||
|
||||
9563
package-lock.json
generated
9563
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
20
package.json
20
package.json
@@ -4,7 +4,7 @@
|
||||
"private": true,
|
||||
"main": "lib/index.js",
|
||||
"scripts": {
|
||||
"build": "npm i ncc && npx ncc build src/run.ts -o lib",
|
||||
"build": "npm i ncc && npx ncc build src/index.ts -o lib",
|
||||
"test": "jest",
|
||||
"test-coverage": "jest --coverage",
|
||||
"format": "prettier --write .",
|
||||
@@ -18,17 +18,17 @@
|
||||
"author": "GitHub",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.0",
|
||||
"@actions/core": "^1.11.1",
|
||||
"@actions/exec": "^1.0.0",
|
||||
"@actions/tool-cache": "^1.0.0"
|
||||
"@actions/tool-cache": "^2.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^26.0.0",
|
||||
"@types/node": "^12.0.4",
|
||||
"@vercel/ncc": "^0.34.0",
|
||||
"jest": "^26.0.1",
|
||||
"prettier": "2.7.1",
|
||||
"ts-jest": "^26.0.0",
|
||||
"typescript": "3.9.2"
|
||||
"@types/jest": "^29.5.14",
|
||||
"@types/node": "^22.15.30",
|
||||
"@vercel/ncc": "^0.38.3",
|
||||
"jest": "^29.7.0",
|
||||
"prettier": "3.5.3",
|
||||
"ts-jest": "^29.3.4",
|
||||
"typescript": "5.8.3"
|
||||
}
|
||||
}
|
||||
|
||||
4
src/index.ts
Normal file
4
src/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import {run} from './run'
|
||||
import * as core from '@actions/core'
|
||||
|
||||
run().catch(core.setFailed)
|
||||
@@ -14,18 +14,14 @@ import * as util from 'util'
|
||||
describe('Testing all functions in run file.', () => {
|
||||
test('getExecutableExtension() - return .exe when os is Windows', () => {
|
||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT')
|
||||
|
||||
expect(getExecutableExtension()).toBe('.exe')
|
||||
expect(os.type).toBeCalled()
|
||||
})
|
||||
|
||||
test('getExecutableExtension() - return empty string for non-windows OS', () => {
|
||||
jest.spyOn(os, 'type').mockReturnValue('Darwin')
|
||||
|
||||
expect(getExecutableExtension()).toBe('')
|
||||
expect(os.type).toBeCalled()
|
||||
})
|
||||
|
||||
test.each([
|
||||
['arm', 'arm'],
|
||||
['arm64', 'arm64'],
|
||||
@@ -34,12 +30,10 @@ describe('Testing all functions in run file.', () => {
|
||||
'getKubectlArch() - return on %s os arch %s kubectl arch',
|
||||
(osArch, kubectlArch) => {
|
||||
jest.spyOn(os, 'arch').mockReturnValue(osArch)
|
||||
|
||||
expect(getKubectlArch()).toBe(kubectlArch)
|
||||
expect(os.arch).toBeCalled()
|
||||
}
|
||||
)
|
||||
|
||||
test.each([['arm'], ['arm64'], ['amd64']])(
|
||||
'getkubectlDownloadURL() - return the URL to download %s kubectl for Linux',
|
||||
(arch) => {
|
||||
@@ -48,12 +42,10 @@ describe('Testing all functions in run file.', () => {
|
||||
'https://dl.k8s.io/release/v1.15.0/bin/linux/%s/kubectl',
|
||||
arch
|
||||
)
|
||||
|
||||
expect(getkubectlDownloadURL('v1.15.0', arch)).toBe(kubectlLinuxUrl)
|
||||
expect(os.type).toBeCalled()
|
||||
}
|
||||
)
|
||||
|
||||
test.each([['arm'], ['arm64'], ['amd64']])(
|
||||
'getkubectlDownloadURL() - return the URL to download %s kubectl for Darwin',
|
||||
(arch) => {
|
||||
@@ -62,17 +54,14 @@ describe('Testing all functions in run file.', () => {
|
||||
'https://dl.k8s.io/release/v1.15.0/bin/darwin/%s/kubectl',
|
||||
arch
|
||||
)
|
||||
|
||||
expect(getkubectlDownloadURL('v1.15.0', arch)).toBe(kubectlDarwinUrl)
|
||||
expect(os.type).toBeCalled()
|
||||
}
|
||||
)
|
||||
|
||||
test.each([['arm'], ['arm64'], ['amd64']])(
|
||||
'getkubectlDownloadURL() - return the URL to download %s kubectl for Windows',
|
||||
(arch) => {
|
||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT')
|
||||
|
||||
const kubectlWindowsUrl = util.format(
|
||||
'https://dl.k8s.io/release/v1.15.0/bin/windows/%s/kubectl.exe',
|
||||
arch
|
||||
@@ -81,38 +70,31 @@ describe('Testing all functions in run file.', () => {
|
||||
expect(os.type).toBeCalled()
|
||||
}
|
||||
)
|
||||
|
||||
test('getStableKubectlVersion() - download stable version file, read version and return it', async () => {
|
||||
jest
|
||||
.spyOn(toolCache, 'downloadTool')
|
||||
.mockReturnValue(Promise.resolve('pathToTool'))
|
||||
jest.spyOn(fs, 'readFileSync').mockReturnValue('v1.20.4')
|
||||
|
||||
expect(await run.getStableKubectlVersion()).toBe('v1.20.4')
|
||||
expect(toolCache.downloadTool).toBeCalled()
|
||||
expect(fs.readFileSync).toBeCalledWith('pathToTool', 'utf8')
|
||||
expect(fs.readFileSync).toHaveBeenCalledWith('pathToTool', 'utf8')
|
||||
})
|
||||
|
||||
test('getStableKubectlVersion() - return default v1.15.0 if version read is empty', async () => {
|
||||
jest
|
||||
.spyOn(toolCache, 'downloadTool')
|
||||
.mockReturnValue(Promise.resolve('pathToTool'))
|
||||
jest.spyOn(fs, 'readFileSync').mockReturnValue('')
|
||||
|
||||
expect(await run.getStableKubectlVersion()).toBe('v1.15.0')
|
||||
expect(toolCache.downloadTool).toBeCalled()
|
||||
expect(fs.readFileSync).toBeCalledWith('pathToTool', 'utf8')
|
||||
expect(fs.readFileSync).toHaveBeenCalledWith('pathToTool', 'utf8')
|
||||
})
|
||||
|
||||
test('getStableKubectlVersion() - return default v1.15.0 if unable to download file', async () => {
|
||||
jest
|
||||
.spyOn(toolCache, 'downloadTool')
|
||||
.mockRejectedValue('Unable to download.')
|
||||
|
||||
expect(await run.getStableKubectlVersion()).toBe('v1.15.0')
|
||||
expect(toolCache.downloadTool).toBeCalled()
|
||||
})
|
||||
|
||||
test('downloadKubectl() - download kubectl, add it to toolCache and return path to it', async () => {
|
||||
jest.spyOn(toolCache, 'find').mockReturnValue('')
|
||||
jest
|
||||
@@ -123,43 +105,37 @@ describe('Testing all functions in run file.', () => {
|
||||
.mockReturnValue(Promise.resolve('pathToCachedTool'))
|
||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT')
|
||||
jest.spyOn(fs, 'chmodSync').mockImplementation(() => {})
|
||||
|
||||
expect(await run.downloadKubectl('v1.15.0')).toBe(
|
||||
path.join('pathToCachedTool', 'kubectl.exe')
|
||||
)
|
||||
expect(toolCache.find).toBeCalledWith('kubectl', 'v1.15.0')
|
||||
expect(toolCache.find).toHaveBeenCalledWith('kubectl', 'v1.15.0')
|
||||
expect(toolCache.downloadTool).toBeCalled()
|
||||
expect(toolCache.cacheFile).toBeCalled()
|
||||
expect(os.type).toBeCalled()
|
||||
expect(fs.chmodSync).toBeCalledWith(
|
||||
expect(fs.chmodSync).toHaveBeenCalledWith(
|
||||
path.join('pathToCachedTool', 'kubectl.exe'),
|
||||
'775'
|
||||
)
|
||||
})
|
||||
|
||||
test('downloadKubectl() - throw DownloadKubectlFailed error when unable to download kubectl', async () => {
|
||||
jest.spyOn(toolCache, 'find').mockReturnValue('')
|
||||
jest
|
||||
.spyOn(toolCache, 'downloadTool')
|
||||
.mockRejectedValue('Unable to download kubectl.')
|
||||
|
||||
await expect(run.downloadKubectl('v1.15.0')).rejects.toThrow(
|
||||
'DownloadKubectlFailed'
|
||||
)
|
||||
expect(toolCache.find).toBeCalledWith('kubectl', 'v1.15.0')
|
||||
expect(toolCache.find).toHaveBeenCalledWith('kubectl', 'v1.15.0')
|
||||
expect(toolCache.downloadTool).toBeCalled()
|
||||
})
|
||||
|
||||
test('downloadKubectl() - throw kubectl not found error when receive 404 response', async () => {
|
||||
const kubectlVersion = 'v1.15.0'
|
||||
const arch = 'arm128'
|
||||
|
||||
jest.spyOn(os, 'arch').mockReturnValue(arch)
|
||||
jest.spyOn(toolCache, 'find').mockReturnValue('')
|
||||
jest.spyOn(toolCache, 'downloadTool').mockImplementation((_) => {
|
||||
throw new toolCache.HTTPError(404)
|
||||
})
|
||||
|
||||
await expect(run.downloadKubectl(kubectlVersion)).rejects.toThrow(
|
||||
util.format(
|
||||
"Kubectl '%s' for '%s' arch not found.",
|
||||
@@ -168,28 +144,26 @@ describe('Testing all functions in run file.', () => {
|
||||
)
|
||||
)
|
||||
expect(os.arch).toBeCalled()
|
||||
expect(toolCache.find).toBeCalledWith('kubectl', kubectlVersion)
|
||||
expect(toolCache.find).toHaveBeenCalledWith('kubectl', kubectlVersion)
|
||||
expect(toolCache.downloadTool).toBeCalled()
|
||||
})
|
||||
|
||||
test('downloadKubectl() - return path to existing cache of kubectl', async () => {
|
||||
jest.spyOn(core, 'getInput').mockImplementation(() => 'v1.15.5')
|
||||
jest.spyOn(toolCache, 'find').mockReturnValue('pathToCachedTool')
|
||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT')
|
||||
jest.spyOn(fs, 'chmodSync').mockImplementation(() => {})
|
||||
jest.spyOn(toolCache, 'downloadTool')
|
||||
|
||||
expect(await run.downloadKubectl('v1.15.0')).toBe(
|
||||
path.join('pathToCachedTool', 'kubectl.exe')
|
||||
)
|
||||
expect(toolCache.find).toBeCalledWith('kubectl', 'v1.15.0')
|
||||
expect(toolCache.find).toHaveBeenCalledWith('kubectl', 'v1.15.0')
|
||||
expect(os.type).toBeCalled()
|
||||
expect(fs.chmodSync).toBeCalledWith(
|
||||
expect(fs.chmodSync).toHaveBeenCalledWith(
|
||||
path.join('pathToCachedTool', 'kubectl.exe'),
|
||||
'775'
|
||||
)
|
||||
expect(toolCache.downloadTool).not.toBeCalled()
|
||||
})
|
||||
|
||||
test('run() - download specified version and set output', async () => {
|
||||
jest.spyOn(core, 'getInput').mockReturnValue('v1.15.5')
|
||||
jest.spyOn(toolCache, 'find').mockReturnValue('pathToCachedTool')
|
||||
@@ -198,16 +172,14 @@ describe('Testing all functions in run file.', () => {
|
||||
jest.spyOn(core, 'addPath').mockImplementation()
|
||||
jest.spyOn(console, 'log').mockImplementation()
|
||||
jest.spyOn(core, 'setOutput').mockImplementation()
|
||||
|
||||
expect(await run.run()).toBeUndefined()
|
||||
expect(core.getInput).toBeCalledWith('version', {required: true})
|
||||
expect(core.addPath).toBeCalledWith('pathToCachedTool')
|
||||
expect(core.setOutput).toBeCalledWith(
|
||||
expect(core.getInput).toHaveBeenCalledWith('version', {required: true})
|
||||
expect(core.addPath).toHaveBeenCalledWith('pathToCachedTool')
|
||||
expect(core.setOutput).toHaveBeenCalledWith(
|
||||
'kubectl-path',
|
||||
path.join('pathToCachedTool', 'kubectl.exe')
|
||||
)
|
||||
})
|
||||
|
||||
test('run() - get latest version, download it and set output', async () => {
|
||||
jest.spyOn(core, 'getInput').mockReturnValue('latest')
|
||||
jest
|
||||
@@ -220,14 +192,13 @@ describe('Testing all functions in run file.', () => {
|
||||
jest.spyOn(core, 'addPath').mockImplementation()
|
||||
jest.spyOn(console, 'log').mockImplementation()
|
||||
jest.spyOn(core, 'setOutput').mockImplementation()
|
||||
|
||||
expect(await run.run()).toBeUndefined()
|
||||
expect(toolCache.downloadTool).toBeCalledWith(
|
||||
expect(toolCache.downloadTool).toHaveBeenCalledWith(
|
||||
'https://storage.googleapis.com/kubernetes-release/release/stable.txt'
|
||||
)
|
||||
expect(core.getInput).toBeCalledWith('version', {required: true})
|
||||
expect(core.addPath).toBeCalledWith('pathToCachedTool')
|
||||
expect(core.setOutput).toBeCalledWith(
|
||||
expect(core.getInput).toHaveBeenCalledWith('version', {required: true})
|
||||
expect(core.addPath).toHaveBeenCalledWith('pathToCachedTool')
|
||||
expect(core.setOutput).toHaveBeenCalledWith(
|
||||
'kubectl-path',
|
||||
path.join('pathToCachedTool', 'kubectl.exe')
|
||||
)
|
||||
|
||||
@@ -89,5 +89,3 @@ export async function downloadKubectl(version: string): Promise<string> {
|
||||
fs.chmodSync(kubectlPath, '775')
|
||||
return kubectlPath
|
||||
}
|
||||
|
||||
run().catch(core.setFailed)
|
||||
|
||||
Reference in New Issue
Block a user