Skip to content

Commit

Permalink
PR time check for dashboard required for creating a workspace (#922)
Browse files Browse the repository at this point in the history
* feat: added PR time check for dashboard required for creating a workspace

Signed-off-by: Oleksii Orel <oorel@redhat.com>

* chore: code cleanup

Signed-off-by: Oleksii Kurinnyi <okurinny@redhat.com>

---------

Signed-off-by: Oleksii Orel <oorel@redhat.com>
Signed-off-by: Oleksii Kurinnyi <okurinny@redhat.com>
Co-authored-by: Oleksii Kurinnyi <okurinny@redhat.com>
  • Loading branch information
olexii4 and akurinnoy authored Sep 15, 2023
1 parent 7ce1a33 commit 05d8301
Show file tree
Hide file tree
Showing 25 changed files with 585 additions and 65 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@ jobs:
name: "Check dependencies usage restrictions"
run: yarn license:check

time-check:
runs-on: ubuntu-22.04
strategy:
matrix:
node-version: [18.x]
steps:
-
name: "Checkout Che Dashboard source code"
uses: actions/checkout@v3
-
name: "Use Node.js ${{ matrix.node-version }}"
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
-
name: "Install dependencies"
run: yarn
-
name: "Workspace creation time check"
run: yarn test:check

build-and-test:
runs-on: ubuntu-22.04
strategy:
Expand Down
3 changes: 3 additions & 0 deletions devfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ components:
path: /
protocol: http
targetPort: 8888
env:
- name: KUBEDOCK_ENABLED
value: true
commands:
- id: installdependencies
exec:
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"license:check": "${PWD}/scripts/container_tool.sh run --rm -t -v ${PWD}/:/workspace/project quay.io/che-incubator/dash-licenses@sha256:72290f67f297a31b7b9b343d19f42cc0ecc90e1d36cc9f18473c586a70e4b7eb --check",
"license:generate": "${PWD}/scripts/container_tool.sh run --rm -t -v ${PWD}/:/workspace/project quay.io/che-incubator/dash-licenses:next",
"test": "lerna run test --stream -- --no-cache $@",
"test:check": "yarn pretest && yarn --cwd packages/dashboard-frontend test --config=jest.config.check.js",
"pretest": "yarn run prebuild",
"test:coverage": "yarn run test -- --coverage",
"format:check": "yarn workspaces run format:check",
Expand Down
18 changes: 18 additions & 0 deletions packages/dashboard-frontend/jest.config.check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (c) 2018-2023 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/

const config = require('./jest.config');

module.exports = {
...config,
testRegex: '(/src/.+\\.check)\\.tsx?$',
};
199 changes: 199 additions & 0 deletions packages/dashboard-frontend/src/__tests__/const.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
/*
* Copyright (c) 2018-2023 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/

import { FactoryResolver } from '../services/helpers/types';
import devfileApi from '../services/devfileApi';
import normalizeDevfileV2 from '../store/FactoryResolver/normalizeDevfileV2';
import { dump } from 'js-yaml';

export const FACTORY_RESOLVER_DELAY = 600;
export const DEVWORKSPACE_RESOURSES_DELAY = 600;
export const CREATE_DEVWORKSPACE_DELAY = 200;
export const CREATE_DEVWORKSPACETEMPLATE_DELAY = 200;
export const PATCH_DEVWORKSPACE_DELAY = 100;

export const TIME_LIMIT = 2500;

// mock objects
export const timestampNew = '2023-09-04T14:09:42.560Z';
export const namespace = { name: 'user-che', attributes: { phase: 'Active' } };
export const url = 'https://github.com/eclipse-che/che-dashboard';
export const devfile = {
schemaVersion: '2.2.0',
metadata: {
name: 'che-dashboard',
namespace: namespace.name,
},
components: [
{
name: 'universal-developer-image',
container: {
image: 'quay.io/devfile/universal-developer-image:ubi8-latest',
},
},
],
commands: [],
};
export const factoryResolver: FactoryResolver = {
v: '4.0',
source: 'devfile.yaml',
scm_info: {
clone_url: 'https://github.com/eclipse-che/che-dashboard.git',
scm_provider: 'github',
},
devfile: devfile,
links: [],
};
export const devfileV2 = normalizeDevfileV2(
devfile as devfileApi.DevfileLike,
factoryResolver,
'https://github.com/eclipse-che/che-dashboard',
[],
namespace.name,
{ factoryUrl: url },
);
const sampleResourceUrl =
'http://localhost/plugin-registry/v3/plugins/che-incubator/che-code/insiders/devfile.yaml';
export const plugins = {
[sampleResourceUrl]: {
url: sampleResourceUrl,
plugin: {
schemaVersion: '2.2.0',
metadata: {
name: 'che-code',
},
} as devfileApi.Devfile,
},
};
export const devfileContent = dump({
schemaVersion: '2.2.0',
metadata: {
name: 'che-dashboard',
namespace: namespace.name,
},
components: [
{
name: 'universal-developer-image',
container: {
image: 'quay.io/devfile/universal-developer-image:ubi8-latest',
},
},
],
commands: [],
projects: [
{
name: 'che-dashboard',
git: {
remotes: {
origin: 'https://github.com/eclipse-che/che-dashboard.git',
},
},
},
],
attributes: {
'dw.metadata.annotations': {
'che.eclipse.org/devfile-source': dump({
scm: {
repo: 'https://github.com/eclipse-che/che-dashboard.git',
fileName: 'devfile.yaml',
},
factory: {
params: 'url=https://github.com/eclipse-che/che-dashboard',
},
}),
},
},
});
export const editorContent = dump({
schemaVersion: '2.2.0',
metadata: {
name: 'che-code',
},
} as devfileApi.Devfile);
export const devworkspaceResources = `
apiVersion: workspace.devfile.io/v1alpha2
kind: DevWorkspaceTemplate
metadata:
name: che-code
---
apiVersion: workspace.devfile.io/v1alpha2
kind: DevWorkspace
metadata:
name: che-dashboard
spec:
started: false
template:
components:
- name: universal-developer-image
container:
image: quay.io/devfile/universal-developer-image:ubi8-latest
projects:
- name: che-dashboard
git:
remotes:
origin: https://github.com/eclipse-che/che-dashboard.git
`;
export const targetDevWorkspace = {
apiVersion: 'workspace.devfile.io/v1alpha2',
kind: 'DevWorkspace',
metadata: {
annotations: {
// 'che.eclipse.org/che-editor': 'che-incubator/che-code/insiders',
'che.eclipse.org/last-updated-timestamp': `${timestampNew}`,
},
name: 'che-dashboard',
namespace: namespace.name,
},
spec: {
routingClass: 'che',
started: false,
template: {
components: [
{
name: 'universal-developer-image',
container: {
image: 'quay.io/devfile/universal-developer-image:ubi8-latest',
},
},
],
projects: [
{
git: {
remotes: { origin: 'https://github.com/eclipse-che/che-dashboard.git' },
},
name: 'che-dashboard',
},
],
},
},
};
export const targetDevWorkspaceTemplate: devfileApi.DevWorkspaceTemplate = {
apiVersion: 'workspace.devfile.io/v1alpha2',
kind: 'DevWorkspaceTemplate',
metadata: {
annotations: {
'che.eclipse.org/components-update-policy': 'managed',
'che.eclipse.org/plugin-registry-url':
'http://localhost/plugin-registry/v3/plugins/che-incubator/che-code/insiders/devfile.yaml',
},
name: 'che-code',
namespace: namespace.name,
ownerReferences: [
{
apiVersion: 'workspace.devfile.io/v1alpha2',
kind: 'devworkspace',
name: 'che-dashboard',
uid: 'che-dashboard-test-uid',
},
],
},
};
Loading

0 comments on commit 05d8301

Please sign in to comment.