Fix MockStorageApi recreating bucket storage

Signed-off-by: Tim Hansen <timbonicus@gmail.com>
This commit is contained in:
Tim Hansen
2021-05-28 20:12:01 -06:00
committed by Fredrik Adelöw
parent 8e919a6f88
commit 7af9cef074
2 changed files with 14 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/test-utils': patch
---
Fix a bug in `MockStorageApi` where it unhelpfully returned new empty buckets every single time
@@ -23,6 +23,8 @@ import ObservableImpl from 'zen-observable';
export type MockStorageBucket = { [key: string]: any };
const bucketStorageApis = new Map<string, MockStorageApi>();
export class MockStorageApi implements StorageApi {
private readonly namespace: string;
private readonly data: MockStorageBucket;
@@ -37,7 +39,13 @@ export class MockStorageApi implements StorageApi {
}
forBucket(name: string): StorageApi {
return new MockStorageApi(`${this.namespace}/${name}`, this.data);
if (!bucketStorageApis.has(name)) {
bucketStorageApis.set(
name,
new MockStorageApi(`${this.namespace}/${name}`, this.data),
);
}
return bucketStorageApis.get(name)!;
}
get<T>(key: string): T | undefined {