2024-11-21 04:01:44 -08:00
|
|
|
import * as config from '../src/internal/config'
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2024-11-21 04:05:04 -08:00
|
|
|
jest.resetModules()
|
2024-11-21 04:01:44 -08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('isGhes returns false for github.com', async () => {
|
2024-11-21 04:05:04 -08:00
|
|
|
process.env.GITHUB_SERVER_URL = 'https://github.com'
|
|
|
|
|
expect(config.isGhes()).toBe(false)
|
2024-11-21 04:01:44 -08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('isGhes returns false for ghe.com', async () => {
|
2024-11-21 04:05:04 -08:00
|
|
|
process.env.GITHUB_SERVER_URL = 'https://somedomain.ghe.com'
|
|
|
|
|
expect(config.isGhes()).toBe(false)
|
2024-11-21 04:01:44 -08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('isGhes returns true for enterprise URL', async () => {
|
2024-11-21 04:05:04 -08:00
|
|
|
process.env.GITHUB_SERVER_URL = 'https://my-enterprise.github.com'
|
|
|
|
|
expect(config.isGhes()).toBe(true)
|
2024-11-21 04:01:44 -08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('isGhes returns false for ghe.localhost', () => {
|
2024-11-21 04:05:04 -08:00
|
|
|
process.env.GITHUB_SERVER_URL = 'https://my.domain.ghe.localhost'
|
|
|
|
|
expect(config.isGhes()).toBe(false)
|
2024-11-21 04:01:44 -08:00
|
|
|
})
|
2026-07-13 10:03:16 -05:00
|
|
|
|
|
|
|
|
describe('cache-mode helpers', () => {
|
|
|
|
|
const original = process.env.ACTIONS_CACHE_MODE
|
|
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
|
if (original === undefined) {
|
|
|
|
|
delete process.env.ACTIONS_CACHE_MODE
|
|
|
|
|
} else {
|
|
|
|
|
process.env.ACTIONS_CACHE_MODE = original
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('getCacheMode normalizes whitespace and case', () => {
|
|
|
|
|
process.env.ACTIONS_CACHE_MODE = ' Write-Only '
|
|
|
|
|
expect(config.getCacheMode()).toBe('write-only')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('getCacheMode returns empty string when unset', () => {
|
|
|
|
|
delete process.env.ACTIONS_CACHE_MODE
|
|
|
|
|
expect(config.getCacheMode()).toBe('')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test.each([
|
|
|
|
|
['', true, true],
|
|
|
|
|
['read', true, false],
|
|
|
|
|
['write', true, true],
|
|
|
|
|
['write-only', false, true],
|
|
|
|
|
['none', false, false],
|
|
|
|
|
['garbage', true, true]
|
|
|
|
|
])("mode '%s' -> readable=%s writable=%s", (mode, readable, writable) => {
|
|
|
|
|
expect(config.isCacheReadable(mode)).toBe(readable)
|
|
|
|
|
expect(config.isCacheWritable(mode)).toBe(writable)
|
|
|
|
|
})
|
|
|
|
|
})
|