@@ -11,22 +11,110 @@ import {
1111 resolveQuerySuiteAlias ,
1212 addSarifExtension ,
1313 diffRangeExtensionPackContents ,
14+ determineCheckoutPath ,
1415} from "./analyze" ;
1516import { createStubCodeQL } from "./codeql" ;
1617import { Feature } from "./feature-flags" ;
18+ import * as gitUtils from "./git-utils" ;
1719import { BuiltInLanguage } from "./languages" ;
1820import { getRunnerLogger } from "./logging" ;
1921import {
2022 setupTests ,
2123 setupActionsVars ,
2224 createFeatures ,
2325 createTestConfig ,
26+ callee ,
2427} from "./testing-utils" ;
2528import * as uploadLib from "./upload-lib" ;
2629import * as util from "./util" ;
2730
2831setupTests ( test ) ;
2932
33+ test . serial (
34+ "determineCheckoutPath - logs when checkout_path is not in a work tree" ,
35+ async ( t ) => {
36+ const expectedPath = "/checkout/path" ;
37+ const target = callee ( determineCheckoutPath )
38+ . withActions ( ( actions ) => {
39+ sinon
40+ . stub ( actions , "getRequiredInput" )
41+ . withArgs ( "checkout_path" )
42+ . returns ( "/checkout/path" ) ;
43+ } )
44+ . withArgs ( createTestConfig ( { } ) ) ;
45+ sinon . stub ( gitUtils , "getGitRoot" ) . resolves ( undefined ) ;
46+
47+ await target
48+ . logs ( t , "is not in the work tree of a git repository" )
49+ . passes ( t . is , expectedPath ) ;
50+ } ,
51+ ) ;
52+
53+ test . serial (
54+ "determineCheckoutPath - logs when checkout_path is not a repo root" ,
55+ async ( t ) => {
56+ const expectedPath = "/checkout/path" ;
57+ const target = callee ( determineCheckoutPath )
58+ . withActions ( ( actions ) => {
59+ sinon
60+ . stub ( actions , "getRequiredInput" )
61+ . withArgs ( "checkout_path" )
62+ . returns ( "/checkout/path" ) ;
63+ } )
64+ . withArgs ( createTestConfig ( { } ) ) ;
65+ sinon . stub ( gitUtils , "getGitRoot" ) . resolves ( "/checkout" ) ;
66+
67+ await target
68+ . logs ( t , "is not the root of the repository" )
69+ . passes ( t . is , expectedPath ) ;
70+ } ,
71+ ) ;
72+
73+ test . serial (
74+ "determineCheckoutPath - logs when checkout_path is not the same as repo root in config" ,
75+ async ( t ) => {
76+ const expectedPath = "/checkout/path" ;
77+ const target = callee ( determineCheckoutPath )
78+ . withActions ( ( actions ) => {
79+ sinon
80+ . stub ( actions , "getRequiredInput" )
81+ . withArgs ( "checkout_path" )
82+ . returns ( "/checkout/path" ) ;
83+ } )
84+ . withArgs ( createTestConfig ( { repositoryRoot : "/some/other/path" } ) ) ;
85+ sinon . stub ( gitUtils , "getGitRoot" ) . resolves ( "/checkout/path" ) ;
86+
87+ await target
88+ . logs ( t , "does not match that found by the 'codeql-action/init' step" )
89+ . passes ( t . is , expectedPath ) ;
90+ } ,
91+ ) ;
92+
93+ test . serial (
94+ "determineCheckoutPath - doesn't log any of the messages when all is as expected" ,
95+ async ( t ) => {
96+ const expectedPath = "/checkout/path" ;
97+ const target = callee ( determineCheckoutPath )
98+ . withActions ( ( actions ) => {
99+ sinon
100+ . stub ( actions , "getRequiredInput" )
101+ . withArgs ( "checkout_path" )
102+ . returns ( "/checkout/path" ) ;
103+ } )
104+ . withArgs ( createTestConfig ( { repositoryRoot : "/checkout/path" } ) ) ;
105+ sinon . stub ( gitUtils , "getGitRoot" ) . resolves ( "/checkout/path" ) ;
106+
107+ await target
108+ . notLogs (
109+ t ,
110+ "is not in the work tree of a git repository" ,
111+ "is not the root of the repository" ,
112+ "does not match that found by the 'codeql-action/init' step" ,
113+ )
114+ . passes ( t . is , expectedPath ) ;
115+ } ,
116+ ) ;
117+
30118/**
31119 * Checks the status report produced by the analyze Action.
32120 *
0 commit comments