Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

feat(resource-monitor-plugin): Update to latest devfile 2 API #1018

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**********************************************************************
* Copyright (c) 2020 Red Hat, Inc.
* Copyright (c) 2020-2021 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -16,6 +16,7 @@
* @author Valerii Svydenko
*/
const che: any = {};
che.workspace = {};
che.devfile = {};
che.devfile.metadata = {};
che.k8s = {};
module.exports = che;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**********************************************************************
* Copyright (c) 2018-2020 Red Hat, Inc.
* Copyright (c) 2018-2021 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -193,6 +193,6 @@ export class ResMon {
}

export async function getNamespace(): Promise<string> {
const workspace = await che.workspace.getCurrentWorkspace();
return workspace.attributes ? workspace.attributes.infrastructureNamespace : '';
const devfile = await che.devfile.get();
return devfile.metadata?.attributes ? devfile.metadata.attributes.infrastructureNamespace : '';
}
15 changes: 8 additions & 7 deletions plugins/resource-monitor-plugin/tests/resource-monitor.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**********************************************************************
* Copyright (c) 2020 Red Hat, Inc.
* Copyright (c) 2020-2021 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -20,10 +20,9 @@ import * as theia from '@theia/plugin';
import { Container } from '../src/objects';
import { ResMon } from '../src/resource-monitor-plugin';
import { SHOW_WARNING_MESSAGE_COMMAND } from '../src/constants';
import { che as cheApi } from '@eclipse-che/api';

describe('Test Resource Monitor Plugin', () => {
const getCurrentWorkspace = jest.fn();
const devfileMock = jest.fn();
const sendRawQuery = jest.fn();
const createStatusBar = jest.fn();
process.env.HOSTNAME = 'workspace';
Expand Down Expand Up @@ -75,12 +74,14 @@ describe('Test Resource Monitor Plugin', () => {
che.k8s.sendRawQuery = sendRawQuery;

// Prepare Namespace
che.workspace.getCurrentWorkspace = getCurrentWorkspace;
che.devfile.get = devfileMock;
const attributes = { infrastructureNamespace: 'che-namespace' };
const workspace: cheApi.workspace.Workspace = {
attributes,
const devfile = {
metadata: {
attributes,
},
};
getCurrentWorkspace.mockReturnValue(workspace);
devfileMock.mockReturnValue(devfile);

// Prepare StatusBarItem
theia.window.createStatusBarItem = createStatusBar;
Expand Down