Search in sources :

Example 1 with CiConfiguration

use of org.sonar.scanner.ci.CiConfiguration in project sonarqube by SonarSource.

the class CirrusCiTest method log_warning_if_missing_commit_variable.

@Test
public void log_warning_if_missing_commit_variable() {
    setEnvVariable("CIRRUS_PR", "1234");
    CiConfiguration configuration = underTest.loadConfiguration();
    assertThat(configuration.getScmRevision()).isEmpty();
    assertThat(logs.logs(LoggerLevel.WARN)).contains("Missing environment variable CIRRUS_CHANGE_IN_REPO");
}
Also used : CiConfiguration(org.sonar.scanner.ci.CiConfiguration) Test(org.junit.Test)

Example 2 with CiConfiguration

use of org.sonar.scanner.ci.CiConfiguration in project sonarqube by SonarSource.

the class ScmRevisionImplTest method ignore_failure_if_scm_does_not_support_revisions.

@Test
public void ignore_failure_if_scm_does_not_support_revisions() {
    CiConfiguration ciConfiguration = mock(CiConfiguration.class);
    when(ciConfiguration.getScmRevision()).thenReturn(Optional.empty());
    Map<String, String> scannerConfiguration = new HashMap<>();
    ScmConfiguration scmConfiguration = mock(ScmConfiguration.class, RETURNS_DEEP_STUBS);
    when(scmConfiguration.provider().revisionId(any())).thenThrow(new UnsupportedOperationException("BOOM"));
    InputModuleHierarchy moduleHierarchy = mock(InputModuleHierarchy.class, RETURNS_DEEP_STUBS);
    ScmRevisionImpl underTest = new ScmRevisionImpl(ciConfiguration, new ScannerProperties(scannerConfiguration), scmConfiguration, moduleHierarchy);
    assertThat(underTest.get()).isEmpty();
}
Also used : InputModuleHierarchy(org.sonar.scanner.fs.InputModuleHierarchy) ScannerProperties(org.sonar.scanner.bootstrap.ScannerProperties) HashMap(java.util.HashMap) CiConfiguration(org.sonar.scanner.ci.CiConfiguration) Test(org.junit.Test)

Example 3 with CiConfiguration

use of org.sonar.scanner.ci.CiConfiguration in project sonarqube by SonarSource.

the class ScmRevisionImplTest method testGet.

private Optional<String> testGet(@Nullable String cliValue, @Nullable String ciValue, @Nullable String scmValue) {
    CiConfiguration ciConfiguration = mock(CiConfiguration.class);
    when(ciConfiguration.getScmRevision()).thenReturn(Optional.ofNullable(ciValue));
    Map<String, String> scannerConfiguration = new HashMap<>();
    scannerConfiguration.put("sonar.scm.revision", cliValue);
    ScmConfiguration scmConfiguration = mock(ScmConfiguration.class, RETURNS_DEEP_STUBS);
    when(scmConfiguration.provider().revisionId(any())).thenReturn(scmValue);
    InputModuleHierarchy moduleHierarchy = mock(InputModuleHierarchy.class, RETURNS_DEEP_STUBS);
    ScmRevisionImpl underTest = new ScmRevisionImpl(ciConfiguration, new ScannerProperties(scannerConfiguration), scmConfiguration, moduleHierarchy);
    return underTest.get();
}
Also used : InputModuleHierarchy(org.sonar.scanner.fs.InputModuleHierarchy) ScannerProperties(org.sonar.scanner.bootstrap.ScannerProperties) HashMap(java.util.HashMap) CiConfiguration(org.sonar.scanner.ci.CiConfiguration)

Example 4 with CiConfiguration

use of org.sonar.scanner.ci.CiConfiguration in project sonarqube by SonarSource.

the class CodeMagicTest method loadConfiguration_commitEnvVariableNotAvailable_addScmRevisionToConfig.

@Test
public void loadConfiguration_commitEnvVariableNotAvailable_addScmRevisionToConfig() {
    setEnvVariable("FCI_BUILD_ID", "1");
    CiConfiguration ciConfiguration = underTest.loadConfiguration();
    List<String> logs = logTester.logs(LoggerLevel.WARN);
    assertThat(ciConfiguration.getScmRevision()).isEmpty();
    assertThat(logs).hasSize(1);
    assertThat(logs.get(0)).isEqualTo("Missing environment variable FCI_COMMIT");
}
Also used : CiConfiguration(org.sonar.scanner.ci.CiConfiguration) Test(org.junit.Test)

Aggregations

CiConfiguration (org.sonar.scanner.ci.CiConfiguration)4 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 ScannerProperties (org.sonar.scanner.bootstrap.ScannerProperties)2 InputModuleHierarchy (org.sonar.scanner.fs.InputModuleHierarchy)2