mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
mock user-store for kubectl_spec
This commit is contained in:
parent
4c24e9ef38
commit
7c3eee0cfc
@ -1,8 +1,6 @@
|
|||||||
import mockFs from "mock-fs"
|
import mockFs from "mock-fs"
|
||||||
import { userStore, UserStore } from "./user-store"
|
import { userStore, UserStore } from "./user-store"
|
||||||
|
|
||||||
jest.mock("electron")
|
|
||||||
|
|
||||||
// Console.log needs to be called before fs-mocks, see https://github.com/tschaub/mock-fs/issues/234
|
// Console.log needs to be called before fs-mocks, see https://github.com/tschaub/mock-fs/issues/234
|
||||||
console.log("");
|
console.log("");
|
||||||
|
|
||||||
|
|||||||
@ -285,13 +285,11 @@ export class Kubectl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected getDownloadMirror() {
|
protected getDownloadMirror() {
|
||||||
if (process.platform == "darwin") {
|
|
||||||
return packageMirrors.get("default") // MacOS packages are only available from default
|
|
||||||
}
|
|
||||||
const mirror = packageMirrors.get(userStore.getPreferences().downloadMirror)
|
const mirror = packageMirrors.get(userStore.getPreferences().downloadMirror)
|
||||||
if (mirror) { return mirror }
|
if (mirror) {
|
||||||
|
return mirror
|
||||||
return packageMirrors.get("default")
|
}
|
||||||
|
return packageMirrors.get("default") // MacOS packages are only available from default
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,19 @@
|
|||||||
import packageInfo from "../../package.json"
|
import packageInfo from "../../package.json"
|
||||||
import { bundledKubectl, Kubectl } from "../../src/main/kubectl";
|
import { bundledKubectl, Kubectl } from "../../src/main/kubectl";
|
||||||
|
import { UserStore } from "../common/user-store";
|
||||||
|
|
||||||
jest.mock("electron")
|
jest.mock("../common/user-store", () => {
|
||||||
|
const userStoreMock: Partial<UserStore> = {
|
||||||
|
getPreferences() {
|
||||||
|
return {
|
||||||
|
downloadMirror: "default"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
userStore: userStoreMock,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
describe("kubectlVersion", () => {
|
describe("kubectlVersion", () => {
|
||||||
it("returns bundled version if exactly same version used", async () => {
|
it("returns bundled version if exactly same version used", async () => {
|
||||||
|
|||||||
@ -1,32 +1,25 @@
|
|||||||
import { EventEmitter } from 'events'
|
import { EventEmitter } from 'events'
|
||||||
import { getFreePort } from "./port"
|
import { getFreePort } from "./port"
|
||||||
import net from "net"
|
|
||||||
|
|
||||||
jest.mock("net");
|
jest.mock("net", () => {
|
||||||
|
return {
|
||||||
class MockServer extends EventEmitter {
|
createServer() {
|
||||||
listen = jest.fn((obj) => {
|
return new class MockServer extends EventEmitter {
|
||||||
this.emit('listening', {})
|
listen = jest.fn(() => {
|
||||||
return this
|
this.emit('listening')
|
||||||
})
|
return this
|
||||||
address = () => {
|
})
|
||||||
return { port: 12345 }
|
address = () => {
|
||||||
|
return { port: 12345 }
|
||||||
|
}
|
||||||
|
unref = jest.fn()
|
||||||
|
close = jest.fn(cb => cb())
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
unref = jest.fn()
|
});
|
||||||
close = jest.fn(cb => cb())
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("getFreePort", () => {
|
describe("getFreePort", () => {
|
||||||
beforeEach(() => {
|
|
||||||
// @ts-ignore
|
|
||||||
// fixme: find a better way to support types for mocked module
|
|
||||||
net.createServer.mockReturnValue(new MockServer)
|
|
||||||
})
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
jest.clearAllMocks()
|
|
||||||
})
|
|
||||||
|
|
||||||
it("finds the next free port", async () => {
|
it("finds the next free port", async () => {
|
||||||
return expect(getFreePort()).resolves.toEqual(expect.any(Number))
|
return expect(getFreePort()).resolves.toEqual(expect.any(Number))
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user