1
0
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:
Roman 2020-06-29 16:33:28 +03:00
parent 4c24e9ef38
commit 7c3eee0cfc
4 changed files with 33 additions and 32 deletions

View File

@ -1,8 +1,6 @@
import mockFs from "mock-fs"
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("");

View File

@ -285,13 +285,11 @@ export class Kubectl {
}
protected getDownloadMirror() {
if (process.platform == "darwin") {
return packageMirrors.get("default") // MacOS packages are only available from default
}
const mirror = packageMirrors.get(userStore.getPreferences().downloadMirror)
if (mirror) { return mirror }
return packageMirrors.get("default")
if (mirror) {
return mirror
}
return packageMirrors.get("default") // MacOS packages are only available from default
}
}

View File

@ -1,7 +1,19 @@
import packageInfo from "../../package.json"
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", () => {
it("returns bundled version if exactly same version used", async () => {

View File

@ -1,32 +1,25 @@
import { EventEmitter } from 'events'
import { getFreePort } from "./port"
import net from "net"
jest.mock("net");
class MockServer extends EventEmitter {
listen = jest.fn((obj) => {
this.emit('listening', {})
return this
})
address = () => {
return { port: 12345 }
jest.mock("net", () => {
return {
createServer() {
return new class MockServer extends EventEmitter {
listen = jest.fn(() => {
this.emit('listening')
return this
})
address = () => {
return { port: 12345 }
}
unref = jest.fn()
close = jest.fn(cb => cb())
}
},
}
unref = jest.fn()
close = jest.fn(cb => cb())
}
});
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 () => {
return expect(getFreePort()).resolves.toEqual(expect.any(Number))
})