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

fix: Referencing apiManager should not throw (#7468)

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2023-04-05 10:17:35 -04:00 committed by GitHub
parent 128b05d4d4
commit 351f9d492f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 14 deletions

View File

@ -206,3 +206,17 @@ describe("ApiManager", () => {
});
});
});
describe("ApiManger without storesAndApisCanBeCreated", () => {
let di: DiContainer;
beforeEach(() => {
di = getDiForUnitTesting();
di.override(storesAndApisCanBeCreatedInjectable, () => false);
});
it("should not throw when creating apiManager", () => {
di.inject(apiManagerInjectable);
});
});

View File

@ -25,7 +25,7 @@ export type KubeObjectStoreFrom<Api> = Api extends KubeApi<infer KubeObj, infer
export type FindApiCallback = (api: KubeApi<KubeObject>) => boolean;
interface Dependencies {
export interface ApiManagerDependencies {
readonly apis: IComputedValue<KubeApi[]>;
readonly crdApis: IComputedValue<KubeApi[]>;
readonly stores: IComputedValue<KubeObjectStore[]>;
@ -38,7 +38,7 @@ export class ApiManager {
private readonly defaultCrdStores = observable.map<string, KubeObjectStore>();
private readonly apis = observable.map<string, KubeApi>();
constructor(private readonly dependencies: Dependencies) {
constructor(private readonly dependencies: ApiManagerDependencies) {
// NOTE: this is done to preserve the old behaviour of an API being discoverable using all previous apiBases
autorun(() => {
const apis = iter.chain(this.dependencies.apis.get().values())

View File

@ -18,18 +18,23 @@ const apiManagerInjectable = getInjectable({
const computedInjectMany = di.inject(computedInjectManyInjectable);
const storesAndApisCanBeCreated = di.inject(storesAndApisCanBeCreatedInjectionToken);
return new ApiManager({
apis: storesAndApisCanBeCreated
? computedInjectMany(kubeApiInjectionToken)
: computed(() => []),
stores: storesAndApisCanBeCreated
? computedInjectMany(kubeObjectStoreInjectionToken)
: computed(() => []),
crdApis: storesAndApisCanBeCreated
? computedInjectMany(customResourceDefinitionApiInjectionToken)
: computed(() => []),
return new ApiManager((
storesAndApisCanBeCreated
? {
apis: computedInjectMany(kubeApiInjectionToken),
stores: computedInjectMany(kubeObjectStoreInjectionToken),
crdApis: computedInjectMany(customResourceDefinitionApiInjectionToken),
createCustomResourceStore: di.inject(createCustomResourceStoreInjectable),
});
}
: {
apis: computed(() => []),
stores: computed(() => []),
crdApis: computed(() => []),
createCustomResourceStore: () => {
throw new Error("Tried to create a KubeObjectStore for a CustomResource in a disallowed environment");
},
}
));
},
});