mirror of
				https://github.com/gradle/gradle-build-action.git
				synced 2025-11-04 01:28:56 +08:00 
			
		
		
		
	Generate cache key based on Job invocation
Attempt to capture as much context as possible about the job run to generate a unique cache key. Unfortunately much of the matrix context is not available to the action implementation.
This commit is contained in:
		@@ -2,30 +2,14 @@ import * as cacheUtils from '../src/cache-utils'
 | 
			
		||||
import * as path from 'path'
 | 
			
		||||
 | 
			
		||||
describe('cacheUtils-utils', () => {
 | 
			
		||||
    describe('can truncate args', () => {
 | 
			
		||||
        test('handles zero-length string', () => {
 | 
			
		||||
            expect(cacheUtils.truncateArgs('')).toBe('')
 | 
			
		||||
    describe('can hash', () => {
 | 
			
		||||
        it('a string', async () => {
 | 
			
		||||
            const hash = cacheUtils.hashStrings(['foo'])
 | 
			
		||||
            expect(hash).toBe('acbd18db4cc2f85cedef654fccc4a4d8')
 | 
			
		||||
        })
 | 
			
		||||
        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')
 | 
			
		||||
        it('multiple strings', async () => {
 | 
			
		||||
            const hash = cacheUtils.hashStrings(['foo', 'bar', 'baz'])
 | 
			
		||||
            expect(hash).toBe('6df23dc03f9b54cc38a0fc1483df6e21')
 | 
			
		||||
        })
 | 
			
		||||
    })
 | 
			
		||||
})
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user