mirror of
https://github.com/gradle/gradle-build-action.git
synced 2025-06-06 08:16:11 +02:00
Truncate Gradle args when constructing cache key (#71)
Cache keys have a hard limit of 512 characters, so we need to ensure that we don't generate a key longer than this. - Remove excess whitespace - Truncate to 400 characters Fixes #70
This commit is contained in:
parent
e0c2736e35
commit
b3afdc78a7
6 changed files with 45 additions and 13 deletions
|
@ -1,10 +1,10 @@
|
|||
import * as cryptoUtils from '../src/crypto-utils'
|
||||
import * as cacheUtils from '../src/cache-utils'
|
||||
import * as path from 'path'
|
||||
|
||||
describe('crypto-utils', () => {
|
||||
describe('cacheUtils-utils', () => {
|
||||
describe('can hash', () => {
|
||||
it('a directory', async () => {
|
||||
const hash = await cryptoUtils.hashFiles(
|
||||
const hash = await cacheUtils.hashFiles(
|
||||
path.resolve('__tests__/data/crypto-utils-test/gradle')
|
||||
)
|
||||
expect(hash).toBe(
|
||||
|
@ -14,7 +14,7 @@ describe('crypto-utils', () => {
|
|||
)
|
||||
})
|
||||
it('a directory with a glob', async () => {
|
||||
const hash = await cryptoUtils.hashFiles(
|
||||
const hash = await cacheUtils.hashFiles(
|
||||
path.resolve('__tests__/data/crypto-utils-test/'),
|
||||
['gradle/**']
|
||||
)
|
||||
|
@ -25,7 +25,7 @@ describe('crypto-utils', () => {
|
|||
)
|
||||
})
|
||||
it('a directory with globs', async () => {
|
||||
const hash = await cryptoUtils.hashFiles(
|
||||
const hash = await cacheUtils.hashFiles(
|
||||
path.resolve('__tests__/data/crypto-utils-test/'),
|
||||
['**/*.gradle', 'gradle/**']
|
||||
)
|
||||
|
@ -36,4 +36,30 @@ describe('crypto-utils', () => {
|
|||
)
|
||||
})
|
||||
})
|
||||
describe('can truncate args', () => {
|
||||
test('handles zero-length string', () => {
|
||||
expect(cacheUtils.truncateArgs('')).toBe('')
|
||||
})
|
||||
test('leaves short string untouched', () => {
|
||||
expect(
|
||||
cacheUtils.truncateArgs('short string that-should-be-untouched')
|
||||
).toBe('short string that-should-be-untouched')
|
||||
})
|
||||
test('truncates long string', () => {
|
||||
const longString = 'a'.repeat(500)
|
||||
expect(cacheUtils.truncateArgs(longString)).toBe('a'.repeat(400))
|
||||
})
|
||||
test('trims leading and trailing whitespace', () => {
|
||||
expect(cacheUtils.truncateArgs(' this is an arg ')).toBe(
|
||||
'this is an arg'
|
||||
)
|
||||
})
|
||||
test('removes repeated whitespace', () => {
|
||||
expect(
|
||||
cacheUtils.truncateArgs(
|
||||
' this one has long \t\n\t\r spaces '
|
||||
)
|
||||
).toBe('this one has long spaces')
|
||||
})
|
||||
})
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue