Skip to content

Commit

Permalink
Added checkly test (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntotten authored Sep 20, 2024
1 parent 9a7ed07 commit df92247
Show file tree
Hide file tree
Showing 6 changed files with 7,324 additions and 1,863 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: API Checks
on:
push:
branches:
- main

env:
CHECKLY_API_KEY: ${{ secrets.CHECKLY_API_KEY }}
CHECKLY_ACCOUNT_ID: ${{ vars.CHECKLY_ACCOUNT_ID }}
ENVIRONMENT_URL: https://0ad703f2f45143aea75b9a469dc41338.api.mockbin.io
CHECKLY_TEST_ENVIRONMENT: production
GITHUB_NPM_TOKEN: ${{ secrets.GH_NPM_PACKAGE_READ_TOKEN }}

jobs:
checkly:
name: Deploy Checks
runs-on: ubuntu-latest
timeout-minutes: 10
environment: production

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Deploy checks
id: deploy-checks
run: npx checkly deploy --force
22 changes: 22 additions & 0 deletions checkly.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { defineConfig } from "checkly";

/**
* See https://www.checklyhq.com/docs/cli/project-structure/
*/
const config = defineConfig({
projectName: "Mockbin",
logicalId: "mockbin",
repoUrl: "https://github.com/zuplo/mockbin",
checks: {
runtimeId: "2024.02",
checkMatch: "checks/**/*.check.ts",
tags: ["service-mockbin", "priority-in-hours"],
},
cli: {
runLocation: "us-east-1",
reporters: ["list"],
retries: 0,
},
});

export default config;
14 changes: 14 additions & 0 deletions checks/api.check.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { asserts, check } from "./group";

check({
name: "Should 200 requesting a mock",
shouldFail: false,
request: {
url: `/`,
method: "GET",
headers: {
"Content-Type": "application/json",
},
},
assertions: [asserts().statusCode().equals(200)],
});
48 changes: 48 additions & 0 deletions checks/group.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* eslint-disable node/no-process-env */
/**
* This is a Checkly CLI CheckGroup construct. To learn more, visit:
* - https://www.checklyhq.com/docs/cli/
* - https://www.checklyhq.com/docs/cli/constructs-reference/#checkgroup
*/

import { ApiCheckOptions, asserts, check as baseCheck } from "@zuplo/checkly";
import {
AlertEscalationBuilder,
CheckGroup,
Frequency,
RetryStrategyBuilder,
WebhookAlertChannel,
} from "checkly/constructs";

export const incidentChannel = WebhookAlertChannel.fromId(231732);

// Alert after 2 failed runs
const alertEscalationPolicy = AlertEscalationBuilder.runBasedEscalation(2);

export const group = new CheckGroup("mockbin", {
name: "Mockbin",
activated: true,
muted: false,
runParallel: true,
locations: ["us-east-1", "eu-west-1", "ap-southeast-2"],
tags: [],
alertChannels: [incidentChannel],
alertEscalationPolicy,
frequency: Frequency.EVERY_1H,
concurrency: 1,
apiCheckDefaults: {
url: process.env.ENVIRONMENT_URL ?? "http://localhost:3000",
queryParameters: [],
},
retryStrategy: RetryStrategyBuilder.linearStrategy({
baseBackoffSeconds: 30,
maxRetries: 2,
maxDurationSeconds: 600,
sameRegion: true,
}),
});

const check = (props: Omit<ApiCheckOptions, "group">) =>
baseCheck({ ...props, group });

export { asserts, check };
Loading

0 comments on commit df92247

Please sign in to comment.