Skip to content

Commit 0af4e8d

Browse files
committed
Add extra test for flush() and initialize()
1 parent a85dcff commit 0af4e8d

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/test/pythonEnvironments/base/envsCache.unit.test.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import * as externalDeps from '../../../client/pythonEnvironments/common/externa
99

1010
suite('Environment Info cache', () => {
1111
let createGlobalPersistentStoreStub: sinon.SinonStub;
12-
let updatedValues: PythonEnvInfo[] = [];
12+
let updatedValues: PythonEnvInfo[] | undefined;
1313

1414
const allEnvsComplete: CompleteEnvInfoFunction = () => true;
1515
const envInfoArray = [
@@ -37,7 +37,7 @@ suite('Environment Info cache', () => {
3737

3838
teardown(() => {
3939
createGlobalPersistentStoreStub.restore();
40-
updatedValues = [];
40+
updatedValues = undefined;
4141
});
4242

4343
test('`initialize` reads from persistent storage', () => {
@@ -48,6 +48,16 @@ suite('Environment Info cache', () => {
4848
assert.ok(createGlobalPersistentStoreStub.calledOnce);
4949
});
5050

51+
test('The in-memory env info array is undefined if there is no value in persistent storage when initializing the cache', () => {
52+
const envsCache = new PythonEnvInfoCache(allEnvsComplete);
53+
54+
createGlobalPersistentStoreStub.returns({ value: undefined });
55+
envsCache.initialize();
56+
const result = envsCache.getAllEnvs();
57+
58+
assert.strictEqual(result, undefined);
59+
});
60+
5161
test('`getAllEnvs` should return undefined if nothing has been set', () => {
5262
const envsCache = new PythonEnvInfoCache(allEnvsComplete);
5363

@@ -108,12 +118,20 @@ suite('Environment Info cache', () => {
108118
assert.deepStrictEqual(updatedValues, expected);
109119
});
110120

121+
test('`flush` should not write to persistent storage if there are no environment info objects in-memory', async () => {
122+
const envsCache = new PythonEnvInfoCache((env) => env.kind === PythonEnvKind.MacDefault);
123+
124+
await envsCache.flush();
125+
126+
assert.strictEqual(updatedValues, undefined);
127+
});
128+
111129
test('`flush` should not write to persistent storage if there are no complete environment info objects', async () => {
112130
const envsCache = new PythonEnvInfoCache((env) => env.kind === PythonEnvKind.MacDefault);
113131

114132
envsCache.initialize();
115133
await envsCache.flush();
116134

117-
assert.deepStrictEqual(updatedValues, []);
135+
assert.strictEqual(updatedValues, undefined);
118136
});
119137
});

0 commit comments

Comments
 (0)