Skip to content

Commit

Permalink
fix: getting pluginRegistry
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksii Orel <[email protected]>
  • Loading branch information
olexii4 committed Nov 30, 2023
1 parent 403c6e9 commit 93ae4b5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,24 @@ describe('Server Config API Service', () => {
expect(res).toEqual([{ container: { image: 'component-image' }, name: 'component-name' }]);
});

test('getting pluginRegistry', () => {
test('getting pluginRegistry(openVSXURL from the CR)', () => {
const openVSXURL = 'https://open-vsx.org';
const res = serverConfigService.getPluginRegistry(buildCustomResource(openVSXURL));
expect(res).toEqual({ openVSXURL: 'https://open-vsx.org' });
});

test('getting pluginRegistry(openVSXURL from the env var)', () => {
process.env.CHE_DEFAULT_SPEC_COMPONENTS_PLUGINREGISTRY_OPENVSXURL = 'https://open-vsx.org';
const res = serverConfigService.getPluginRegistry(buildCustomResource());
expect(res).toEqual({ openVSXURL: 'https://open-vsx.org' });
});

test('getting pluginRegistry(empty openVSXURL from the env var)', () => {
process.env.CHE_DEFAULT_SPEC_COMPONENTS_PLUGINREGISTRY_OPENVSXURL = '';
const res = serverConfigService.getPluginRegistry(buildCustomResource());
expect(res).toEqual({ openVSXURL: '' });
});

test('getting PVC strategy', () => {
const res = serverConfigService.getPvcStrategy(buildCustomResource());
expect(res).toEqual('per-user');
Expand Down Expand Up @@ -149,7 +162,7 @@ function buildCustomResourceList(): { body: CustomResourceDefinitionList } {
};
}

function buildCustomResource(): CheClusterCustomResource {
function buildCustomResource(openVSXURL?: string): CheClusterCustomResource {
return {
apiVersion: 'org.eclipse.che/v2',
kind: 'CheCluster',
Expand All @@ -166,7 +179,7 @@ function buildCustomResource(): CheClusterCustomResource {
},
},
devWorkspace: {},
pluginRegistry: { openVSXURL: 'https://open-vsx.org' },
pluginRegistry: openVSXURL ? { openVSXURL } : {},
devfileRegistry: {
externalDevfileRegistries: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,11 @@ export class ServerConfigApiService implements IServerConfigApi {
// - empty value forces to use embedded registry
// - undefined value means that the default value should be used

const pluginRegistry = cheCustomResource.spec.components?.pluginRegistry
? cheCustomResource.spec.components.pluginRegistry
: ({ openVSXURL: '' } as api.IPluginRegistry);
const pluginRegistry = cheCustomResource.spec.components?.pluginRegistry || {};

const openVSXURL =
cheCustomResource.spec.components?.pluginRegistry?.openVSXURL !== undefined
? pluginRegistry.openVSXURL
: process.env['CHE_DEFAULT_SPEC_COMPONENTS_PLUGINREGISTRY_OPENVSXURL'];

if (openVSXURL) {
pluginRegistry.openVSXURL = openVSXURL;
if (cheCustomResource.spec.components?.pluginRegistry?.openVSXURL === undefined) {
pluginRegistry.openVSXURL =
process.env['CHE_DEFAULT_SPEC_COMPONENTS_PLUGINREGISTRY_OPENVSXURL'];
}

return pluginRegistry;
Expand Down

0 comments on commit 93ae4b5

Please sign in to comment.