From 1d333e3853b781ee61a2820bc07b8e732efd0538 Mon Sep 17 00:00:00 2001 From: John Wesley Walker III <81404201+jww3@users.noreply.github.com> Date: Fri, 18 Oct 2024 16:59:28 +0000 Subject: [PATCH] add unit test --- __tests__/utils.test.ts | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/__tests__/utils.test.ts b/__tests__/utils.test.ts index c2c6bca5..057a781c 100644 --- a/__tests__/utils.test.ts +++ b/__tests__/utils.test.ts @@ -13,6 +13,7 @@ import { getVersionInputFromPlainFile, getVersionInputFromTomlFile, getNextPageUrl, + isGhes, IS_WINDOWS, getDownloadFileName } from '../src/utils'; @@ -195,3 +196,42 @@ describe('getDownloadFileName', () => { } }); }); + + +describe('isGhes', () => { + const pristineEnv = process.env; + + beforeEach(() => { + jest.resetModules(); + process.env = { ...pristineEnv }; + }); + + afterAll(() => { + process.env = pristineEnv; + }); + + it('returns false when the GITHUB_SERVER_URL environment variable is not defined', async () => { + delete process.env['GITHUB_SERVER_URL']; + expect(isGhes()).toBeFalsy(); + }); + + it('returns false when the GITHUB_SERVER_URL environment variable is set to github.com', async () => { + process.env['GITHUB_SERVER_URL'] = 'https://github.com'; + expect(isGhes()).toBeFalsy(); + }); + + it('returns false when the GITHUB_SERVER_URL environment variable is set to a GitHub Enterprise Cloud-style URL', async () => { + process.env['GITHUB_SERVER_URL'] = 'https://contoso.ghe.com'; + expect(isGhes()).toBeFalsy(); + }); + + it('returns false when the GITHUB_SERVER_URL environment variable has a .localhost suffix', async () => { + process.env['GITHUB_SERVER_URL'] = 'https://mock-github.localhost'; + expect(isGhes()).toBeFalsy(); + }); + + it('returns true when the GITHUB_SERVER_URL environment variable is set to some other URL', async () => { + process.env['GITHUB_SERVER_URL'] = 'https://src.onpremise.fabrikam.com'; + expect(isGhes()).toBeTruthy(); + }); +});