Skip to content

Commit

Permalink
chore: update extension settings (#234)
Browse files Browse the repository at this point in the history
Signed-off-by: Ilona Shishov <[email protected]>
  • Loading branch information
IlonaShishov authored Dec 19, 2023
1 parent d5c8477 commit 938249e
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 70 deletions.
20 changes: 11 additions & 9 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,17 @@ class Config
* @param data - The data from extension workspace settings to update the global configuration with.
*/
updateConfig( data: any ) {
this.exhortSnykToken = data.redHatDependencyAnalytics.exhortSnykToken;
this.matchManifestVersions = data.redHatDependencyAnalytics.matchManifestVersions ? 'true' : 'false';
this.exhortMvnPath = data.mvn.executable.path || 'mvn';
this.exhortNpmPath = data.npm.executable.path || 'npm';
this.exhortGoPath = data.go.executable.path || 'go';
this.exhortPython3Path = data.python3.executable.path || 'python3';
this.exhortPip3Path = data.pip3.executable.path || 'pip3';
this.exhortPythonPath = data.python.executable.path || 'python';
this.exhortPipPath = data.pip.executable.path || 'pip';
const rhdaData = data.redHatDependencyAnalytics;

this.exhortSnykToken = rhdaData.exhortSnykToken;
this.matchManifestVersions = rhdaData.matchManifestVersions ? 'true' : 'false';
this.exhortMvnPath = rhdaData.mvn.executable.path || 'mvn';
this.exhortNpmPath = rhdaData.npm.executable.path || 'npm';
this.exhortGoPath = rhdaData.go.executable.path || 'go';
this.exhortPython3Path = rhdaData.python3.executable.path || 'python3';
this.exhortPip3Path = rhdaData.pip3.executable.path || 'pip3';
this.exhortPythonPath = rhdaData.python.executable.path || 'python';
this.exhortPipPath = rhdaData.pip.executable.path || 'pip';
}
}

Expand Down
122 changes: 61 additions & 61 deletions test/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,59 +10,59 @@ describe('Config tests', () => {

const data = {
redHatDependencyAnalytics: {
exhortSnykToken: 'mockToken',
matchManifestVersions: false
},
mvn: {
executable: { path: 'mockPath' }
},
npm: {
executable: { path: 'mockPath' }
},
go: {
executable: { path: 'mockPath' }
},
python3: {
executable: { path: 'mockPath' }
},
pip3: {
executable: { path: 'mockPath' }
},
python: {
executable: { path: 'mockPath' }
},
pip: {
executable: { path: 'mockPath' }
exhortSnykToken: 'mockToken',
matchManifestVersions: false,
mvn: {
executable: { path: 'mockPath' }
},
npm: {
executable: { path: 'mockPath' }
},
go: {
executable: { path: 'mockPath' }
},
python3: {
executable: { path: 'mockPath' }
},
pip3: {
executable: { path: 'mockPath' }
},
python: {
executable: { path: 'mockPath' }
},
pip: {
executable: { path: 'mockPath' }
},
},
};

const partialData = {
redHatDependencyAnalytics: {
exhortSnykToken: 'mockToken',
matchManifestVersions: true
},
mvn: {
executable: { path: '' }
},
npm: {
executable: { path: '' }
},
go: {
executable: { path: '' }
},
python3: {
executable: { path: '' }
},
pip3: {
executable: { path: '' }
},
python: {
executable: { path: '' }
},
pip: {
executable: { path: '' }
},
};
redHatDependencyAnalytics: {
exhortSnykToken: 'mockToken',
matchManifestVersions: true,
mvn: {
executable: { path: '' }
},
npm: {
executable: { path: '' }
},
go: {
executable: { path: '' }
},
python3: {
executable: { path: '' }
},
pip3: {
executable: { path: '' }
},
python: {
executable: { path: '' }
},
pip: {
executable: { path: '' }
},
},
};

it('should initialize with default values when environment variables are not set', () => {
expect(mockConfig.triggerFullStackAnalysis).to.eq('');
Expand All @@ -79,7 +79,7 @@ describe('Config tests', () => {
expect(mockConfig.exhortPythonPath).to.eq('python');
expect(mockConfig.exhortPipPath).to.eq('pip');
});

it('should update configuration based on provided data', () => {

mockConfig.updateConfig(data);
Expand All @@ -97,16 +97,16 @@ describe('Config tests', () => {

it('should update configuration based on provided partial data', () => {

mockConfig.updateConfig(partialData);
mockConfig.updateConfig(partialData);

expect(mockConfig.exhortSnykToken).to.eq('mockToken');
expect(mockConfig.matchManifestVersions).to.eq('true');
expect(mockConfig.exhortMvnPath).to.eq('mvn');
expect(mockConfig.exhortNpmPath).to.eq('npm');
expect(mockConfig.exhortGoPath).to.eq('go');
expect(mockConfig.exhortPython3Path).to.eq('python3');
expect(mockConfig.exhortPip3Path).to.eq('pip3');
expect(mockConfig.exhortPythonPath).to.eq('python');
expect(mockConfig.exhortPipPath).to.eq('pip');
});
expect(mockConfig.exhortSnykToken).to.eq('mockToken');
expect(mockConfig.matchManifestVersions).to.eq('true');
expect(mockConfig.exhortMvnPath).to.eq('mvn');
expect(mockConfig.exhortNpmPath).to.eq('npm');
expect(mockConfig.exhortGoPath).to.eq('go');
expect(mockConfig.exhortPython3Path).to.eq('python3');
expect(mockConfig.exhortPip3Path).to.eq('pip3');
expect(mockConfig.exhortPythonPath).to.eq('python');
expect(mockConfig.exhortPipPath).to.eq('pip');
});
});

0 comments on commit 938249e

Please sign in to comment.