11import test from "ava" ;
2+ import sinon from "sinon" ;
23
4+ import { ActionsEnvVars } from "../actions-util" ;
5+ import { getTestEnv } from "../testing-utils" ;
36import { ConfigurationError } from "../util" ;
47
58import {
@@ -10,15 +13,17 @@ import {
1013} from "./remote-file" ;
1114
1215test ( "expandConfigFileInput accepts full remote addresses" , async ( t ) => {
13- t . deepEqual ( parseRemoteFileAddress ( "owner/repo/path@ref" ) , {
16+ const env = getTestEnv ( ) ;
17+
18+ t . deepEqual ( parseRemoteFileAddress ( env , "owner/repo/path@ref" ) , {
1419 owner : "owner" ,
1520 repo : "repo" ,
1621 path : "path" ,
1722 ref : "ref" ,
1823 } satisfies RemoteFileAddress ) ;
1924
2025 t . deepEqual (
21- parseRemoteFileAddress ( "owner/repo/path/to/codeql.yml@ref/feature" ) ,
26+ parseRemoteFileAddress ( env , "owner/repo/path/to/codeql.yml@ref/feature" ) ,
2227 {
2328 owner : "owner" ,
2429 repo : "repo" ,
@@ -29,14 +34,16 @@ test("expandConfigFileInput accepts full remote addresses", async (t) => {
2934} ) ;
3035
3136test ( "expandConfigFileInput accepts remote address without a path" , async ( t ) => {
32- t . deepEqual ( parseRemoteFileAddress ( "owner/repo@ref" ) , {
37+ const env = getTestEnv ( ) ;
38+
39+ t . deepEqual ( parseRemoteFileAddress ( env , "owner/repo@ref" ) , {
3340 owner : "owner" ,
3441 repo : "repo" ,
3542 path : DEFAULT_CONFIG_FILE_NAME ,
3643 ref : "ref" ,
3744 } satisfies RemoteFileAddress ) ;
3845
39- t . deepEqual ( parseRemoteFileAddress ( "owner/repo" ) , {
46+ t . deepEqual ( parseRemoteFileAddress ( env , "owner/repo" ) , {
4047 owner : "owner" ,
4148 repo : "repo" ,
4249 path : DEFAULT_CONFIG_FILE_NAME ,
@@ -45,14 +52,16 @@ test("expandConfigFileInput accepts remote address without a path", async (t) =>
4552} ) ;
4653
4754test ( "expandConfigFileInput accepts remote address without a ref" , async ( t ) => {
48- t . deepEqual ( parseRemoteFileAddress ( "owner/repo/path" ) , {
55+ const env = getTestEnv ( ) ;
56+
57+ t . deepEqual ( parseRemoteFileAddress ( env , "owner/repo/path" ) , {
4958 owner : "owner" ,
5059 repo : "repo" ,
5160 path : "path" ,
5261 ref : DEFAULT_CONFIG_FILE_REF ,
5362 } satisfies RemoteFileAddress ) ;
5463
55- t . deepEqual ( parseRemoteFileAddress ( "owner/repo/path@" ) , {
64+ t . deepEqual ( parseRemoteFileAddress ( env , "owner/repo/path@" ) , {
5665 owner : "owner" ,
5766 repo : "repo" ,
5867 path : "path" ,
@@ -61,13 +70,17 @@ test("expandConfigFileInput accepts remote address without a ref", async (t) =>
6170} ) ;
6271
6372test ( "expandConfigFileInput rejects invalid values" , async ( t ) => {
64- t . throws ( ( ) => parseRemoteFileAddress ( " " ) , {
65- instanceOf : ConfigurationError ,
66- } ) ;
67- t . throws ( ( ) => parseRemoteFileAddress ( "repo//absolute" ) , {
73+ const env = getTestEnv ( ) ;
74+ const owner = "owner" ;
75+ const getRequired = sinon . stub ( env , "getRequired" ) ;
76+ getRequired
77+ . withArgs ( ActionsEnvVars . GITHUB_REPOSITORY )
78+ . returns ( `${ owner } /current-repo` ) ;
79+
80+ t . throws ( ( ) => parseRemoteFileAddress ( env , " " ) , {
6881 instanceOf : ConfigurationError ,
6982 } ) ;
70- t . throws ( ( ) => parseRemoteFileAddress ( "repo:file.yml:unexpected " ) , {
83+ t . throws ( ( ) => parseRemoteFileAddress ( env , "repo//absolute " ) , {
7184 instanceOf : ConfigurationError ,
7285 } ) ;
7386} ) ;
0 commit comments