Skip to content
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
rebase-capture-condition
  • Loading branch information
adamfweidman committed Feb 28, 2024
commit f923952636acf990c37c226f8cea7dc83fafb207
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
8 changes: 4 additions & 4 deletions packages/synthetics-sdk-broken-links/src/broken_links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ export enum StatusClass {

export interface ScreenshotOptions {
storage_location?: string;
screenshot_condition?: ScreenshotCondition;
capture_condition?: CaptureCondition;
}

export enum ScreenshotCondition {
export enum CaptureCondition {
NONE = 'NONE',
FAILING = 'FAILING',
ALL = 'ALL',
Expand Down Expand Up @@ -112,10 +112,10 @@ export async function runBrokenLinks(
const errors: BaseError[] = [];

// Initialize Storage Client with Error Handling. Set to `null` if
// screenshot_condition is 'None'
// capture_condition is 'None'
const storageClient = createStorageClientIfStorageSelected(
errors,
options.screenshot_options!.screenshot_condition
options.screenshot_options!.capture_condition
);

// TODO. Just to show where this will be called. uncommented in next PR
Expand Down
30 changes: 13 additions & 17 deletions packages/synthetics-sdk-broken-links/src/options_func.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ import {
BrokenLinksResultV1_BrokenLinkCheckerOptions_LinkOrder,
BrokenLinksResultV1_BrokenLinkCheckerOptions_PerLinkOption,
BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions,
BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions_ScreenshotCondition,
BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions_CaptureCondition as ApiCaptureCondition,
ResponseStatusCode,
ResponseStatusCode_StatusClass,
} from '@google-cloud/synthetics-sdk-api';
import {
BrokenLinkCheckerOptions,
LinkOrder,
StatusClass,
ScreenshotCondition,
CaptureCondition,
} from './broken_links';

/**
Expand Down Expand Up @@ -156,13 +156,13 @@ export function validateInputOptions(

// check storage_condition
if (
inputOptions.screenshot_options?.screenshot_condition !== undefined &&
!Object.values(ScreenshotCondition).includes(
inputOptions.screenshot_options?.screenshot_condition
inputOptions.screenshot_options?.capture_condition !== undefined &&
!Object.values(CaptureCondition).includes(
inputOptions.screenshot_options?.capture_condition
)
) {
throw new Error(
'Invalid screenshot_condition value, must be `ALL`, `FAILING`, OR `NONE`'
'Invalid capture_condition value, must be `ALL`, `FAILING`, OR `NONE`'
);
}

Expand Down Expand Up @@ -217,8 +217,7 @@ export function validateInputOptions(
per_link_options: inputOptions.per_link_options,
total_synthetic_timeout_millis: inputOptions.total_synthetic_timeout_millis,
screenshot_options: {
screenshot_condition:
inputOptions.screenshot_options?.screenshot_condition,
capture_condition: inputOptions.screenshot_options?.capture_condition,
storage_location: inputOptions.screenshot_options?.storage_location,
},
};
Expand All @@ -245,8 +244,7 @@ export function setDefaultOptions(
per_link_options: {},
total_synthetic_timeout_millis: 60000,
screenshot_options: {
screenshot_condition:
BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions_ScreenshotCondition.FAILING,
capture_condition: ApiCaptureCondition.FAILING,
storage_location: '',
},
};
Expand Down Expand Up @@ -283,14 +281,12 @@ export function setDefaultOptions(
// BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions
outputOptions.screenshot_options =
{} as BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions;
if (inputOptions.screenshot_options?.screenshot_condition) {
outputOptions.screenshot_options!.screenshot_condition =
BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions_ScreenshotCondition[
inputOptions.screenshot_options.screenshot_condition
];
if (inputOptions.screenshot_options?.capture_condition) {
outputOptions.screenshot_options!.capture_condition =
ApiCaptureCondition[inputOptions.screenshot_options.capture_condition];
} else {
outputOptions.screenshot_options!.screenshot_condition =
defaultOptions.screenshot_options!.screenshot_condition;
outputOptions.screenshot_options!.capture_condition =
defaultOptions.screenshot_options!.capture_condition;
}

if (outputOptions.screenshot_options?.storage_location) {
Expand Down
6 changes: 3 additions & 3 deletions packages/synthetics-sdk-broken-links/src/storage_func.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Storage, Bucket } from '@google-cloud/storage';
import {
BaseError,
BrokenLinksResultV1_BrokenLinkCheckerOptions,
BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions_ScreenshotCondition as ApiScreenshotCondition,
BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions_CaptureCondition as ApiCaptureCondition,
resolveProjectId,
getExecutionRegion,
BrokenLinksResultV1_SyntheticLinkResult_ScreenshotOutput as ApiScreenshotOutput,
Expand Down Expand Up @@ -107,9 +107,9 @@ export async function getOrCreateStorageBucket(
*/
export function createStorageClientIfStorageSelected(
errors: BaseError[],
storageCondition: ApiScreenshotCondition
captureCondition: ApiCaptureCondition
): Storage | null {
if (storageCondition === ApiScreenshotCondition.NONE) return null;
if (captureCondition === ApiCaptureCondition.NONE) return null;

try {
return new Storage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
BaseError,
BrokenLinksResultV1_BrokenLinkCheckerOptions_LinkOrder,
BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions,
BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions_ScreenshotCondition,
BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions_CaptureCondition as ApiCaptureCondition,
BrokenLinksResultV1_SyntheticLinkResult_ScreenshotOutput,
ResponseStatusCode_StatusClass,
SyntheticResult,
Expand All @@ -35,8 +35,7 @@ describe('CloudFunctionV2 Running Broken Link Synthetics', async () => {
};
const default_screenshot_options: BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions =
{
screenshot_condition:
BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions_ScreenshotCondition.FAILING,
capture_condition: ApiCaptureCondition.FAILING,
storage_location: '',
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
BrokenLinksResultV1_BrokenLinkCheckerOptions,
BrokenLinksResultV1_BrokenLinkCheckerOptions_LinkOrder,
BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions,
BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions_ScreenshotCondition,
BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions_CaptureCondition as ApiCaptureCondition,
BrokenLinksResultV1_SyntheticLinkResult,
ResponseStatusCode,
BaseError,
Expand All @@ -37,8 +37,7 @@ describe('runBrokenLinks', async () => {
};
const default_screenshot_options: BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions =
{
screenshot_condition:
BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions_ScreenshotCondition.FAILING,
capture_condition: ApiCaptureCondition.FAILING,
storage_location: '',
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,19 +371,19 @@ describe('GCM Synthetics Broken Links options_func suite testing', () => {
it('throws error if storage_condition is not a valid StorageCondition value', () => {
const options = {
origin_uri: 'http://example.com',
screenshot_options: { screenshot_condition: 'invalid' },
screenshot_options: { capture_condition: 'invalid' },
} as any as BrokenLinkCheckerOptions;
expect(() => {
validateInputOptions(options);
}).to.throw(
Error,
'Invalid screenshot_condition value, must be `ALL`, `FAILING`, OR `NONE`'
'Invalid capture_condition value, must be `ALL`, `FAILING`, OR `NONE`'
);
});
it('storage_condition accepts string', () => {
const options = {
origin_uri: 'http://example.com',
screenshot_options: { screenshot_condition: 'FAILING' },
screenshot_options: { capture_condition: 'FAILING' },
} as any as BrokenLinkCheckerOptions;
expect(() => {
validateInputOptions(options);
Expand Down Expand Up @@ -425,7 +425,7 @@ describe('GCM Synthetics Broken Links options_func suite testing', () => {
},
screenshot_options: {
storage_location: '',
screenshot_condition: 'FAILING',
capture_condition: 'FAILING',
},
} as BrokenLinkCheckerOptions;

Expand All @@ -452,7 +452,7 @@ describe('GCM Synthetics Broken Links options_func suite testing', () => {
total_synthetic_timeout_millis: undefined,
screenshot_options: {
storage_location: undefined,
screenshot_condition: undefined,
capture_condition: undefined,
},
} as BrokenLinkCheckerOptions;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ describe('GCM Synthetics Broken Links storage_func suite testing', () => {

const storage_condition_failing_links =
sdkApi
.BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions_ScreenshotCondition
.BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions_CaptureCondition
.FAILING;
const storage_condition_none =
sdkApi
.BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions_ScreenshotCondition
.BrokenLinksResultV1_BrokenLinkCheckerOptions_ScreenshotOptions_CaptureCondition
.NONE;

beforeEach(() => {
Expand Down