public void Exe_PreProcFails() { // Arrange BootstrapperTestUtils.EnsureDefaultPropertiesFileDoesNotExist(); using (InitializeNonTeamBuildEnvironment(RootDir)) { MockProcessors(false, true); // Act var logger = CheckExecutionFails(AnalysisPhase.PreProcessing, true, "/install:true", // this argument should just pass through "/d:sonar.verbose=true", "/d:sonar.host.url=http://host:9", "/d:another.key=will be ignored"); // Assert logger.AssertWarningsLogged(0); logger.AssertVerbosity(LoggerVerbosity.Debug); AssertPreProcessorArgs("/install:true", "/d:sonar.verbose=true", "/d:sonar.host.url=http://host:9", "/d:another.key=will be ignored"); AssertPostProcessorNotCalled(); } }
public void Exe_PreProc_UrlIsRequired() { // Arrange BootstrapperTestUtils.EnsureDefaultPropertiesFileDoesNotExist(); string rootDir = TestUtils.CreateTestSpecificFolder(this.TestContext); using (InitializeNonTeamBuildEnvironment(rootDir)) { string binDir = CalculateBinDir(rootDir); MockBuildAgentUpdater mockUpdater = new MockBuildAgentUpdater(); // Act TestLogger logger = CheckExecutionFails(mockUpdater, "begin"); // Assert mockUpdater.AssertUpdateNotAttempted(); mockUpdater.AssertVersionNotChecked(); AssertDirectoryDoesNotExist(binDir); logger.AssertErrorLogged(SonarQube.Bootstrapper.Resources.ERROR_Args_UrlRequired); logger.AssertErrorsLogged(1); } }
public void Exe_PreProc_VersionCheckSucceeds_PreProcSucceeds() { // Arrange BootstrapperTestUtils.EnsureDefaultPropertiesFileDoesNotExist(); string rootDir = TestUtils.CreateTestSpecificFolder(this.TestContext); using (InitializeNonTeamBuildEnvironment(rootDir)) { string binDir = CalculateBinDir(rootDir); MockBuildAgentUpdater mockUpdater = CreateValidUpdater(binDir, "http://anotherHost"); mockUpdater.Updating += (sender, args) => { AssertDirectoryExists(args.TargetDir); DummyExeHelper.CreateDummyPreProcessor(args.TargetDir, 0 /* pre-proc succeeds */); }; // Act TestLogger logger = CheckExecutionSucceeds(mockUpdater, "/d:sonar.host.url=http://anotherHost", "begin"); // Assert mockUpdater.AssertUpdateAttempted(); mockUpdater.AssertVersionChecked(); logger.AssertWarningsLogged(0); logger.AssertVerbosity(VerbosityCalculator.DefaultLoggingVerbosity); string logPath = DummyExeHelper.AssertDummyPreProcLogExists(binDir, this.TestContext); DummyExeHelper.AssertExpectedLogContents(logPath, "/d:sonar.host.url=http://anotherHost"); } }
public void Initialize() { // The project setup means the default properties file will automatically // be copied alongside the product binaries.st of these tests assume // the default properties file does not exist so we'll ensure it doesn't. // Any tests that do require default properties file should re-create it // with known content. BootstrapperTestUtils.EnsureDefaultPropertiesFileDoesNotExist(); }
private static string CreateDefaultPropertiesFile(AnalysisProperties defaultProperties) { // NOTE: don't forget to delete this file when the test that uses it // completes, otherwise it may affect subsequent tests. string defaultPropertiesFilePath = BootstrapperTestUtils.GetDefaultPropertiesFilePath(); defaultProperties.Save(defaultPropertiesFilePath); return(defaultPropertiesFilePath); }
public void Exe_CopyDLLs() { // Arrange BootstrapperTestUtils.EnsureDefaultPropertiesFileDoesNotExist(); using (InitializeNonTeamBuildEnvironment(RootDir)) { // Act var logger = CheckExecutionSucceeds(AnalysisPhase.PreProcessing, false, "/d:sonar.host.url=http://anotherHost"); // Assert Assert.IsTrue(File.Exists(Path.Combine(TempDir, "bin", "SonarQube.Common.dll"))); Assert.IsTrue(File.Exists(Path.Combine(TempDir, "bin", "SonarQube.Integration.Tasks.dll"))); } }
public void Exe_CopyDLLs() { // Arrange BootstrapperTestUtils.EnsureDefaultPropertiesFileDoesNotExist(); using (InitializeNonTeamBuildEnvironment(RootDir)) { // Act CheckExecutionSucceeds(AnalysisPhase.PreProcessing, false, "/d:sonar.host.url=http://anotherHost"); // Assert File.Exists(Path.Combine(TempDir, "bin", "SonarScanner.MSBuild.Common.dll")).Should().BeTrue(); File.Exists(Path.Combine(TempDir, "bin", "SonarScanner.MSBuild.Tasks.dll")).Should().BeTrue(); } }
public void Exe_PreProcSucceeds() { // Arrange BootstrapperTestUtils.EnsureDefaultPropertiesFileDoesNotExist(); using (InitializeNonTeamBuildEnvironment(RootDir)) { // Act var logger = CheckExecutionSucceeds(AnalysisPhase.PreProcessing, false, "/d:sonar.host.url=http://anotherHost"); // Assert logger.AssertWarningsLogged(0); logger.AssertVerbosity(VerbosityCalculator.DefaultLoggingVerbosity); AssertPreProcessorArgs("/d:sonar.host.url=http://anotherHost"); } }
public void CopyDlls_WhenFileExistAndAreLockedButDifferentVersion_Fails() { // Arrange BootstrapperTestUtils.EnsureDefaultPropertiesFileDoesNotExist(); using (InitializeNonTeamBuildEnvironment(RootDir)) { Directory.CreateDirectory(Path.Combine(TempDir, "bin")); var file1 = File.Create(Path.Combine(TempDir, "bin", "SonarScanner.MSBuild.Common.dll")); var file2 = File.Create(Path.Combine(TempDir, "bin", "SonarScanner.MSBuild.Tasks.dll")); int callCount = 0; Func <string, Version> getAssemblyVersion = _ => { if (callCount == 0) { callCount++; return(new Version("1.0")); } return(new Version("2.0")); }; // Act var logger = CheckExecutionFails(AnalysisPhase.PreProcessing, false, getAssemblyVersion, "/d:sonar.host.url=http://anotherHost"); // Assert File.Exists(Path.Combine(TempDir, "bin", "SonarScanner.MSBuild.Common.dll")).Should().BeTrue(); File.Exists(Path.Combine(TempDir, "bin", "SonarScanner.MSBuild.Tasks.dll")).Should().BeTrue(); logger.DebugMessages.Should().HaveCount(3); logger.DebugMessages[0].Should().Match("Cannot delete directory: '*\\.sonarqube\\bin' because The process cannot access the file 'SonarScanner.MSBuild.Common.dll' because it is being used by another process.."); logger.DebugMessages[1].Should().Match("Cannot delete file: '*\\.sonarqube\\bin\\SonarScanner.MSBuild.Common.dll' because The process cannot access the file 'SonarScanner.MSBuild.Common.dll' because it is being used by another process.."); logger.DebugMessages[2].Should().Match("Cannot delete file: '*\\.sonarqube\\bin\\SonarScanner.MSBuild.Tasks.dll' because The process cannot access the file 'SonarScanner.MSBuild.Tasks.dll' because it is being used by another process.."); logger.AssertErrorLogged(@"Cannot copy a different version of the SonarScanner for MSBuild assemblies because they are used by a running MSBuild/.Net Core process. To resolve this problem try one of the following: - Analyze this project using the same version of SonarScanner for MSBuild - Build your project with the '/nr:false' switch"); // Do not close before to ensure the file is locked file1.Close(); file2.Close(); } }
public void CopyDlls_WhenFileExistButAreNotLocked_FilesAreCopied() { // Arrange BootstrapperTestUtils.EnsureDefaultPropertiesFileDoesNotExist(); using (InitializeNonTeamBuildEnvironment(RootDir)) { Directory.CreateDirectory(Path.Combine(TempDir, "bin")); File.Create(Path.Combine(TempDir, "bin", "SonarScanner.MSBuild.Common.dll")).Close(); File.Create(Path.Combine(TempDir, "bin", "SonarScanner.MSBuild.Tasks.dll")).Close(); // Act CheckExecutionSucceeds(AnalysisPhase.PreProcessing, false, null, "/d:sonar.host.url=http://anotherHost"); // Assert File.Exists(Path.Combine(TempDir, "bin", "SonarScanner.MSBuild.Common.dll")).Should().BeTrue(); File.Exists(Path.Combine(TempDir, "bin", "SonarScanner.MSBuild.Tasks.dll")).Should().BeTrue(); } }
public void Exe_PreProc_VersionCheckSucceeds_PreProcFails() { // Arrange BootstrapperTestUtils.EnsureDefaultPropertiesFileDoesNotExist(); string rootDir = TestUtils.CreateTestSpecificFolder(this.TestContext); using (InitializeNonTeamBuildEnvironment(rootDir)) { string binDir = CalculateBinDir(rootDir); MockBuildAgentUpdater mockUpdater = CreateValidUpdater(binDir, "http://host:9"); mockUpdater.Updating += (sender, args) => { AssertDirectoryExists(args.TargetDir); DummyExeHelper.CreateDummyPreProcessor(args.TargetDir, 1 /* pre-proc fails */); }; // Act TestLogger logger = CheckExecutionFails(mockUpdater, "begin", "/install:true", // this argument should just pass through "/d:sonar.verbose=true", "/d:sonar.host.url=http://host:9", "/d:another.key=will be ignored"); // Assert mockUpdater.AssertUpdateAttempted(); mockUpdater.AssertVersionChecked(); logger.AssertWarningsLogged(0); logger.AssertVerbosity(LoggerVerbosity.Debug); // sonar.verbose=true was specified string logPath = DummyExeHelper.AssertDummyPreProcLogExists(binDir, this.TestContext); DummyExeHelper.AssertExpectedLogContents(logPath, "/install:true", "/d:sonar.verbose=true", "/d:sonar.host.url=http://host:9", "/d:another.key=will be ignored"); } }
public void Exe_PreProcCleansTemp() { // Arrange BootstrapperTestUtils.EnsureDefaultPropertiesFileDoesNotExist(); using (InitializeNonTeamBuildEnvironment(RootDir)) { // Create dummy file in Temp var filePath = Path.Combine(TempDir, "myfile"); Directory.CreateDirectory(TempDir); var stream = File.Create(filePath); stream.Close(); Assert.IsTrue(File.Exists(filePath)); // Act var logger = CheckExecutionSucceeds(AnalysisPhase.PreProcessing, false, "/d:sonar.host.url=http://anotherHost"); // Assert Assert.IsFalse(File.Exists(filePath)); } }
public void CopyDlls_WhenFileExistAndAreLockedButSameVersion_DoNothing() { // Arrange BootstrapperTestUtils.EnsureDefaultPropertiesFileDoesNotExist(); using (InitializeNonTeamBuildEnvironment(RootDir)) { Directory.CreateDirectory(Path.Combine(TempDir, "bin")); var file1 = File.Create(Path.Combine(TempDir, "bin", "SonarScanner.MSBuild.Common.dll")); var file2 = File.Create(Path.Combine(TempDir, "bin", "SonarScanner.MSBuild.Tasks.dll")); // Act CheckExecutionSucceeds(AnalysisPhase.PreProcessing, false, _ => new Version(), "/d:sonar.host.url=http://anotherHost"); // Assert File.Exists(Path.Combine(TempDir, "bin", "SonarScanner.MSBuild.Common.dll")).Should().BeTrue(); File.Exists(Path.Combine(TempDir, "bin", "SonarScanner.MSBuild.Tasks.dll")).Should().BeTrue(); // Do not close before to ensure the file is locked file1.Close(); file2.Close(); } }