@@ -3,15 +3,17 @@ import * as sinon from "sinon";
33
44import * as actionsUtil from "./actions-util" ;
55import { Config } from "./config-utils" ;
6- import { EnvVar } from "./environment" ;
6+ import { EnvVar , RegistryProxyVars } from "./environment" ;
77import { BuiltInLanguage } from "./languages" ;
88import { getRunnerLogger } from "./logging" ;
99import { ToolsSource } from "./setup-codeql" ;
10+ import type { Registry } from "./start-proxy" ;
1011import {
1112 ActionName ,
1213 createInitWithConfigStatusReport ,
1314 createStatusReportBase ,
1415 getActionsStatus ,
16+ getRegistryTypesFromEnv ,
1517 InitStatusReport ,
1618 InitWithConfigStatusReport ,
1719} from "./status-report" ;
@@ -20,11 +22,54 @@ import {
2022 setupActionsVars ,
2123 createTestConfig ,
2224 makeMacro ,
25+ getTestEnv ,
26+ RecordingLogger ,
2327} from "./testing-utils" ;
2428import { BuildMode , ConfigurationError , withTmpDir , wrapError } from "./util" ;
2529
2630setupTests ( test ) ;
2731
32+ test ( "getRegistryTypesFromEnv - gets unique registry types from environment" , async ( t ) => {
33+ const logger = new RecordingLogger ( true ) ;
34+ const env = getTestEnv ( {
35+ [ RegistryProxyVars . PROXY_URLS ] : JSON . stringify ( [
36+ { type : "git_source" , url : "https://example.com" } ,
37+ { type : "git_source" , url : "https://github.com" } ,
38+ { type : "docker_registry" , url : "https://registry.example.com" } ,
39+ ] satisfies Array < Partial < Registry > > ) ,
40+ } ) ;
41+
42+ const result = getRegistryTypesFromEnv ( logger , env ) ;
43+ t . deepEqual ( result , [ "git_source" , "docker_registry" ] . sort ( ) . join ( "," ) ) ;
44+ } ) ;
45+
46+ test ( "getRegistryTypesFromEnv - returns undefined if the env var is not set" , async ( t ) => {
47+ const logger = new RecordingLogger ( true ) ;
48+ const env = getTestEnv ( { } ) ;
49+
50+ const result = getRegistryTypesFromEnv ( logger , env ) ;
51+ t . is ( result , undefined ) ;
52+ } ) ;
53+
54+ test ( "getRegistryTypesFromEnv - returns undefined if the env var is not valid JSON" , async ( t ) => {
55+ const logger = new RecordingLogger ( true ) ;
56+ const env = getTestEnv ( { [ RegistryProxyVars . PROXY_URLS ] : "[" } ) ;
57+
58+ const result = getRegistryTypesFromEnv ( logger , env ) ;
59+ t . is ( result , undefined ) ;
60+ } ) ;
61+
62+ test ( "getRegistryTypesFromEnv - returns undefined if the env var is unexpected JSON" , async ( t ) => {
63+ const logger = new RecordingLogger ( true ) ;
64+ const env = getTestEnv ( {
65+ // Top-level object rather than an array of objects.
66+ [ RegistryProxyVars . PROXY_URLS ] : JSON . stringify ( { type : "git_source" } ) ,
67+ } ) ;
68+
69+ const result = getRegistryTypesFromEnv ( logger , env ) ;
70+ t . is ( result , undefined ) ;
71+ } ) ;
72+
2873function setupEnvironmentAndStub ( tmpDir : string ) {
2974 setupActionsVars ( tmpDir , tmpDir , {
3075 GITHUB_EVENT_NAME : "dynamic" ,
0 commit comments