11import * as fs from "fs" ;
2+ import path from "path" ;
23
34import test from "ava" ;
45
5- import { EnvVar } from "../environment" ;
66import { getRunnerLogger } from "../logging" ;
7- import { getTestEnv , setupTests } from "../testing-utils" ;
7+ import { setupTests } from "../testing-utils" ;
88import * as util from "../util" ;
99
10- import {
11- getCachedCodeQlVersion ,
12- getCommandCacheFilePath ,
13- } from "./output-cache" ;
10+ import { getCachedCodeQlVersion } from "./output-cache" ;
1411
1512setupTests ( test ) ;
1613
@@ -20,19 +17,22 @@ test.serial(
2017 "getCachedCodeQlVersion reuses a version persisted by an earlier step" ,
2118 async ( t ) => {
2219 await util . withTmpDir ( async ( tmpDir : string ) => {
23- const env = getTestEnv ( { [ EnvVar . TEMP ] : tmpDir } ) ;
24- const cacheFile = getCommandCacheFilePath ( env ) ;
20+ const cacheFilePath = path . join ( tmpDir , "cache.json" ) ;
21+
2522 fs . writeFileSync (
26- cacheFile ,
23+ cacheFilePath ,
2724 JSON . stringify ( {
2825 cmd : "/path/to/codeql" ,
2926 entries : { version : { version : "2.20.0" } } ,
3027 } ) ,
3128 "utf8" ,
3229 ) ;
33- t . deepEqual ( getCachedCodeQlVersion ( logger , env , "/path/to/codeql" ) , {
34- version : "2.20.0" ,
35- } ) ;
30+ t . deepEqual (
31+ getCachedCodeQlVersion ( logger , cacheFilePath , "/path/to/codeql" ) ,
32+ {
33+ version : "2.20.0" ,
34+ } ,
35+ ) ;
3636 } ) ;
3737 } ,
3838) ;
@@ -41,17 +41,19 @@ test.serial(
4141 "getCachedCodeQlVersion ignores a persisted version from a different CLI" ,
4242 async ( t ) => {
4343 await util . withTmpDir ( async ( tmpDir : string ) => {
44- const env = getTestEnv ( { [ EnvVar . TEMP ] : tmpDir } ) ;
45- const cacheFile = getCommandCacheFilePath ( env ) ;
44+ const cacheFilePath = path . join ( tmpDir , "cache.json" ) ;
4645 fs . writeFileSync (
47- cacheFile ,
46+ cacheFilePath ,
4847 JSON . stringify ( {
4948 cmd : "/path/to/other-codeql" ,
5049 entries : { version : { version : "2.20.0" } } ,
5150 } ) ,
5251 "utf8" ,
5352 ) ;
54- t . is ( getCachedCodeQlVersion ( logger , env , "/path/to/codeql" ) , undefined ) ;
53+ t . is (
54+ getCachedCodeQlVersion ( logger , cacheFilePath , "/path/to/codeql" ) ,
55+ undefined ,
56+ ) ;
5557 } ) ;
5658 } ,
5759) ;
@@ -60,10 +62,12 @@ test.serial(
6062 "getCachedCodeQlVersion ignores a malformed persisted value" ,
6163 async ( t ) => {
6264 await util . withTmpDir ( async ( tmpDir : string ) => {
63- const env = getTestEnv ( { [ EnvVar . TEMP ] : tmpDir } ) ;
64- const cacheFile = getCommandCacheFilePath ( env ) ;
65- fs . writeFileSync ( cacheFile , "not valid json" , "utf8" ) ;
66- t . is ( getCachedCodeQlVersion ( logger , env , "/path/to/codeql" ) , undefined ) ;
65+ const cacheFilePath = path . join ( tmpDir , "cache.json" ) ;
66+ fs . writeFileSync ( cacheFilePath , "not valid json" , "utf8" ) ;
67+ t . is (
68+ getCachedCodeQlVersion ( logger , cacheFilePath , "/path/to/codeql" ) ,
69+ undefined ,
70+ ) ;
6771 } ) ;
6872 } ,
6973) ;
@@ -72,8 +76,7 @@ test.serial(
7276 "getCachedCodeQlVersion ignores a persisted value with the wrong structure" ,
7377 async ( t ) => {
7478 await util . withTmpDir ( async ( tmpDir : string ) => {
75- const env = getTestEnv ( { [ EnvVar . TEMP ] : tmpDir } ) ;
76- const cacheFile = getCommandCacheFilePath ( env ) ;
79+ const cacheFilePath = path . join ( tmpDir , "cache.json" ) ;
7780 const testValues = [
7881 { cmd : "/path/to/codeql" } ,
7982 { entries : { version : { version : "2.20.0" } } } ,
@@ -96,9 +99,9 @@ test.serial(
9699 ] . map ( ( v ) => JSON . stringify ( v ) ) ;
97100
98101 for ( const value of testValues ) {
99- fs . writeFileSync ( cacheFile , value , "utf8" ) ;
102+ fs . writeFileSync ( cacheFilePath , value , "utf8" ) ;
100103 t . is (
101- getCachedCodeQlVersion ( logger , env , "/path/to/codeql" ) ,
104+ getCachedCodeQlVersion ( logger , cacheFilePath , "/path/to/codeql" ) ,
102105 undefined ,
103106 value ,
104107 ) ;
@@ -109,9 +112,12 @@ test.serial(
109112
110113test . serial ( "getCachedCodeQlVersion ignores non-existent file" , async ( t ) => {
111114 await util . withTmpDir ( async ( tmpDir : string ) => {
112- const env = getTestEnv ( { [ EnvVar . TEMP ] : tmpDir } ) ;
115+ const cacheFilePath = path . join ( tmpDir , "cache.json" ) ;
113116 t . notThrows ( ( ) => {
114- t . is ( getCachedCodeQlVersion ( logger , env , "/path/to/codeql" ) , undefined ) ;
117+ t . is (
118+ getCachedCodeQlVersion ( logger , cacheFilePath , "/path/to/codeql" ) ,
119+ undefined ,
120+ ) ;
115121 } ) ;
116122 } ) ;
117123} ) ;
0 commit comments