@@ -3,7 +3,8 @@ import * as core from '@actions/core';
33import {
44 convertVersionToSemver ,
55 isVersionSatisfies ,
6- isCacheFeatureAvailable
6+ isCacheFeatureAvailable ,
7+ isGhes
78} from '../src/util' ;
89
910jest . mock ( '@actions/cache' ) ;
@@ -80,3 +81,41 @@ describe('convertVersionToSemver', () => {
8081 expect ( actual ) . toBe ( expected ) ;
8182 } ) ;
8283} ) ;
84+
85+ describe ( 'isGhes' , ( ) => {
86+ const pristineEnv = process . env ;
87+
88+ beforeEach ( ( ) => {
89+ jest . resetModules ( ) ;
90+ process . env = { ...pristineEnv } ;
91+ } ) ;
92+
93+ afterAll ( ( ) => {
94+ process . env = pristineEnv ;
95+ } ) ;
96+
97+ it ( 'returns false when the GITHUB_SERVER_URL environment variable is not defined' , async ( ) => {
98+ delete process . env [ 'GITHUB_SERVER_URL' ] ;
99+ expect ( isGhes ( ) ) . toBeFalsy ( ) ;
100+ } ) ;
101+
102+ it ( 'returns false when the GITHUB_SERVER_URL environment variable is set to github.com' , async ( ) => {
103+ process . env [ 'GITHUB_SERVER_URL' ] = 'https://github.com' ;
104+ expect ( isGhes ( ) ) . toBeFalsy ( ) ;
105+ } ) ;
106+
107+ it ( 'returns false when the GITHUB_SERVER_URL environment variable is set to a GitHub Enterprise Cloud-style URL' , async ( ) => {
108+ process . env [ 'GITHUB_SERVER_URL' ] = 'https://contoso.ghe.com' ;
109+ expect ( isGhes ( ) ) . toBeFalsy ( ) ;
110+ } ) ;
111+
112+ it ( 'returns false when the GITHUB_SERVER_URL environment variable has a .localhost suffix' , async ( ) => {
113+ process . env [ 'GITHUB_SERVER_URL' ] = 'https://mock-github.localhost' ;
114+ expect ( isGhes ( ) ) . toBeFalsy ( ) ;
115+ } ) ;
116+
117+ it ( 'returns true when the GITHUB_SERVER_URL environment variable is set to some other URL' , async ( ) => {
118+ process . env [ 'GITHUB_SERVER_URL' ] = 'https://src.onpremise.fabrikam.com' ;
119+ expect ( isGhes ( ) ) . toBeTruthy ( ) ;
120+ } ) ;
121+ } ) ;
0 commit comments