Skip to content

Commit

Permalink
Bump deps (switcher-client-deno, validtor4oak, oak) (#33)
Browse files Browse the repository at this point in the history
* Bump deps (switcher-client-deno, validtor4oak, oak)

* chore: excluded thrid-party lib coverage scan
  • Loading branch information
petruki committed May 26, 2024
1 parent 440d8dc commit 2cd2481
Show file tree
Hide file tree
Showing 14 changed files with 216 additions and 240 deletions.
4 changes: 2 additions & 2 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.42.2
- name: Setup Deno v1.43.6
uses: denoland/setup-deno@v1
with:
deno-version: v1.42.2
deno-version: v1.43.6

- name: Setup LCOV
run: sudo apt install -y lcov
Expand Down
4 changes: 2 additions & 2 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.42.2
- name: Setup Deno v1.43.6
uses: denoland/setup-deno@v1
with:
deno-version: v1.42.2
deno-version: v1.43.6

- name: Verify formatting
run: deno task fmt
Expand Down
4 changes: 2 additions & 2 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 Denov1.42.2
- name: Setup Denov1.43.6
uses: denoland/setup-deno@v1
with:
deno-version: v1.42.2
deno-version: v1.43.6

- name: Verify formatting
run: deno task fmt
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM denoland/deno:alpine-1.42.2
FROM denoland/deno:alpine-1.43.6

ENV APP_HOME=/home/app
WORKDIR $APP_HOME
Expand All @@ -11,6 +11,6 @@ COPY /src .

RUN addgroup -S app && \
adduser -S app -G app && \
chown -R app:app $APP_HOME /deno-dir
chown -R app:app "$APP_HOME" /deno-dir

USER app
5 changes: 3 additions & 2 deletions deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
"fmt": "deno fmt src/ --options-single-quote --options-line-width=120 --check",
"fmt:fix": "deno fmt test/ src/ --options-single-quote --options-line-width=120",
"test": "deno test --allow-read --allow-net --allow-env --allow-write --coverage=coverage",
"lcov": "deno coverage coverage --lcov --output=coverage/report.lcov",
"lcov": "deno coverage --exclude=external --lcov --output=coverage/report.lcov",
"clean": "rm -rf ./npm ./coverage",
"cover": "deno task clean && deno task test && deno task lcov && genhtml -o coverage/html coverage/report.lcov"
"cover": "deno task clean && deno task test && deno task lcov && genhtml -o coverage/html coverage/report.lcov",
"cover:html": "deno task clean && deno task test && deno task lcov && deno coverage --exclude=external --html"
},
"lock": true
}
336 changes: 151 additions & 185 deletions deno.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ 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,src/external/**/*

# Ignore invalid rule for Deno tests
sonar.issue.ignore.multicriteria=e1
Expand Down
12 changes: 5 additions & 7 deletions src/deps.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
export { Application, Router } from 'https://deno.land/x/oak@14.2.0/mod.ts';
export type { Middleware, Next } from 'https://deno.land/x/oak@14.2.0/mod.ts';
export { Context } from 'https://deno.land/x/oak@14.2.0/context.ts';
export { load } from 'https://deno.land/std@0.223.0/dotenv/mod.ts';
export { bold, cyan, green } from 'https://deno.land/std@0.223.0/fmt/colors.ts';
export { checkValue, Switcher } from 'https://deno.land/x/switcher4deno@v1.0.9/mod.ts';
export { ValidatorFn, ValidatorMiddleware } from 'https://deno.land/x/validator4oak@v1.0.0/mod.ts';
export { Application, Context, type Middleware, type Next, Router } from 'jsr:@oak/oak@16.0.0';
export { load } from 'https://deno.land/std@0.224.0/dotenv/mod.ts';
export { bold, cyan, green } from 'https://deno.land/std@0.224.0/fmt/colors.ts';
export { Client } from 'jsr:@switcherapi/switcher-client-deno@2.0.1';
export { ValidatorFn, ValidatorMiddleware } from 'jsr:@trackerforce/validator4oak@1.0.1';
27 changes: 15 additions & 12 deletions src/config/switcher-client.ts → src/external/switcher-client.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Switcher } from '../deps.ts';
import { Client } from '../deps.ts';
import { getEnv, logger } from '../utils.ts';

/**
* SwitcherClient wraps Switcher SDK settings and initialization.
*/
export default class SwitcherClient {
static async initialize(fetchOnline = true) {
static async initialize(fetchRemote = true) {
const domain = getEnv('SWITCHER_DOMAIN', 'Switcher API');
const component = getEnv('SWITCHER_COMPONENT', 'switcher-management');
const apiKey = getEnv('SWITCHER_API_KEY', '');
Expand All @@ -29,36 +29,39 @@ export default class SwitcherClient {
snapshotLocation,
updateInterval,
certPath,
fetchOnline,
fetchRemote,
});

Switcher.buildContext({ url, apiKey, domain, component, environment }, {
Client.buildContext({ url, apiKey, domain, component, environment }, {
local,
snapshotLocation,
regexSafe,
certPath,
});

await Switcher.loadSnapshot(false, fetchOnline).then((version) => {
await Client.loadSnapshot({ fetchRemote }).then((version) => {
logger('INFO', 'SwitcherClient', `Snapshot version ${version} loaded`);
}).catch((err) => {
logger('ERROR', 'SwitcherClient', `Failed to load snapshot: ${err}`);
});

if (updateInterval) {
Switcher.scheduleSnapshotAutoUpdate(Number(updateInterval), (updated) => {
if (updated) {
logger('INFO', 'SwitcherClient', `Snapshot updated: ${Switcher.snapshot?.data.domain.version}`);
}
}, (err) => {
logger('ERROR', 'SwitcherClient', `Failed to update snapshot: ${err}`);
Client.scheduleSnapshotAutoUpdate(Number(updateInterval), {
success: (updated) => {
if (updated) {
logger('INFO', 'SwitcherClient', `Snapshot updated: ${Client.snapshot?.data.domain.version}`);
}
},
reject: (err) => {
logger('ERROR', 'SwitcherClient', `Failed to update snapshot: ${err}`);
},
});
}

return true;
}

static terminateSnapshotAutoUpdate(): void {
Switcher.terminateSnapshotAutoUpdate();
Client.terminateSnapshotAutoUpdate();
}
}
15 changes: 7 additions & 8 deletions src/services/feature.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import SwitcherClient from '../config/switcher-client.ts';
import { checkValue, Switcher } from '../deps.ts';
import SwitcherClient from '../external/switcher-client.ts';
import { Client } from '../deps.ts';

class FeatureService {
async initialize(fetchOnline: boolean) {
await SwitcherClient.initialize(fetchOnline);
async initialize(fetchRemote: boolean) {
await SwitcherClient.initialize(fetchRemote);
}

async isFeatureEnabled(featureName: string, params?: Param) {
const switcher = Switcher.factory();
const entries = [];
const switcher = Client.getSwitcher();

if (params?.value) {
entries.push(checkValue(params.value));
switcher.checkValue(params.value);
}

return await switcher.isItOn(featureName, entries) as boolean;
return await switcher.isItOn(featureName) as boolean;
}

terminateSnapshotAutoUpdate() {
Expand Down
7 changes: 3 additions & 4 deletions test/deps.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export { testing } from 'https://deno.land/x/oak@14.2.0/mod.ts';
export type { Middleware } from 'https://deno.land/x/oak@14.2.0/mod.ts';
export { assert, assertEquals, assertFalse, assertObjectMatch } from 'https://deno.land/std@0.223.0/assert/mod.ts';
export { type Middleware, testing } from 'jsr:@oak/oak@16.0.0';
export { assert, assertEquals, assertFalse, assertObjectMatch } from 'https://deno.land/std@0.224.0/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.9/mod.ts';
export { Client } from 'jsr:@switcherapi/switcher-client-deno@2.0.1';
14 changes: 7 additions & 7 deletions test/routes/feature.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import app from '../../src/app.ts';
import { assert, assertFalse, assertObjectMatch, superoak, Switcher } from '../deps.ts';
import { assert, assertFalse, assertObjectMatch, Client, superoak } from '../deps.ts';

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

const request = await superoak(app);
const response = await request.post('/')
Expand All @@ -18,7 +18,7 @@ Deno.test({
Deno.test({
name: 'Feature route - it should return true for enabled feature - with parameters',
async fn() {
Switcher.assume('FEATURE_NAME').false();
Client.assume('FEATURE_NAME').false();

const request = await superoak(app);
const response = await request.post('/')
Expand All @@ -32,7 +32,7 @@ Deno.test({
Deno.test({
name: 'it should return error - cannot access API',
async fn() {
Switcher.forget('FEATURE_NAME');
Client.forget('FEATURE_NAME');

const request = await superoak(app);
const res = await request.post('/')
Expand All @@ -46,7 +46,7 @@ Deno.test({
Deno.test({
name: 'Feature route - it should return error - body request not provided',
async fn() {
Switcher.forget('FEATURE_NAME');
Client.forget('FEATURE_NAME');

const request = await superoak(app);
const res = await request.post('/')
Expand All @@ -60,7 +60,7 @@ Deno.test({
Deno.test({
name: 'Feature route - it should return error - feature name not provided',
async fn() {
Switcher.forget('FEATURE_NAME');
Client.forget('FEATURE_NAME');

const request = await superoak(app);
const res = await request.post('/')
Expand All @@ -74,7 +74,7 @@ Deno.test({
Deno.test({
name: 'Feature route - it should return error - parameters has invalid length',
async fn() {
Switcher.forget('FEATURE_NAME');
Client.forget('FEATURE_NAME');

const request = await superoak(app);
const res = await request.post('/')
Expand Down
5 changes: 3 additions & 2 deletions test/services/feature.integrated.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ const teardown = () => {
featureService.terminateSnapshotAutoUpdate();
};

const setupDenoEnv = () => {
const setupDenoEnv = async () => {
Deno.env.set('SWITCHER_ENVIRONMENT', 'test');
Deno.env.set('SWITCHER_LOCAL', 'true');
Deno.env.set('SWITCHER_SNAPSHOT_UPDATE_INTERVAL', '3');
await import('../../src/app.ts');
};

Deno.test({
name: 'Feature service integrated - it should return feature enabled - from snapshot cache',
async fn() {
//given
setupDenoEnv();
await setupDenoEnv();
await featureService.initialize(false);

//test
Expand Down
17 changes: 13 additions & 4 deletions test/services/feature.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import FeatureService from '../../src/services/feature.ts';
import { assert, assertFalse, Switcher } from '../deps.ts';
import { assert, assertFalse, Client } from '../deps.ts';

const featureService = new FeatureService();

const setupDenoEnv = async (local: boolean, interval: string = '') => {
Deno.env.set('SWITCHER_ENVIRONMENT', 'test');
Deno.env.set('SWITCHER_LOCAL', String(local));
Deno.env.set('SWITCHER_SNAPSHOT_UPDATE_INTERVAL', interval);
await import('../../src/app.ts');
};

Deno.test({
name: 'Feature service - it should return feature disabled',
async fn() {
//given
Switcher.assume('FEATURE_NAME').false();
await setupDenoEnv(true);
Client.assume('FEATURE_NAME').false();
const featureName = 'FEATURE_NAME';

//test
Expand All @@ -24,7 +32,8 @@ Deno.test({
name: 'Feature service - it should return feature enabled - with parameters',
async fn() {
//given
Switcher.assume('FEATURE_NAME').true();
await setupDenoEnv(true);
Client.assume('FEATURE_NAME').true();
const featureName = 'FEATURE_NAME';

//test
Expand All @@ -35,4 +44,4 @@ Deno.test({
assert(response);
featureService.terminateSnapshotAutoUpdate();
},
});
});

0 comments on commit 2cd2481

Please sign in to comment.