Skip to content

Commit

Permalink
SLVSCODE-1004 improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
sophio-japharidze-sonarsource committed Feb 7, 2025
1 parent 91718f6 commit cc8dbf2
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/lsp/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function languageServerCommand(

const params = [];
if (DEBUG) {
params.push('-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8004,quiet=y');
params.push('-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000,quiet=y');
params.push('-Dsonarlint.telemetry.disabled=true');
params.push('-Dsonarlint.monitoring.disabled=true');
}
Expand Down
2 changes: 1 addition & 1 deletion src/util/dogfoodingUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ const DOGFOODING_ENVIRONMENT_VARIABLE_NAME = 'SONARSOURCE_DOGFOODING';

export function isDogfoodingEnvironment() : boolean {
return process.env[DOGFOODING_ENVIRONMENT_VARIABLE_NAME] === '1';
}
}
5 changes: 4 additions & 1 deletion src/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,11 @@ export function sonarCloudRegionToLabel(region: number): SonarCloudRegion {
}

export function sanitizeSonarCloudRegionSetting(region: string): SonarCloudRegion {
if (!region) {
return 'EU';
}
// Technically, users could put anything in the `region` setting. If it is something invalid, we default to EU.
switch (region) {
switch (region.toUpperCase()) {
case 'EU': return 'EU';
case 'US': return 'US';
default: return 'EU';
Expand Down
6 changes: 5 additions & 1 deletion test/suite/sharedConnectedModeSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import * as path from 'path';
import { selectFirstQuickPickItem } from './commons';
import { sleep } from '../testutil';

const SHARED_CONNECTED_MODE_FILE_CONTENT = '{\n' + ' "sonarCloudOrganization": "sonarsource",\n' + ' "projectKey": "autoscan.net"\n' + '}';
const SHARED_CONNECTED_MODE_FILE_CONTENT = '{\n'
+ ' "sonarCloudOrganization": "sonarsource",\n'
+ ' "projectKey": "autoscan.net"\n'
+ ' "region": "EU",\n'
+ '}';

const mockClient = ({
async getSharedConnectedModeConfigFileContent(configScopeId) {
Expand Down
17 changes: 17 additions & 0 deletions test/suite/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
getQuickPickListItemsForWorkspaceFolders,
globPatternToRegex,
isRunningAutoBuild,
sanitizeSonarCloudRegionSetting,
sonarCloudRegionToLabel,
startedInDebugMode
} from '../../src/util/util';

Expand Down Expand Up @@ -215,4 +217,19 @@ suite('util', () => {
expect(excludedPatterns[1]).to.equal('**/*.bar');
});

test('should convert SonarCloudRegion enum to label', () => {
expect(sonarCloudRegionToLabel(0)).to.equal('EU');
expect(sonarCloudRegionToLabel(1)).to.equal('US');
expect(sonarCloudRegionToLabel(2)).to.equal('EU');
expect(sonarCloudRegionToLabel(null)).to.equal('EU');
});

test('should sanitize SonarCloudRegion user setting', () => {
expect(sanitizeSonarCloudRegionSetting('EU')).to.equal('EU');
expect(sanitizeSonarCloudRegionSetting('eu')).to.equal('EU');
expect(sanitizeSonarCloudRegionSetting('US')).to.equal('US');
expect(sanitizeSonarCloudRegionSetting('us')).to.equal('US');
expect(sanitizeSonarCloudRegionSetting('APJ')).to.equal('EU');
});

});

0 comments on commit cc8dbf2

Please sign in to comment.