Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(codepipeline-actions): more convenient methods to CacheControl #28491

Merged
merged 2 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,26 @@ export class CacheControl {
public static noCache() { return new CacheControl('no-cache'); }
/** The 'no-transform' cache control directive. */
public static noTransform() { return new CacheControl('no-transform'); }
/** The 'no-store' cache control directive. */
public static noStore() { return new CacheControl('no-store'); }
/** The 'must-understand' cache control directive. */
public static mustUnderstand() { return new CacheControl('must-understand'); }
/** The 'public' cache control directive. */
public static setPublic() { return new CacheControl('public'); }
/** The 'private' cache control directive. */
public static setPrivate() { return new CacheControl('private'); }
/** The 'immutable' cache control directive. */
public static immutable() { return new CacheControl('immutable'); }
/** The 'proxy-revalidate' cache control directive. */
public static proxyRevalidate() { return new CacheControl('proxy-revalidate'); }
/** The 'max-age' cache control directive. */
public static maxAge(t: Duration) { return new CacheControl(`max-age=${t.toSeconds()}`); }
/** The 's-max-age' cache control directive. */
public static sMaxAge(t: Duration) { return new CacheControl(`s-maxage=${t.toSeconds()}`); }
/** The 'stale-while-revalidate' cache control directive. */
public static staleWhileRevalidate(t: Duration) { return new CacheControl(`stale-while-revalidate=${t.toSeconds()}`); }
/** The 'stale-if-error' cache control directive. */
public static staleIfError(t: Duration) { return new CacheControl(`stale-if-error=${t.toSeconds()}`); }
/**
* Allows you to create an arbitrary cache control directive,
* in case our support is missing a method for a particular directive.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,23 @@ describe('S3 Deploy Action', () => {
});
});

test('cache-control directive has correct values', () => {
expect(cpactions.CacheControl.mustRevalidate().value).toEqual('must-revalidate');
expect(cpactions.CacheControl.noCache().value).toEqual('no-cache');
expect(cpactions.CacheControl.noTransform().value).toEqual('no-transform');
expect(cpactions.CacheControl.noStore().value).toEqual('no-store');
expect(cpactions.CacheControl.mustUnderstand().value).toEqual('must-understand');
expect(cpactions.CacheControl.setPublic().value).toEqual('public');
expect(cpactions.CacheControl.setPrivate().value).toEqual('private');
expect(cpactions.CacheControl.immutable().value).toEqual('immutable');
expect(cpactions.CacheControl.proxyRevalidate().value).toEqual('proxy-revalidate');
expect(cpactions.CacheControl.maxAge(Duration.minutes(1)).value).toEqual('max-age=60');
expect(cpactions.CacheControl.sMaxAge(Duration.minutes(1)).value).toEqual('s-maxage=60');
expect(cpactions.CacheControl.staleWhileRevalidate(Duration.minutes(1)).value).toEqual('stale-while-revalidate=60');
expect(cpactions.CacheControl.staleIfError(Duration.minutes(1)).value).toEqual('stale-if-error=60');
expect(cpactions.CacheControl.fromString('custom').value).toEqual('custom');
});

test('allow customizing objectKey (deployment path on S3)', () => {
const stack = new Stack();
minimalPipeline(stack, {
Expand Down