This commit is contained in:
code liturgy 2022-11-13 21:40:47 +00:00
parent aa222550c1
commit 96cb8df66f
4 changed files with 45 additions and 34 deletions

View File

@ -1,9 +1,14 @@
using System.Text;
namespace Sharp.Augeas.Test;
public class AugeasTests
{
private Augeas _augeas;
private const string EXAMPLE_CONF_1 = "/etc/apache2/sites-available/example.com.conf";
private const string EXAMPLE_CONF_2 = "/etc/apache2/sites-available/example2.com.conf";
public static string RandomString(int length)
{
var random = new Random();
@ -19,14 +24,14 @@ public class AugeasTests
var rootDir = Environment.CurrentDirectory + "/root";
var lensDir = Environment.CurrentDirectory + "/lens";
_augeas = new Augeas(new AugSettings(rootDir, lensDir));
_augeas.LoadFile("/etc/apache2/sites-available/example.com.conf");
_augeas.LoadFile("/etc/apache2/sites-available/example2.com.conf");
_augeas.LoadFile(EXAMPLE_CONF_1);
_augeas.LoadFile(EXAMPLE_CONF_2);
}
[Test]
public void NoExceptionThrownWhenPrintingVirtualhostTree()
{
var virtualHostConfig = "/etc/apache2/sites-available/example.com.conf";
var virtualHostConfig = EXAMPLE_CONF_1;
_augeas.PrintVirtualHostTree(virtualHostConfig);
Assert.Pass();
}
@ -34,27 +39,23 @@ public class AugeasTests
[Test]
public void NoExceptionThrownWhenPrintingPreview()
{
var virtualHostConfig = "/etc/apache2/sites-available/example.com.conf";
var virtualHostConfig = EXAMPLE_CONF_1;
_augeas.PrintPreview(virtualHostConfig);
Assert.Pass();
}
[Test]
public void GetPreviewReturnsValid()
{
var preview = _augeas.GetPreview("/files/etc/apache2/sites-available/example.com.conf");
var stringInvalid = string.IsNullOrEmpty(preview);
Assert.That(!stringInvalid);
}
[Test]
public void AfterSettingNodeGetNodeReturnsNewValue()
{
var nodePath = $"/files/etc/apache2/sites-available/example.com.conf/VirtualHost/directive[1]/arg";
var newValue = "example.com";
_augeas.SetNode(nodePath, newValue);
@ -63,11 +64,9 @@ public class AugeasTests
}
[Test]
public void SettingNodeAndSave()
{
var nodePath = $"/files/etc/apache2/sites-available/example.com.conf/VirtualHost/directive[1]/arg";
var newValue = RandomString(10);
_augeas.SetNode(nodePath, newValue);
@ -84,7 +83,6 @@ public class AugeasTests
[Test]
public void InsertNode()
{
var nodePath = $"/files/etc/apache2/sites-available/example.com.conf/VirtualHost/directive[3]";
_augeas.InsertNode(nodePath, "Test");
var node = _augeas.GetNode(nodePath);
@ -93,7 +91,6 @@ public class AugeasTests
}
[Test]
public void MatchReturnsTwoSites()
{
@ -103,10 +100,19 @@ public class AugeasTests
[Test]
public void MatchCanReturnMultipleDirectives()
{
var nodePath = $"/files/etc/apache2/sites-available/example.com.conf/VirtualHost/directive[7]/*";
var sites = _augeas.Match(nodePath);
Assert.That(sites.Length > 0);
}
[Test]
public void GetTreeVirtualHostReturnsDictionaryWithKeys()
{
var path = "/etc/apache2/sites-available/example.com.conf";
var path = EXAMPLE_CONF_1;
var tree = _augeas.GetVirtualHostTree(path);
Assert.That(tree.Count > 0);
}

View File

@ -15,4 +15,9 @@
<TargetPath>root\%(RecursiveDir)\%(Filename)%(Extension)</TargetPath>
</ContentWithTargetPath>
</ItemGroup>
<ItemGroup >
<Content Include="./Platform/Linux/libclAugeas.so">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>

View File

@ -1,7 +1,7 @@
namespace Sharp.Augeas;
public class Directive<T> : Node where T: Node
public class Directive : Node
{
public string Value;
public List<Argument<Directive<T>>> Arguments;
public List<Argument> Arguments;
}

View File

@ -1,6 +1,6 @@
namespace Sharp.Augeas
{
public class VirtualHost
public class VirtualHost : Node
{
public List<Directive<Proxy>> Directives;
public List<Argument<Proxy>> Arguments;