mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add failing unit test
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
2550b1efbd
commit
0c1c7b3996
@ -19,6 +19,9 @@ import { KubeObject } from "../kube-object";
|
||||
import { KubeObjectStore } from "../kube-object.store";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
// eslint-disable-next-line no-restricted-imports
|
||||
import { KubeApi as ExternalKubeApi } from "../../../extensions/common-api/k8s-api";
|
||||
|
||||
class TestApi extends KubeApi<KubeObject> {
|
||||
protected async checkPreferredVersion() {
|
||||
return;
|
||||
@ -54,7 +57,7 @@ describe("ApiManager", () => {
|
||||
});
|
||||
|
||||
describe("registerApi", () => {
|
||||
it("re-register store if apiBase changed", async () => {
|
||||
it("re-register store if apiBase changed", () => {
|
||||
const apiBase = "apis/v1/foo";
|
||||
const fallbackApiBase = "/apis/extensions/v1beta1/foo";
|
||||
const kubeApi = new TestApi({
|
||||
@ -72,21 +75,48 @@ describe("ApiManager", () => {
|
||||
logger: di.inject(loggerInjectable),
|
||||
}, kubeApi);
|
||||
|
||||
apiManager.registerApi(apiBase, kubeApi);
|
||||
apiManager.registerApi(kubeApi);
|
||||
|
||||
// Define to use test api for ingress store
|
||||
Object.defineProperty(kubeStore, "api", { value: kubeApi });
|
||||
apiManager.registerStore(kubeStore, [kubeApi]);
|
||||
apiManager.registerStore(kubeStore);
|
||||
|
||||
// Test that store is returned with original apiBase
|
||||
expect(apiManager.getStore(kubeApi)).toBe(kubeStore);
|
||||
|
||||
// Change apiBase similar as checkPreferredVersion does
|
||||
Object.defineProperty(kubeApi, "apiBase", { value: fallbackApiBase });
|
||||
apiManager.registerApi(fallbackApiBase, kubeApi);
|
||||
apiManager.registerApi(kubeApi);
|
||||
|
||||
// Test that store is returned with new apiBase
|
||||
expect(apiManager.getStore(kubeApi)).toBe(kubeStore);
|
||||
});
|
||||
});
|
||||
|
||||
describe("technical tests for autorun", () => {
|
||||
it("given two extensions register apis with the same apibase, settle into using the second", () => {
|
||||
const apiBase = "/apis/aquasecurity.github.io/v1alpha1/vulnerabilityreports";
|
||||
const firstApi = Object.assign(new ExternalKubeApi({
|
||||
objectConstructor: KubeObject,
|
||||
apiBase,
|
||||
kind: "VulnerabilityReport",
|
||||
}), {
|
||||
myField: 1,
|
||||
});
|
||||
const secondApi = Object.assign(new ExternalKubeApi({
|
||||
objectConstructor: KubeObject,
|
||||
apiBase,
|
||||
kind: "VulnerabilityReport",
|
||||
}), {
|
||||
myField: 2,
|
||||
});
|
||||
|
||||
void firstApi;
|
||||
void secondApi;
|
||||
|
||||
expect(apiManager.getApi(apiBase)).toMatchObject({
|
||||
myField: 2,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user