From 47c7c3acf6f685821bf65a30f58d99034e39fccf Mon Sep 17 00:00:00 2001 From: code liturgy Date: Mon, 14 Nov 2022 21:12:18 +0000 Subject: [PATCH] Add Change Tree test --- Sharp.Augeas.Test/AugeasTests.cs | 24 ++++++++++++++++++------ Sharp.Augeas/Tree/Node.cs | 4 ++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/Sharp.Augeas.Test/AugeasTests.cs b/Sharp.Augeas.Test/AugeasTests.cs index e1f2d99..d6ea3bc 100644 --- a/Sharp.Augeas.Test/AugeasTests.cs +++ b/Sharp.Augeas.Test/AugeasTests.cs @@ -7,8 +7,8 @@ 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"; + private const string ExampleConf1 = "/etc/apache2/sites-available/example.com.conf"; + private const string ExampleConf2 = "/etc/apache2/sites-available/example2.com.conf"; private static string RandomString(int length) { @@ -24,21 +24,32 @@ public class AugeasTests var rootDir = Environment.CurrentDirectory + "/root"; var lensDir = Environment.CurrentDirectory + "/lens"; _augeas = new Augeas(new AugSettings(rootDir, lensDir)); - _augeas.LoadFile(EXAMPLE_CONF_1); - _augeas.LoadFile(EXAMPLE_CONF_2); + _augeas.LoadFile(ExampleConf1); + _augeas.LoadFile(ExampleConf2); } [Test] public void GetTreeHasDirectivesAndArguments() { - var tree = _augeas.GetTree("VirtualHost", $"/files{EXAMPLE_CONF_1}/VirtualHost/*"); + var tree = _augeas.GetTree("VirtualHost", $"/files{ExampleConf1}/VirtualHost/*"); Assert.That(tree.Arguments.Count > 0 && tree.Directives.Count > 0); } + [Test] + public void TreeIsChangeable() + { + var tree = _augeas.GetTree("VirtualHost", $"/files{ExampleConf1}/VirtualHost/*"); + var directive = tree.GetDirective("ServerName"); + var newValue = RandomString(10); + directive.Set($"ServerName {newValue}"); + bool save = directive.Save(); + Assert.That(save); + } + [Test] public void NoExceptionThrownWhenPrintingPreview() { - var virtualHostConfig = EXAMPLE_CONF_1; + var virtualHostConfig = ExampleConf1; _augeas.PrintPreview(virtualHostConfig); Assert.Pass(); } @@ -107,4 +118,5 @@ public class AugeasTests Assert.That(sites.Length > 0); } + } \ No newline at end of file diff --git a/Sharp.Augeas/Tree/Node.cs b/Sharp.Augeas/Tree/Node.cs index 090115f..1320006 100644 --- a/Sharp.Augeas/Tree/Node.cs +++ b/Sharp.Augeas/Tree/Node.cs @@ -20,6 +20,10 @@ public class Node Path = path; } + /// + /// Write all pending changes to disk. Only files that had any changes made to them are written. + /// + /// public bool Save() { return _augeas.Save();