Skip to content

Commit

Permalink
add integration tests to BE
Browse files Browse the repository at this point in the history
FLPATH-799
https://issues.redhat.com/browse/FLPATH-799

Signed-off-by: Yaron Dayagi <[email protected]>
  • Loading branch information
ydayagi committed Jan 9, 2024
1 parent be30796 commit 9901d8a
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 104 deletions.
22 changes: 15 additions & 7 deletions .github/actions/test/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ runs:
using: 'composite'
steps:
- name: Setup Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'yarn'
Expand All @@ -20,14 +20,22 @@ runs:
shell: bash
run: yarn --prefer-offline --frozen-lockfile

- name: Run prettier
- name: Build all packages
shell: bash
run: yarn prettier:check
run: yarn build --filter=${{ inputs.args }} --concurrency=1

- name: Run lint
- name: Start backstage
shell: bash
run: yarn lint --filter=${{ inputs.args }}
run: yarn install

- name: Run tests
- name: Start backstage
shell: bash
run: yarn test --filter=${{ inputs.args }}
run: ls;yarn start:backstage

- name: Wait for backstage
shell: bash
run: timeout 15 bash -c 'until echo > /dev/tcp/localhost/7007; do sleep 3; done'

- name: Test get notifications
shell: bash
run: curl http://localhost:7007/api/notifications/notifications
73 changes: 0 additions & 73 deletions .github/workflows/pr-semantic.yaml

This file was deleted.

23 changes: 1 addition & 22 deletions .github/workflows/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Push
on:
push:
branches:
- main
- flpath799

concurrency:
group: push
Expand All @@ -19,24 +19,3 @@ jobs:

- name: Test
uses: ./.github/actions/test

release:
name: Release
needs:
- test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Build all packages
uses: ./.github/actions/build

- name: Release via semantic-release
run: |
npm config set workspaces-update false
yarn release --ignore-private-packages
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_OPTIONS: '--max-old-space-size=8192'
25 changes: 23 additions & 2 deletions app-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,25 @@ backend:
# This is for local development only, it is not recommended to use this in production
# The production database configuration is stored in app-config.production.yaml
database:
connection: ':memory:'
client: better-sqlite3
connection:
':memory:'
#directory: ./mydb.sqlite
useNullAsDefault: true
#plugin:
#notifications:
#connection:
#filename: ./mydb.sqlite/thedb.sqlite
#host: 127.0.0.1
#port: 5432
#user: postgres
#password: secret
#knexConfig:
# pool:
# min: 3
# max: 12
# acquireTimeoutMillis: 60000
# idleTimeoutMillis: 60000
cache:
store: memory
# workingDirectory: /tmp # Use this to configure a working directory for the scaffolder, defaults to the OS temp-dir
Expand Down Expand Up @@ -84,8 +102,11 @@ catalog:
entityFilename: catalog-info.yaml
pullRequestBranchName: backstage-integration
rules:
- allow: [Component, System, API, Resource, Location]
- allow: [Component, System, API, Resource, Location, User, Group]
locations:
- type: file
# *** Here is new change, referes to a file stored in the root of the Backstage:
target: /home/ydayagi/work/src/github.com/ydayagi/backstage-plugins/plugins/notifications-backend/users.yaml
# Local example data, file locations are relative to the backend process, typically `packages/backend`
- type: file
target: ../../examples/entities.yaml
Expand Down
5 changes: 5 additions & 0 deletions packages/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import Router from 'express-promise-router';
import app from './plugins/app';
import auth from './plugins/auth';
import catalog from './plugins/catalog';
import notifications from './plugins/notifications';
import permission from './plugins/permissions';
import proxy from './plugins/proxy';
import scaffolder from './plugins/scaffolder';
Expand Down Expand Up @@ -104,6 +105,10 @@ async function main() {
getPluginIds: () => ['catalog', 'scaffolder', 'permission'],
}),
);
const notificationsEnv = useHotMemoize(module, () =>
createEnv('notifications'),
);
apiRouter.use('/notifications', await notifications(notificationsEnv));

// Add backends ABOVE this line; this 404 handler is the catch-all fallback
apiRouter.use(notFoundHandler());
Expand Down
18 changes: 18 additions & 0 deletions packages/backend/src/plugins/notifications.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { CatalogClient } from '@backstage/catalog-client';
import { createRouter } from '@backstage/plugin-notifications-backend';

import { Router } from 'express';

import { PluginEnvironment } from '../types';

export default async function createPlugin(
env: PluginEnvironment,
): Promise<Router> {
const catalogClient = new CatalogClient({ discoveryApi: env.discovery });
const dbConfig = env.config.getConfig('backend.database');
return await createRouter({
logger: env.logger,
dbConfig,
catalogClient,
});
}
1 change: 1 addition & 0 deletions plugins/notifications-backend/users.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
apiVersion: backstage.io/v1alpha1
kind: User
metadata:
namespace: default
name: guest
spec:
profile:
Expand Down

0 comments on commit 9901d8a

Please sign in to comment.