Skip to content

Commit 29cf23b

Browse files
committed
Added storage test for extension auth
Signed-off-by: Seb Julliand <[email protected]>
1 parent a4d7a4a commit 29cf23b

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/testing/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { ContentSuite } from "./content";
77
import { DeployToolsSuite } from "./deployTools";
88
import { FilterSuite } from "./filter";
99
import { ILEErrorSuite } from "./ileErrors";
10+
import { StorageSuite } from "./storage";
1011
import { TestSuitesTreeProvider } from "./testCasesTree";
1112
import { ToolsSuite } from "./tools";
1213

@@ -17,7 +18,8 @@ const suites: TestSuite[] = [
1718
DeployToolsSuite,
1819
ToolsSuite,
1920
ILEErrorSuite,
20-
FilterSuite
21+
FilterSuite,
22+
StorageSuite
2123
]
2224

2325
export type TestSuite = {

src/testing/storage.ts

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import assert from "assert";
2+
import vscode from "vscode";
3+
import { TestSuite } from ".";
4+
import { instance } from "../instantiate";
5+
6+
export const StorageSuite: TestSuite = {
7+
name: `Extension storage tests`,
8+
tests: [
9+
{
10+
name: "Authorized extensions", test: async () => {
11+
const storage = instance.getStorage();
12+
if(storage){
13+
const extension = vscode.extensions.getExtension("halcyontechltd.code-for-ibmi")!;
14+
try{
15+
let auth = storage.getExtensionAuthorisation(extension);
16+
assert.strictEqual(undefined, auth, "Extension is already authorized");
17+
storage.grantExtensionAuthorisation(extension);
18+
19+
auth = storage.getExtensionAuthorisation(extension);
20+
assert.ok(auth, "Authorisation not found");
21+
assert.strictEqual(new Date(auth.since).toDateString(), new Date().toDateString(), "Access date must be today");
22+
23+
const lastAccess = auth.lastAccess;
24+
await new Promise(r => setTimeout(r, 100)); //Wait a bit
25+
auth = storage.getExtensionAuthorisation(extension);
26+
assert.ok(auth, "Authorisation not found");
27+
assert.notStrictEqual(lastAccess, auth.lastAccess, "Last access did not change")
28+
}
29+
finally{
30+
const auth = storage.getExtensionAuthorisation(extension);
31+
if(auth){
32+
storage.revokeExtensionAuthorisation(auth);
33+
}
34+
}
35+
}
36+
else{
37+
throw Error("Cannot run test: no storage")
38+
}
39+
}
40+
}
41+
]
42+
}

0 commit comments

Comments
 (0)