Skip to content

Commit

Permalink
Upgrade Deno 1.41, Oak 14, ARM64 support (#29)
Browse files Browse the repository at this point in the history
* Upgrade Deno 1.41, Oak 14, ARM64 support

* sonar: ignore test folder analysis
* sonar: fix exclusions
* sonar: fix invalid ts rule for Deno
* sonar: fix ignore multicriteria
  • Loading branch information
petruki committed Mar 2, 2024
1 parent 3f353d6 commit 5082277
Show file tree
Hide file tree
Showing 19 changed files with 207 additions and 203 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:
with:
fetch-depth: 0

- name: Setup Deno v1.39.2
- name: Setup Deno v1.41.0
uses: denoland/setup-deno@v1
with:
deno-version: v1.39.2
deno-version: v1.41.0

- name: Setup LCOV
run: sudo apt install -y lcov
Expand Down Expand Up @@ -71,7 +71,7 @@ jobs:
uses: docker/build-push-action@v5
with:
push: true
platforms: linux/amd64
platforms: linux/amd64,linux/arm64
tags: trackerforce/switcher-management-feature:latest

update-kustomize:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/re-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:
fetch-depth: 0
ref: ${{ github.event.inputs.tag }}

- name: Setup Deno v1.39.2
- name: Setup Deno v1.41.0
uses: denoland/setup-deno@v1
with:
deno-version: v1.39.2
deno-version: v1.41.0

- name: Verify formatting
run: deno task fmt
Expand Down Expand Up @@ -71,6 +71,6 @@ jobs:
with:
context: .
push: true
platforms: linux/amd64
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
with:
fetch-depth: 0

- name: Setup Deno v1.39.2
- name: Setup Denov1.41.0
uses: denoland/setup-deno@v1
with:
deno-version: v1.39.2
deno-version: v1.41.0

- name: Verify formatting
run: deno task fmt
Expand Down Expand Up @@ -62,6 +62,6 @@ jobs:
with:
context: .
push: true
platforms: linux/amd64
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"deno.enable": true,
"deno.enablePaths": [],
"deno.unstable": true,
"[typescript]": {
"editor.defaultFormatter": "vscode.typescript-language-features"
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM denoland/deno:alpine-1.39.2
FROM denoland/deno:alpine-1.41.0

ENV APP_HOME=/home/app
WORKDIR $APP_HOME
Expand Down
3 changes: 3 additions & 0 deletions deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"name": "@switcherapi/switcher-management-feature",
"version": "1.0.1",
"description": "Feature Flag Service for Switcher Management",
"tasks": {
"run": "deno run --unstable --allow-net --allow-env --allow-read --allow-write src/index.ts",
"run:dev": "ENV_PATH=.env.dev deno task run",
Expand Down
299 changes: 152 additions & 147 deletions deno.lock

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ sonar.tests=test
sonar.language=typescript

sonar.dynamicAnalysis=reuseReports
sonar.exclusions=src/api-docs/**, src/routes/api-docs.ts, src/index.ts
sonar.exclusions=src/api-docs/**/*, src/routes/api-docs.ts, src/index.ts

# Ignore invalid rule for Deno tests
sonar.issue.ignore.multicriteria=e1
sonar.issue.ignore.multicriteria.e1.ruleKey=typescript:S2187
sonar.issue.ignore.multicriteria.e1.resourceKey=test/**/*.ts

# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
10 changes: 5 additions & 5 deletions src/deps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export { Application, Router } from 'https://deno.land/x/oak@v12.6.1/mod.ts';
export type { Middleware, Next } from 'https://deno.land/x/oak@v12.6.1/mod.ts';
export { Context } from 'https://deno.land/x/oak@v12.6.1/context.ts';
export { load } from 'https://deno.land/std@0.211.0/dotenv/mod.ts';
export { Application, Router } from 'https://deno.land/x/oak@v14.1.1/mod.ts';
export type { Middleware, Next } from 'https://deno.land/x/oak@v14.1.1/mod.ts';
export { Context } from 'https://deno.land/x/oak@v14.1.1/context.ts';
export { load } from 'https://deno.land/std@0.218.2/dotenv/mod.ts';
export { checkValue, Switcher } from 'https://deno.land/x/switcher4deno@v1.0.6/mod.ts';
export { bold, cyan, green } from 'https://deno.land/std@0.211.0/fmt/colors.ts';
export { bold, cyan, green } from 'https://deno.land/std@0.218.2/fmt/colors.ts';
4 changes: 2 additions & 2 deletions src/dto/mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export function toFeatureResponseDto(status: boolean): FeatureResponseDto {
};
}

export async function toFeatureRequestDto(context: Context): Promise<FeatureRequestDto> {
const reqBody = await context.request.body({ type: 'json' }).value;
export function toFeatureRequestDto(context: Context): FeatureRequestDto {
const reqBody = context.state.request_body;
return {
feature: decodeURIComponent(reqBody.feature),
value: decodeURIComponent(reqBody.parameters?.value),
Expand Down
7 changes: 4 additions & 3 deletions src/middleware/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ interface ValidatorParams {
export default class Validator {
static checkBody(args: ValidatorParams[]) {
return async (context: Context, next: Next) => {
const reqBody = await context.request.body({ type: 'json' }).value;
const body = await context.request.body.text();

if (!reqBody) {
if (!body) {
return responseError(context, new Error('Invalid request body'), 400);
}

context.state.request_body = JSON.parse(body);
for (const arg of args) {
const value = arg.key.split('.').reduce((o, i) => {
if (o) return o[i];
}, reqBody);
}, context.state.request_body);

for (const validator of arg.validators) {
if (!validator(value, arg.key, context)) {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ router.post(
]),
async (context: Context) => {
try {
const request = await toFeatureRequestDto(context);
const request = toFeatureRequestDto(context);
const status = await getService().isFeatureEnabled(request.feature, { value: request?.value });
responseSuccess(context, toFeatureResponseDto(status));
} catch (error) {
Expand Down
8 changes: 4 additions & 4 deletions test/deps.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { testing } from 'https://deno.land/x/oak@v12.6.1/mod.ts';
export type { Middleware } from 'https://deno.land/x/oak@v12.6.1/mod.ts';
export { assert, assertEquals, assertFalse, assertObjectMatch } from 'https://deno.land/std@0.211.0/assert/mod.ts';
export { superoak } from 'https://deno.land/x/superoak@4.7.0/mod.ts';
export { testing } from 'https://deno.land/x/oak@v14.1.1/mod.ts';
export type { Middleware } from 'https://deno.land/x/oak@v14.1.1/mod.ts';
export { assert, assertEquals, assertFalse, assertObjectMatch } from 'https://deno.land/std@0.218.2/assert/mod.ts';
export { superoak } from 'https://deno.land/x/superoak@4.8.1/mod.ts';
export { Switcher } from 'https://deno.land/x/switcher4deno@v1.0.6/mod.ts';
4 changes: 1 addition & 3 deletions test/middleware/helmet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import Helmet from '../../src/middleware/helmet.ts';
import { Context, Next } from '../../src/deps.ts';
import { assertEquals } from '../deps.ts';

const testTitle = (description: string) => `Helmet middleware - ${description}`;

const newRequest = () => {
return {
request: {
Expand All @@ -18,7 +16,7 @@ const newRequest = () => {
};

Deno.test({
name: testTitle('it should set the headers'),
name: 'Helmet middleware - it should set the headers',
async fn() {
const helmet = new Helmet();
const middleware = helmet.middleware();
Expand Down
6 changes: 2 additions & 4 deletions test/middleware/rate-limit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import RateLimit from '../../src/middleware/rate-limit.ts';
import { Context, Next } from '../../src/deps.ts';
import { assertEquals } from '../deps.ts';

const testTitle = (description: string) => `RateLimit middleware - ${description}`;

const newRequest = () => {
return {
request: {
Expand All @@ -18,7 +16,7 @@ const newRequest = () => {
};

Deno.test({
name: testTitle('it should return 429 error when limit is exceeded'),
name: 'RateLimit middleware - it should return 429 error when limit is exceeded',
async fn() {
const rateLimit = new RateLimit();
const middleware = rateLimit.middleware({
Expand All @@ -44,7 +42,7 @@ Deno.test({
});

Deno.test({
name: testTitle('it should reset counter after windowMs'),
name: 'RateLimit middleware - it should reset counter after windowMs',
async fn() {
const rateLimit = new RateLimit();
const middleware = rateLimit.middleware({
Expand Down
16 changes: 7 additions & 9 deletions test/routes/api.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import app from '../../src/app.ts';
import { assert, assertEquals, superoak } from '../deps.ts';

const testTitle = (description: string) => `API route - ${description}`;

Deno.test({
name: testTitle('it should return ok'),
name: 'API route - it should return ok',
async fn() {
const request = await superoak(app);
const response = await request.get('/api/check').expect(200);
Expand All @@ -19,17 +17,17 @@ Deno.test({
},
switcherSettings: {
url: 'https://api.switcherapi.com',
environment: "test",
offline: "true",
snapshotAutoLoad: "false",
snapshotUpdateInterval: "not set"
environment: 'test',
offline: 'true',
snapshotAutoLoad: 'false',
snapshotUpdateInterval: 'not set',
},
});
},
});

Deno.test({
name: testTitle('it should return ok - release time'),
name: 'API route - it should return ok - release time',
async fn() {
//given
Deno.env.set('RELEASE_TIME', 'tomorow');
Expand All @@ -43,7 +41,7 @@ Deno.test({
});

Deno.test({
name: testTitle('it should return ok - ssl enabled'),
name: 'API route - it should return ok - ssl enabled',
async fn() {
//given
Deno.env.set('SSL_CERT', 'cert');
Expand Down
14 changes: 6 additions & 8 deletions test/routes/feature.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import app from '../../src/app.ts';
import { assert, assertFalse, assertObjectMatch, superoak, Switcher } from '../deps.ts';

const testTitle = (description: string) => `Feature route - ${description}`;

Deno.test({
name: testTitle('it should return true for enabled feature'),
name: 'Feature route - it should return true for enabled feature',
async fn() {
Switcher.assume('FEATURE_NAME').true();

Expand All @@ -18,7 +16,7 @@ Deno.test({
});

Deno.test({
name: testTitle('it should return true for enabled feature - with parameters'),
name: 'Feature route - it should return true for enabled feature - with parameters',
async fn() {
Switcher.assume('FEATURE_NAME').false();

Expand All @@ -32,7 +30,7 @@ Deno.test({
});

Deno.test({
name: testTitle('it should return error - cannot access API'),
name: 'it should return error - cannot access API',
async fn() {
Switcher.forget('FEATURE_NAME');

Expand All @@ -46,7 +44,7 @@ Deno.test({
});

Deno.test({
name: testTitle('it should return error - body request not provided'),
name: 'Feature route - it should return error - body request not provided',
async fn() {
Switcher.forget('FEATURE_NAME');

Expand All @@ -60,7 +58,7 @@ Deno.test({
});

Deno.test({
name: testTitle('it should return error - feature name not provided'),
name: 'Feature route - it should return error - feature name not provided',
async fn() {
Switcher.forget('FEATURE_NAME');

Expand All @@ -74,7 +72,7 @@ Deno.test({
});

Deno.test({
name: testTitle('it should return error - parameters has invalid length'),
name: 'Feature route - it should return error - parameters has invalid length',
async fn() {
Switcher.forget('FEATURE_NAME');

Expand Down
3 changes: 1 addition & 2 deletions test/services/feature.integrated.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { assert } from '../deps.ts';
await load({ export: true, envPath: getEnv('ENV_PATH', '.env.test') });
const featureService = new FeatureService();

const testTitle = (description: string) => `Feature service integrated - ${description}`;
const teardown = () => {
Deno.env.set('SWITCHER_SNAPSHOT_UPDATE_INTERVAL', '');
featureService.terminateSnapshotAutoUpdate();
Expand All @@ -19,7 +18,7 @@ const setupDenoEnv = () => {
};

Deno.test({
name: testTitle('it should return feature enabled - from snapshot cache'),
name: 'Feature service integrated - it should return feature enabled - from snapshot cache',
async fn() {
//given
setupDenoEnv();
Expand Down
5 changes: 2 additions & 3 deletions test/services/feature.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import FeatureService from '../../src/services/feature.ts';
import { assert, assertFalse, Switcher } from '../deps.ts';

const featureService = new FeatureService();
const testTitle = (description: string) => `Feature service - ${description}`;

Deno.test({
name: testTitle('it should return feature disabled'),
name: 'Feature service - it should return feature disabled',
async fn() {
//given
Switcher.assume('FEATURE_NAME').false();
Expand All @@ -22,7 +21,7 @@ Deno.test({
});

Deno.test({
name: testTitle('it should return feature enabled - with parameters'),
name: 'Feature service - it should return feature enabled - with parameters',
async fn() {
//given
Switcher.assume('FEATURE_NAME').true();
Expand Down

0 comments on commit 5082277

Please sign in to comment.