1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Fix use of bundled kubectl (#241)

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen 2020-04-11 17:48:29 +03:00 committed by GitHub
parent 758034f61a
commit d80e956870
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 3 deletions

14
__mocks__/electron.js Normal file
View File

@ -0,0 +1,14 @@
module.exports = {
require: jest.fn(),
match: jest.fn(),
app: {
getVersion: jest.fn().mockReturnValue("3.0.0"),
getPath: jest.fn().mockReturnValue("/foo/bar")
},
remote: {
app: {
getPath: jest.fn()
}
},
dialog: jest.fn()
};

View File

@ -11,7 +11,7 @@
"version": "3.2.0", "version": "3.2.0",
"main": "main.ts", "main": "main.ts",
"config": { "config": {
"bundledKubectlVersion": "1.17.3", "bundledKubectlVersion": "1.17.4",
"bundledHelmVersion": "3.1.2" "bundledHelmVersion": "3.1.2"
}, },
"engines": { "engines": {
@ -99,6 +99,7 @@
"collectCoverage": true, "collectCoverage": true,
"testRegex": "spec/.*_(spec)\\.[jt]sx?$", "testRegex": "spec/.*_(spec)\\.[jt]sx?$",
"verbose": true, "verbose": true,
"testEnvironment": "node",
"transform": { "transform": {
"^.+\\.tsx?$": "ts-jest" "^.+\\.tsx?$": "ts-jest"
} }

View File

@ -0,0 +1,17 @@
jest.mock("electron")
jest.mock("../../../src/common/user-store")
import { Kubectl, bundledKubectl } from "../../../src/main/kubectl"
describe("kubectlVersion", () => {
it("returns bundled version if exactly same version used", async () => {
const kubectl = new Kubectl(bundledKubectl.kubectlVersion)
expect(kubectl.kubectlVersion).toBe(bundledKubectl.kubectlVersion)
})
it("returns bundled version if same major.minor version is used", async () => {
const kubectl = new Kubectl("1.17.0")
expect(kubectl.kubectlVersion).toBe(bundledKubectl.kubectlVersion)
})
})

View File

@ -0,0 +1,9 @@
const userStore = {
getPreferences: jest.fn(() => {
return {
downloadMirror: "default"
}
})
}
export { userStore };

View File

@ -11,6 +11,7 @@ import * as lockFile from "proper-lockfile"
import { helmCli } from "./helm-cli" import { helmCli } from "./helm-cli"
import { userStore } from "../common/user-store" import { userStore } from "../common/user-store"
const bundledVersion = require("../../package.json").config.bundledKubectlVersion
const kubectlMap: Map<string, string> = new Map([ const kubectlMap: Map<string, string> = new Map([
["1.7", "1.8.15"], ["1.7", "1.8.15"],
["1.8", "1.9.10"], ["1.8", "1.9.10"],
@ -22,7 +23,7 @@ const kubectlMap: Map<string, string> = new Map([
["1.14", "1.14.10"], ["1.14", "1.14.10"],
["1.15", "1.15.11"], ["1.15", "1.15.11"],
["1.16", "1.16.8"], ["1.16", "1.16.8"],
["1.17", "1.17.4"], ["1.17", bundledVersion],
["1.18", "1.18.0"] ["1.18", "1.18.0"]
]) ])
@ -54,7 +55,7 @@ export class Kubectl {
public static readonly kubectlDir = path.join((app || remote.app).getPath("userData"), "binaries", "kubectl") public static readonly kubectlDir = path.join((app || remote.app).getPath("userData"), "binaries", "kubectl")
public static readonly bundledKubectlPath = bundledPath public static readonly bundledKubectlPath = bundledPath
public static readonly bundledKubectlVersion: string = require("../../package.json").config.bundledKubectlVersion public static readonly bundledKubectlVersion: string = bundledVersion
private static bundledInstance: Kubectl; private static bundledInstance: Kubectl;
// Returns the single bundled Kubectl instance // Returns the single bundled Kubectl instance