Skip to content

Commit f63bbbd

Browse files
authored
rebase-capture-condition (#110)
1 parent 5f21106 commit f63bbbd

9 files changed

+34
-40
lines changed

package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.

packages/synthetics-sdk-broken-links/src/broken_links.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ export enum StatusClass {
7979

8080
export interface ScreenshotOptions {
8181
storage_location?: string;
82-
screenshot_condition?: ScreenshotCondition;
82+
capture_condition?: CaptureCondition;
8383
}
8484

85-
export enum ScreenshotCondition {
85+
export enum CaptureCondition {
8686
NONE = 'NONE',
8787
FAILING = 'FAILING',
8888
ALL = 'ALL',
@@ -112,10 +112,10 @@ export async function runBrokenLinks(
112112
const errors: BaseError[] = [];
113113

114114
// Initialize Storage Client with Error Handling. Set to `null` if
115-
// screenshot_condition is 'None'
115+
// capture_condition is 'None'
116116
const storageClient = createStorageClientIfStorageSelected(
117117
errors,
118-
options.screenshot_options!.screenshot_condition
118+
options.screenshot_options!.capture_condition
119119
);
120120

121121
// TODO. Just to show where this will be called. uncommented in next PR

packages/synthetics-sdk-broken-links/src/options_func.ts

+13-17
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ import {
1717
BrokenLinksResultV1_BrokenLinkCheckerOptions_LinkOrder,
1818
BrokenLinksResultV1_BrokenLinkCheckerOptions_PerLinkOption,
1919
BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions,
20-
BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions_ScreenshotCondition,
20+
BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions_CaptureCondition as ApiCaptureCondition,
2121
ResponseStatusCode,
2222
ResponseStatusCode_StatusClass,
2323
} from '@google-cloud/synthetics-sdk-api';
2424
import {
2525
BrokenLinkCheckerOptions,
2626
LinkOrder,
2727
StatusClass,
28-
ScreenshotCondition,
28+
CaptureCondition,
2929
} from './broken_links';
3030

3131
/**
@@ -156,13 +156,13 @@ export function validateInputOptions(
156156

157157
// check storage_condition
158158
if (
159-
inputOptions.screenshot_options?.screenshot_condition !== undefined &&
160-
!Object.values(ScreenshotCondition).includes(
161-
inputOptions.screenshot_options?.screenshot_condition
159+
inputOptions.screenshot_options?.capture_condition !== undefined &&
160+
!Object.values(CaptureCondition).includes(
161+
inputOptions.screenshot_options?.capture_condition
162162
)
163163
) {
164164
throw new Error(
165-
'Invalid screenshot_condition value, must be `ALL`, `FAILING`, OR `NONE`'
165+
'Invalid capture_condition value, must be `ALL`, `FAILING`, OR `NONE`'
166166
);
167167
}
168168

@@ -217,8 +217,7 @@ export function validateInputOptions(
217217
per_link_options: inputOptions.per_link_options,
218218
total_synthetic_timeout_millis: inputOptions.total_synthetic_timeout_millis,
219219
screenshot_options: {
220-
screenshot_condition:
221-
inputOptions.screenshot_options?.screenshot_condition,
220+
capture_condition: inputOptions.screenshot_options?.capture_condition,
222221
storage_location: inputOptions.screenshot_options?.storage_location,
223222
},
224223
};
@@ -245,8 +244,7 @@ export function setDefaultOptions(
245244
per_link_options: {},
246245
total_synthetic_timeout_millis: 60000,
247246
screenshot_options: {
248-
screenshot_condition:
249-
BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions_ScreenshotCondition.FAILING,
247+
capture_condition: ApiCaptureCondition.FAILING,
250248
storage_location: '',
251249
},
252250
};
@@ -283,14 +281,12 @@ export function setDefaultOptions(
283281
// BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions
284282
outputOptions.screenshot_options =
285283
{} as BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions;
286-
if (inputOptions.screenshot_options?.screenshot_condition) {
287-
outputOptions.screenshot_options!.screenshot_condition =
288-
BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions_ScreenshotCondition[
289-
inputOptions.screenshot_options.screenshot_condition
290-
];
284+
if (inputOptions.screenshot_options?.capture_condition) {
285+
outputOptions.screenshot_options!.capture_condition =
286+
ApiCaptureCondition[inputOptions.screenshot_options.capture_condition];
291287
} else {
292-
outputOptions.screenshot_options!.screenshot_condition =
293-
defaultOptions.screenshot_options!.screenshot_condition;
288+
outputOptions.screenshot_options!.capture_condition =
289+
defaultOptions.screenshot_options!.capture_condition;
294290
}
295291

296292
if (outputOptions.screenshot_options?.storage_location) {

packages/synthetics-sdk-broken-links/src/storage_func.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { Storage, Bucket } from '@google-cloud/storage';
1717
import {
1818
BaseError,
1919
BrokenLinksResultV1_BrokenLinkCheckerOptions,
20-
BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions_ScreenshotCondition as ApiScreenshotCondition,
20+
BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions_CaptureCondition as ApiCaptureCondition,
2121
resolveProjectId,
2222
getExecutionRegion,
2323
BrokenLinksResultV1_SyntheticLinkResult_ScreenshotOutput as ApiScreenshotOutput,
@@ -107,9 +107,9 @@ export async function getOrCreateStorageBucket(
107107
*/
108108
export function createStorageClientIfStorageSelected(
109109
errors: BaseError[],
110-
storageCondition: ApiScreenshotCondition
110+
captureCondition: ApiCaptureCondition
111111
): Storage | null {
112-
if (storageCondition === ApiScreenshotCondition.NONE) return null;
112+
if (captureCondition === ApiCaptureCondition.NONE) return null;
113113

114114
try {
115115
return new Storage();

packages/synthetics-sdk-broken-links/test/integration/integration.spec.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
BaseError,
1717
BrokenLinksResultV1_BrokenLinkCheckerOptions_LinkOrder,
1818
BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions,
19-
BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions_ScreenshotCondition,
19+
BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions_CaptureCondition as ApiCaptureCondition,
2020
BrokenLinksResultV1_SyntheticLinkResult_ScreenshotOutput,
2121
ResponseStatusCode_StatusClass,
2222
SyntheticResult,
@@ -35,8 +35,7 @@ describe('CloudFunctionV2 Running Broken Link Synthetics', async () => {
3535
};
3636
const default_screenshot_options: BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions =
3737
{
38-
screenshot_condition:
39-
BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions_ScreenshotCondition.FAILING,
38+
capture_condition: ApiCaptureCondition.FAILING,
4039
storage_location: '',
4140
};
4241

packages/synthetics-sdk-broken-links/test/unit/broken_links.spec.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
BrokenLinksResultV1_BrokenLinkCheckerOptions,
2020
BrokenLinksResultV1_BrokenLinkCheckerOptions_LinkOrder,
2121
BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions,
22-
BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions_ScreenshotCondition,
22+
BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions_CaptureCondition as ApiCaptureCondition,
2323
BrokenLinksResultV1_SyntheticLinkResult,
2424
ResponseStatusCode,
2525
BaseError,
@@ -37,8 +37,7 @@ describe('runBrokenLinks', async () => {
3737
};
3838
const default_screenshot_options: BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions =
3939
{
40-
screenshot_condition:
41-
BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions_ScreenshotCondition.FAILING,
40+
capture_condition: ApiCaptureCondition.FAILING,
4241
storage_location: '',
4342
};
4443

packages/synthetics-sdk-broken-links/test/unit/options_func.spec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -371,19 +371,19 @@ describe('GCM Synthetics Broken Links options_func suite testing', () => {
371371
it('throws error if storage_condition is not a valid StorageCondition value', () => {
372372
const options = {
373373
origin_uri: 'http://example.com',
374-
screenshot_options: { screenshot_condition: 'invalid' },
374+
screenshot_options: { capture_condition: 'invalid' },
375375
} as any as BrokenLinkCheckerOptions;
376376
expect(() => {
377377
validateInputOptions(options);
378378
}).to.throw(
379379
Error,
380-
'Invalid screenshot_condition value, must be `ALL`, `FAILING`, OR `NONE`'
380+
'Invalid capture_condition value, must be `ALL`, `FAILING`, OR `NONE`'
381381
);
382382
});
383383
it('storage_condition accepts string', () => {
384384
const options = {
385385
origin_uri: 'http://example.com',
386-
screenshot_options: { screenshot_condition: 'FAILING' },
386+
screenshot_options: { capture_condition: 'FAILING' },
387387
} as any as BrokenLinkCheckerOptions;
388388
expect(() => {
389389
validateInputOptions(options);
@@ -425,7 +425,7 @@ describe('GCM Synthetics Broken Links options_func suite testing', () => {
425425
},
426426
screenshot_options: {
427427
storage_location: '',
428-
screenshot_condition: 'FAILING',
428+
capture_condition: 'FAILING',
429429
},
430430
} as BrokenLinkCheckerOptions;
431431

@@ -452,7 +452,7 @@ describe('GCM Synthetics Broken Links options_func suite testing', () => {
452452
total_synthetic_timeout_millis: undefined,
453453
screenshot_options: {
454454
storage_location: undefined,
455-
screenshot_condition: undefined,
455+
capture_condition: undefined,
456456
},
457457
} as BrokenLinkCheckerOptions;
458458

packages/synthetics-sdk-broken-links/test/unit/storage_func.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ describe('GCM Synthetics Broken Links storage_func suite testing', () => {
4343

4444
const storage_condition_failing_links =
4545
sdkApi
46-
.BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions_ScreenshotCondition
46+
.BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions_CaptureCondition
4747
.FAILING;
4848
const storage_condition_none =
4949
sdkApi
50-
.BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions_ScreenshotCondition
50+
.BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions_CaptureCondition
5151
.NONE;
5252

5353
beforeEach(() => {

0 commit comments

Comments
 (0)