@@ -8,6 +8,7 @@ import { setupTests } from "../testing-utils";
88
99import {
1010 cacheCommandOutput ,
11+ CommandCacheKey ,
1112 getCachedCommandOutput ,
1213 resetCachedCommandOutputs ,
1314 type VersionInfo ,
@@ -51,16 +52,13 @@ test.serial(
5152 async ( t ) => {
5253 await withCacheDir ( ( cacheFilePath ) => {
5354 writeCacheFile ( cacheFilePath , {
54- version : {
55+ [ CommandCacheKey . Version ] : {
5556 cmd : "/path/to/codeql" ,
5657 output : { version : "2.20.0" } ,
5758 } ,
5859 } ) ;
5960 t . deepEqual (
60- getCachedCommandOutput (
61- "version" ,
62- "/path/to/codeql" ,
63- ) ,
61+ getCachedCommandOutput ( CommandCacheKey . Version , "/path/to/codeql" ) ,
6462 { version : "2.20.0" } ,
6563 ) ;
6664 } ) ;
@@ -72,16 +70,13 @@ test.serial(
7270 async ( t ) => {
7371 await withCacheDir ( ( cacheFilePath ) => {
7472 writeCacheFile ( cacheFilePath , {
75- version : {
73+ [ CommandCacheKey . Version ] : {
7674 cmd : "/path/to/other-codeql" ,
7775 output : { version : "2.20.0" } ,
7876 } ,
7977 } ) ;
8078 t . is (
81- getCachedCommandOutput (
82- "version" ,
83- "/path/to/codeql" ,
84- ) ,
79+ getCachedCommandOutput ( CommandCacheKey . Version , "/path/to/codeql" ) ,
8580 undefined ,
8681 ) ;
8782 } ) ;
@@ -94,10 +89,7 @@ test.serial(
9489 await withCacheDir ( ( cacheFilePath ) => {
9590 fs . writeFileSync ( cacheFilePath , "not valid json" ) ;
9691 t . is (
97- getCachedCommandOutput (
98- "version" ,
99- "/path/to/codeql" ,
100- ) ,
92+ getCachedCommandOutput ( CommandCacheKey . Version , "/path/to/codeql" ) ,
10193 undefined ,
10294 ) ;
10395 } ) ;
@@ -109,10 +101,7 @@ test.serial(
109101 async ( t ) => {
110102 await withCacheDir ( ( ) => {
111103 t . is (
112- getCachedCommandOutput (
113- "version" ,
114- "/path/to/codeql" ,
115- ) ,
104+ getCachedCommandOutput ( CommandCacheKey . Version , "/path/to/codeql" ) ,
116105 undefined ,
117106 ) ;
118107 } ) ;
@@ -131,13 +120,10 @@ test.serial(
131120 ] ) {
132121 resetCachedCommandOutputs ( ) ;
133122 writeCacheFile ( cacheFilePath , {
134- version : { cmd : "/path/to/codeql" , output } ,
123+ [ CommandCacheKey . Version ] : { cmd : "/path/to/codeql" , output } ,
135124 } ) ;
136125 t . is (
137- getCachedCommandOutput (
138- "version" ,
139- "/path/to/codeql" ,
140- ) ,
126+ getCachedCommandOutput ( CommandCacheKey . Version , "/path/to/codeql" ) ,
141127 undefined ,
142128 JSON . stringify ( output ) ,
143129 ) ;
@@ -151,13 +137,10 @@ test.serial(
151137 async ( t ) => {
152138 await withCacheDir ( ( cacheFilePath ) => {
153139 writeCacheFile ( cacheFilePath , {
154- version : { output : { version : "2.20.0" } } ,
140+ [ CommandCacheKey . Version ] : { output : { version : "2.20.0" } } ,
155141 } ) ;
156142 t . is (
157- getCachedCommandOutput (
158- "version" ,
159- "/path/to/codeql" ,
160- ) ,
143+ getCachedCommandOutput ( CommandCacheKey . Version , "/path/to/codeql" ) ,
161144 undefined ,
162145 ) ;
163146 } ) ;
@@ -167,10 +150,13 @@ test.serial(
167150test . serial ( "cacheCommandOutput persists the output to the memo" , async ( t ) => {
168151 await withCacheDir ( ( ) => {
169152 const output : VersionInfo = { version : "2.20.0" } ;
170- cacheCommandOutput ( "version" , "/path/to/codeql" , output ) ;
153+ cacheCommandOutput ( CommandCacheKey . Version , "/path/to/codeql" , output ) ;
171154
172155 // Tier 1: the value is immediately available from the memo.
173- t . deepEqual ( getCachedCommandOutput ( "version" , "/path/to/codeql" ) , output ) ;
156+ t . deepEqual (
157+ getCachedCommandOutput ( CommandCacheKey . Version , "/path/to/codeql" ) ,
158+ output ,
159+ ) ;
174160 } ) ;
175161} ) ;
176162
@@ -179,16 +165,19 @@ test.serial(
179165 async ( t ) => {
180166 await withCacheDir ( ( cacheFilePath ) => {
181167 const output : VersionInfo = { version : "2.20.0" , overlayVersion : 1 } ;
182- cacheCommandOutput ( "version" , "/path/to/codeql" , output ) ;
168+ cacheCommandOutput ( CommandCacheKey . Version , "/path/to/codeql" , output ) ;
183169
184170 // Overwrite the file with a different value; the memo (tier 1) should win.
185171 writeCacheFile ( cacheFilePath , {
186- version : {
172+ [ CommandCacheKey . Version ] : {
187173 cmd : "/path/to/codeql" ,
188174 output : { version : "2.21.0" } ,
189175 } ,
190176 } ) ;
191- t . deepEqual ( getCachedCommandOutput ( "version" , "/path/to/codeql" ) , output ) ;
177+ t . deepEqual (
178+ getCachedCommandOutput ( CommandCacheKey . Version , "/path/to/codeql" ) ,
179+ output ,
180+ ) ;
192181 } ) ;
193182 } ,
194183) ;
0 commit comments