@@ -3,12 +3,11 @@ import path from "path";
33
44import test from "ava" ;
55
6- import { EnvVar } from "../environment" ;
76import { getRunnerLogger } from "../logging" ;
8- import { getTestEnv , setupTests } from "../testing-utils" ;
7+ import { setupTests } from "../testing-utils" ;
98import * as util from "../util" ;
109
11- import * as outputCache from "./output-cache" ;
10+ import { getCachedCodeQlVersion } from "./output-cache" ;
1211
1312setupTests ( test ) ;
1413
@@ -18,18 +17,18 @@ test.serial(
1817 "getCachedCodeQlVersion reuses a version persisted by an earlier step" ,
1918 async ( t ) => {
2019 await util . withTmpDir ( async ( tmpDir : string ) => {
21- const cacheFile = path . join ( tmpDir , "codeql-action-command-cache.json" ) ;
20+ const cacheFilePath = path . join ( tmpDir , "cache.json" ) ;
21+
2222 fs . writeFileSync (
23- cacheFile ,
23+ cacheFilePath ,
2424 JSON . stringify ( {
2525 cmd : "/path/to/codeql" ,
2626 entries : { version : { version : "2.20.0" } } ,
2727 } ) ,
2828 "utf8" ,
2929 ) ;
30- const env = getTestEnv ( { [ EnvVar . TEMP ] : tmpDir } ) ;
3130 t . deepEqual (
32- outputCache . getCachedCodeQlVersion ( logger , env , "/path/to/codeql" ) ,
31+ getCachedCodeQlVersion ( logger , cacheFilePath , "/path/to/codeql" ) ,
3332 {
3433 version : "2.20.0" ,
3534 } ,
@@ -42,18 +41,17 @@ test.serial(
4241 "getCachedCodeQlVersion ignores a persisted version from a different CLI" ,
4342 async ( t ) => {
4443 await util . withTmpDir ( async ( tmpDir : string ) => {
45- const cacheFile = path . join ( tmpDir , "version .json" ) ;
44+ const cacheFilePath = path . join ( tmpDir , "cache .json" ) ;
4645 fs . writeFileSync (
47- cacheFile ,
46+ cacheFilePath ,
4847 JSON . stringify ( {
4948 cmd : "/path/to/other-codeql" ,
50- version : { version : "2.20.0" } ,
49+ entries : { version : { version : "2.20.0" } } ,
5150 } ) ,
5251 "utf8" ,
5352 ) ;
54- const env = getTestEnv ( { [ EnvVar . TEMP ] : tmpDir } ) ;
5553 t . is (
56- outputCache . getCachedCodeQlVersion ( logger , env , "/path/to/codeql" ) ,
54+ getCachedCodeQlVersion ( logger , cacheFilePath , "/path/to/codeql" ) ,
5755 undefined ,
5856 ) ;
5957 } ) ;
@@ -64,11 +62,10 @@ test.serial(
6462 "getCachedCodeQlVersion ignores a malformed persisted value" ,
6563 async ( t ) => {
6664 await util . withTmpDir ( async ( tmpDir : string ) => {
67- const cacheFile = path . join ( tmpDir , "version.json" ) ;
68- fs . writeFileSync ( cacheFile , "not valid json" , "utf8" ) ;
69- const env = getTestEnv ( { [ EnvVar . TEMP ] : tmpDir } ) ;
65+ const cacheFilePath = path . join ( tmpDir , "cache.json" ) ;
66+ fs . writeFileSync ( cacheFilePath , "not valid json" , "utf8" ) ;
7067 t . is (
71- outputCache . getCachedCodeQlVersion ( logger , env , "/path/to/codeql" ) ,
68+ getCachedCodeQlVersion ( logger , cacheFilePath , "/path/to/codeql" ) ,
7269 undefined ,
7370 ) ;
7471 } ) ;
@@ -79,9 +76,7 @@ test.serial(
7976 "getCachedCodeQlVersion ignores a persisted value with the wrong structure" ,
8077 async ( t ) => {
8178 await util . withTmpDir ( async ( tmpDir : string ) => {
82- const cacheFile = path . join ( tmpDir , "version.json" ) ;
83- const env = getTestEnv ( { [ EnvVar . TEMP ] : tmpDir } ) ;
84-
79+ const cacheFilePath = path . join ( tmpDir , "cache.json" ) ;
8580 const testValues = [
8681 { cmd : "/path/to/codeql" } ,
8782 { entries : { version : { version : "2.20.0" } } } ,
@@ -104,9 +99,9 @@ test.serial(
10499 ] . map ( ( v ) => JSON . stringify ( v ) ) ;
105100
106101 for ( const value of testValues ) {
107- fs . writeFileSync ( cacheFile , value , "utf8" ) ;
102+ fs . writeFileSync ( cacheFilePath , value , "utf8" ) ;
108103 t . is (
109- outputCache . getCachedCodeQlVersion ( logger , env , "/path/to/codeql" ) ,
104+ getCachedCodeQlVersion ( logger , cacheFilePath , "/path/to/codeql" ) ,
110105 undefined ,
111106 value ,
112107 ) ;
@@ -117,10 +112,10 @@ test.serial(
117112
118113test . serial ( "getCachedCodeQlVersion ignores non-existent file" , async ( t ) => {
119114 await util . withTmpDir ( async ( tmpDir : string ) => {
120- const env = getTestEnv ( { [ EnvVar . TEMP ] : tmpDir } ) ;
115+ const cacheFilePath = path . join ( tmpDir , "cache.json" ) ;
121116 t . notThrows ( ( ) => {
122117 t . is (
123- outputCache . getCachedCodeQlVersion ( logger , env , "/path/to/codeql" ) ,
118+ getCachedCodeQlVersion ( logger , cacheFilePath , "/path/to/codeql" ) ,
124119 undefined ,
125120 ) ;
126121 } ) ;
0 commit comments