Skip to content

Commit

Permalink
Update InstallerEngine tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bording committed Feb 28, 2024
1 parent 49c044d commit ee01957
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 57 deletions.
Expand Up @@ -11,7 +11,4 @@
<add key="ServiceControl.Audit/EnableFullTextSearchOnBodies"
value="false" />
</appSettings>
<runtime>
<gcServer enabled="true" />
</runtime>
</configuration>
Expand Up @@ -13,7 +13,4 @@
<add key="ServiceControl.Audit/DBPath" value="value-not-asserted" />
<add key="ServiceControl.Audit/DatabaseMaintenancePort" value="33333" />
</appSettings>
<runtime>
<gcServer enabled="true" />
</runtime>
</configuration>
Expand Up @@ -13,7 +13,4 @@
<add key="ServiceControl.Audit/DBPath" value="value-not-asserted" />
<add key="ServiceControl.Audit/DatabaseMaintenancePort" value="33333" />
</appSettings>
<runtime>
<gcServer enabled="true" />
</runtime>
</configuration>
Expand Up @@ -3,9 +3,7 @@
using System;
using System.IO;
using System.ServiceProcess;
using System.Xml;
using NUnit.Framework;
using ServiceControlInstaller.Engine.Configuration.ServiceControl;
using ServiceControlInstaller.Engine.Instances;
using ServiceControlInstaller.Engine.Services;

Expand All @@ -14,44 +12,6 @@ class AuditInstanceTests : InstallationFixture
{
const string zipResourceName = "Particular.ServiceControl.Audit.zip";

[Test]
public void Should_default_to_raven35_when_no_config_entry_exists()
{
var newInstance = ServiceControlAuditNewInstance.CreateWithPersistence("RavenDB35");

newInstance.InstallPath = InstallPath;
newInstance.TransportPackage = ServiceControlCoreTransports.Find("LearningTransport");
newInstance.DBPath = DbPath;
newInstance.LogPath = LogPath;
newInstance.HostName = "localhost";
newInstance.DatabaseMaintenancePort = 33333;

newInstance.CopyFiles(zipResourceName);
newInstance.WriteConfigurationFile();

//delete the setting to simulate an existing older instance
var configPath = Path.Combine(InstallPath, "ServiceControl.Audit.exe.config");
var existingConfigFile = new XmlDocument();
existingConfigFile.Load(configPath);
var entry = existingConfigFile.SelectSingleNode($"//add[@key='{AuditInstanceSettingsList.PersistenceType.Name}']");
entry.ParentNode.RemoveChild(entry);
existingConfigFile.Save(configPath);

var instance = new ServiceControlAuditInstance(new FakeWindowsServiceController(Path.Combine(InstallPath, "ServiceControl.Audit.exe")));

instance.Reload();

instance.UpgradeFiles(zipResourceName);
// Don't want any persistence DLL, bit awkward but serves the purpose of the test
FileAssert.DoesNotExist(Path.Combine(InstallPath, "ServiceControl.Audit.Persistence.RavenDb.dll"));
FileAssert.DoesNotExist(Path.Combine(InstallPath, "ServiceControl.Audit.Persistence.RavenDB.dll"));
FileAssert.DoesNotExist(Path.Combine(InstallPath, "ServiceControl.Audit.Persistence.RavenDb5.dll"));

var manifestFilePath = Path.Combine(InstallPath, "persistence.manifest");
var manifestText = File.ReadAllText(manifestFilePath);
StringAssert.Contains("RavenDB 3.5", manifestText);
}

[Test]
public void Should_update_existing_persister()
{
Expand All @@ -69,16 +29,17 @@ public void Should_update_existing_persister()
newInstance.WriteConfigurationFile();

var instance = new ServiceControlAuditInstance(new FakeWindowsServiceController(Path.Combine(InstallPath, "ServiceControl.Audit.exe")));
var backup = instance.BackupAppConfig();

instance.Reload();
instance.UpgradeFiles(zipResourceName);

var persisterFilePath = Path.Combine(InstallPath, "ServiceControl.Audit.Persistence.RavenDB.dll");
var configFile = Path.Combine(InstallPath, "ServiceControl.Audit.exe.config");
FileAssert.Exists(configFile);

//delete the persistence dll to make sure it gets re-installed
File.Delete(persisterFilePath);
var configText = File.ReadAllText(configFile);
var backupText = File.ReadAllText(backup);

instance.UpgradeFiles(zipResourceName);
FileAssert.Exists(persisterFilePath);
Assert.That(configText, Is.EqualTo(backupText));
}

[Test]
Expand Down
Expand Up @@ -26,7 +26,6 @@ public void Should_install_modern_raven_for_new_instances()
newInstance.CopyFiles(zipResourceName);
newInstance.WriteConfigurationFile();

FileAssert.Exists(Path.Combine(InstallPath, "ServiceControl.Audit.Persistence.RavenDB.dll"));
var configFile = File.ReadAllText(Path.Combine(InstallPath, "ServiceControl.Audit.exe.config"));

Approver.Verify(configFile, input => input.Replace(DbPath, "value-not-asserted").Replace(LogPath, "value-not-asserted"));
Expand Down
2 changes: 1 addition & 1 deletion src/ServiceControlInstaller.Engine/FileSystem/FileUtils.cs
Expand Up @@ -38,7 +38,7 @@ public static void DeleteDirectory(string path, bool recursive, bool contentsOnl
var files = Directory.GetFiles(path);
foreach (var f in files)
{
if (excludes.Any(p => string.Equals(p, Path.GetDirectoryName(f), StringComparison.OrdinalIgnoreCase)))
if (excludes.Any(p => string.Equals(p, Path.GetFileName(f), StringComparison.OrdinalIgnoreCase)))
{
continue;
}
Expand Down

0 comments on commit ee01957

Please sign in to comment.