Skip to content

Commit

Permalink
feat: add new options to windows install script and installer
Browse files Browse the repository at this point in the history
* fix test error
* add validation for empty opamp folder when remotely managed
* more opamp tests
  • Loading branch information
fguimond committed Feb 8, 2024
1 parent 285bef8 commit 1b1358a
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public ConfigUpdater(StreamReader streamReader) {

public void Update(Config config)
{
if (config.RemotelyManaged && string.IsNullOrEmpty(config.OpAmpFolder))
{
throw new MissingConfigurationException("OpAmpFolder");
}

YamlMappingNode root = (YamlMappingNode)this.Document.RootNode;

EnsureMapKey(root, "extensions");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ public static ActionResult UpdateConfig(Session session)
var opAmpFolder = session.CustomActionData[pOpAmpFolder];
var api = session.CustomActionData[pApi];

if (remotelyManaged && string.IsNullOrEmpty(opAmpFolder))
{
ShowErrorMessage(session, ecMissingCustomActionData, pOpAmpFolder);
return ActionResult.Failure;
}

// Load config from disk and replace values
Config config = new Config { InstallationToken = installationToken, RemotelyManaged = remotelyManaged, Ephemeral = ephemeral,
OpAmpFolder = opAmpFolder, Api = api };
Expand Down
5 changes: 5 additions & 0 deletions packaging/msi/SumoLogic.wixext/SumoLogic.wixext/Exceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ public class TagValueLengthExceededException : Exception
{
public TagValueLengthExceededException(string message) { }
}

public class MissingConfigurationException : Exception
{
public MissingConfigurationException(string message) { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void InstallationTokenAssertions(Config config, StreamReader sr)
Assert.AreEqual("yaz", collectorFields.Children["xaz"]);
}

public void OpAmpAssertion(Config config, StreamReader sr)
public void OpAmpAssertions(Config config, StreamReader sr)
{
YamlStream ys = new YamlStream();
ys.Load(sr);
Expand All @@ -65,13 +65,20 @@ public void OpAmpAssertion(Config config, StreamReader sr)
Assert.AreEqual(YamlNodeType.Mapping, root.Children["extensions"].NodeType);
var extensions = (YamlMappingNode)root.Children["extensions"];

Assert.IsTrue(extensions.Children.ContainsKey("opamp"));
Assert.AreEqual(YamlNodeType.Mapping, extensions.Children["opamp"].NodeType);
var opamp = (YamlMappingNode)extensions.Children["opamp"];
if (config.RemotelyManaged)
{
Assert.IsTrue(extensions.Children.ContainsKey("opamp"));
Assert.AreEqual(YamlNodeType.Mapping, extensions.Children["opamp"].NodeType);
var opamp = (YamlMappingNode)extensions.Children["opamp"];

Assert.IsTrue(opamp.Children.ContainsKey("remote_configuration_directory"));
Assert.AreEqual(YamlNodeType.Scalar, opamp.Children["remote_configuration_directory"].NodeType);
Assert.AreEqual(config.OpAmpFolder, opamp.Children["remote_configuration_directory"].ToString());
Assert.IsTrue(opamp.Children.ContainsKey("remote_configuration_directory"));
Assert.AreEqual(YamlNodeType.Scalar, opamp.Children["remote_configuration_directory"].NodeType);
Assert.AreEqual(config.OpAmpFolder, opamp.Children["remote_configuration_directory"].ToString());
}
else
{
Assert.IsFalse(extensions.Children.ContainsKey("opamp"));
}

Assert.IsTrue(root.Children.ContainsKey("service"));
Assert.AreEqual(YamlNodeType.Mapping, root.Children["service"].NodeType);
Expand All @@ -80,7 +87,14 @@ public void OpAmpAssertion(Config config, StreamReader sr)
Assert.IsTrue(service.Children.ContainsKey("extensions"));
Assert.AreEqual(YamlNodeType.Sequence, service.Children["extensions"].NodeType);
var serviceExtensions = (YamlSequenceNode)service.Children["extensions"];
Assert.IsTrue(serviceExtensions.Contains("opamp"));
if (config.RemotelyManaged)
{
Assert.IsTrue(serviceExtensions.Children.Contains("opamp"));
}
else
{
Assert.IsFalse(serviceExtensions.Children.Contains("opamp"));
}
}

[TestMethod]
Expand Down Expand Up @@ -215,8 +229,52 @@ public void TestUpdate_OpAmp()

ms.Seek(0, SeekOrigin.Begin);

OpAmpAssertion(config, sr);
OpAmpAssertions(config, sr);
}
}

[TestMethod]
[ExpectedException(typeof(MissingConfigurationException), "OpAmpFolder")]
public void TestUpdate_OpAmpNoFolder()
{
var filePath = Path.Combine(testDataPath, "with-extensions-block.yaml");
var config = new Config { InstallationToken = "foobar", Ephemeral = true, RemotelyManaged = true };
config.SetCollectorFieldsFromTags(@"foo=bar,baz=kaz,xaz=yaz");

using (MemoryStream ms = new MemoryStream())
{
var configUpdater = new ConfigUpdater(new StreamReader(filePath));
configUpdater.Update(config);
configUpdater.Save(new StreamWriter(ms));
}
}

[TestMethod]
public void TestUpdate_NoOpAmpWithFolder()
{
var filePath = Path.Combine(testDataPath, "with-extensions-block.yaml");
var config = new Config { InstallationToken = "foobar", Ephemeral = true, RemotelyManaged = false, OpAmpFolder = "/opamp" };
config.SetCollectorFieldsFromTags(@"foo=bar,baz=kaz,xaz=yaz");

using (MemoryStream ms = new MemoryStream())
{
var configUpdater = new ConfigUpdater(new StreamReader(filePath));
configUpdater.Update(config);
configUpdater.Save(new StreamWriter(ms));

ms.Seek(0, SeekOrigin.Begin);

StreamReader sr = new StreamReader(ms);
while (!sr.EndOfStream)
{
Console.WriteLine(sr.ReadLine());
}

ms.Seek(0, SeekOrigin.Begin);

OpAmpAssertions(config, sr);
}
}

}
}

0 comments on commit 1b1358a

Please sign in to comment.