mirror of
				https://github.com/actions/cache.git
				synced 2025-11-04 15:48:39 +08:00 
			
		
		
		
	Add save-always inpute/output test
This commit is contained in:
		
							parent
							
								
									f04cc738d7
								
							
						
					
					
						commit
						faaa3912ca
					
				| 
						 | 
				
			
			@ -489,3 +489,40 @@ test("restore failure with earlyExit should call process exit", async () => {
 | 
			
		|||
    );
 | 
			
		||||
    expect(processExitMock).toHaveBeenCalledWith(1);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test("restore with save-always set", async () => {
 | 
			
		||||
    jest.spyOn(actionUtils, "isGhes").mockImplementation(() => true);
 | 
			
		||||
    const path = "node_modules";
 | 
			
		||||
    const key = "node-test";
 | 
			
		||||
    testUtils.setInputs({
 | 
			
		||||
        path: path,
 | 
			
		||||
        key,
 | 
			
		||||
        saveAlways: true
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
 | 
			
		||||
    const restoreCacheMock = jest
 | 
			
		||||
        .spyOn(cache, "restoreCache")
 | 
			
		||||
        .mockImplementationOnce(() => {
 | 
			
		||||
            return Promise.resolve(undefined);
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
    await restoreImpl(new StateProvider());
 | 
			
		||||
 | 
			
		||||
    expect(restoreCacheMock).toHaveBeenCalledTimes(1);
 | 
			
		||||
    expect(restoreCacheMock).toHaveBeenCalledWith(
 | 
			
		||||
        [path],
 | 
			
		||||
        key,
 | 
			
		||||
        [],
 | 
			
		||||
        {
 | 
			
		||||
            lookupOnly: false
 | 
			
		||||
        },
 | 
			
		||||
        false
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
 | 
			
		||||
    expect(setCacheHitOutputMock).toHaveBeenCalledWith(
 | 
			
		||||
        "save-always-d18d746b9",
 | 
			
		||||
        "true"
 | 
			
		||||
    );
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -16,6 +16,7 @@ interface CacheInput {
 | 
			
		|||
    enableCrossOsArchive?: boolean;
 | 
			
		||||
    failOnCacheMiss?: boolean;
 | 
			
		||||
    lookupOnly?: boolean;
 | 
			
		||||
    saveAlways?: boolean;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function setInputs(input: CacheInput): void {
 | 
			
		||||
| 
						 | 
				
			
			@ -32,6 +33,8 @@ export function setInputs(input: CacheInput): void {
 | 
			
		|||
        setInput(Inputs.FailOnCacheMiss, input.failOnCacheMiss.toString());
 | 
			
		||||
    input.lookupOnly !== undefined &&
 | 
			
		||||
        setInput(Inputs.LookupOnly, input.lookupOnly.toString());
 | 
			
		||||
    input.saveAlways !== undefined &&
 | 
			
		||||
        setInput(Inputs.SaveAlways, input.saveAlways.toString());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function clearInputs(): void {
 | 
			
		||||
| 
						 | 
				
			
			@ -42,4 +45,5 @@ export function clearInputs(): void {
 | 
			
		|||
    delete process.env[getInputName(Inputs.EnableCrossOsArchive)];
 | 
			
		||||
    delete process.env[getInputName(Inputs.FailOnCacheMiss)];
 | 
			
		||||
    delete process.env[getInputName(Inputs.LookupOnly)];
 | 
			
		||||
    delete process.env[getInputName(Inputs.SaveAlways)];
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user