Adding unit tests for correct attribute counts
This commit is contained in:
@@ -8,6 +8,7 @@ using TimberWinR;
|
||||
using TimberWinR.Inputs;
|
||||
using TimberWinR.Filters;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using TimberWinR.Parser;
|
||||
|
||||
namespace TimberWinR.UnitTests
|
||||
{
|
||||
@@ -69,7 +70,55 @@ namespace TimberWinR.UnitTests
|
||||
catch (TimberWinR.Parser.Grok.GrokAddTagException ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestRedisHostCount()
|
||||
{
|
||||
string redisJson = @"{
|
||||
""TimberWinR"":
|
||||
{
|
||||
""Outputs"":
|
||||
{
|
||||
""Redis"":
|
||||
[{
|
||||
""host"":
|
||||
[
|
||||
""logaggregator.vistaprint.svc""
|
||||
]
|
||||
}]
|
||||
}
|
||||
}
|
||||
}";
|
||||
|
||||
|
||||
Configuration c = Configuration.FromString(redisJson);
|
||||
RedisOutput redis = c.RedisOutputs.First() as RedisOutput;
|
||||
Assert.IsTrue(redis.Host.Length >= 1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDateFilterMatchCount()
|
||||
{
|
||||
string dateJson = @"{
|
||||
""TimberWinR"":{
|
||||
""Filters"":[
|
||||
{
|
||||
""date"":{
|
||||
""match"":[
|
||||
""timestamp"",
|
||||
""MMM d HH:mm:sss"",
|
||||
""MMM dd HH:mm:ss""
|
||||
],
|
||||
}
|
||||
}]
|
||||
}
|
||||
}";
|
||||
|
||||
|
||||
Configuration c = Configuration.FromString(dateJson);
|
||||
DateFilter date = c.Filters.First() as DateFilter;
|
||||
Assert.IsTrue(date.Match.Length >= 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,7 +179,7 @@ namespace TimberWinR.UnitTests
|
||||
}
|
||||
}";
|
||||
|
||||
// Postitive Tests
|
||||
// Positive Tests
|
||||
Configuration c = Configuration.FromString(grokJson1);
|
||||
Grok grok = c.Filters.First() as Grok;
|
||||
Assert.IsTrue(grok.Apply(json));
|
||||
@@ -239,5 +239,115 @@ namespace TimberWinR.UnitTests
|
||||
Assert.IsTrue(json["tags"].Children().Count() == 1);
|
||||
Assert.AreEqual(json["tags"][0].ToString(), "tag2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestMatchCount()
|
||||
{
|
||||
string grokJson = @"{
|
||||
""TimberWinR"":{
|
||||
""Filters"":[
|
||||
{
|
||||
""grok"":{
|
||||
""condition"": ""[type] == \""Win32-FileLog\"""",
|
||||
""match"":[
|
||||
""Text"",
|
||||
""""
|
||||
],
|
||||
""remove_tag"":[
|
||||
""tag1""
|
||||
]
|
||||
}
|
||||
}]
|
||||
}
|
||||
}";
|
||||
|
||||
Configuration c = Configuration.FromString(grokJson);
|
||||
Grok grok = c.Filters.First() as Grok;
|
||||
Assert.AreEqual(2, grok.Match.Length);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestRemoveFieldCount()
|
||||
{
|
||||
string grokJson = @"{
|
||||
""TimberWinR"":{
|
||||
""Filters"":[
|
||||
{
|
||||
""grok"":{
|
||||
""condition"": ""[type] == \""Win32-FileLog\"""",
|
||||
""match"":[
|
||||
""Text"",
|
||||
""""
|
||||
],
|
||||
""remove_field"":[
|
||||
""ComputerName""
|
||||
]
|
||||
}
|
||||
}]
|
||||
}
|
||||
}";
|
||||
|
||||
Configuration c = Configuration.FromString(grokJson);
|
||||
Grok grok = c.Filters.First() as Grok;
|
||||
Assert.IsTrue(grok.RemoveField.Length >= 1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestAddFieldCount()
|
||||
{
|
||||
string grokJson = @"{
|
||||
""TimberWinR"":{
|
||||
""Filters"":[
|
||||
{
|
||||
""grok"":{
|
||||
""condition"": ""[type] == \""Win32-FileLog\"""",
|
||||
""match"":[
|
||||
""Text"",
|
||||
""""
|
||||
],
|
||||
""remove_tag"":[
|
||||
""tag1""
|
||||
],
|
||||
""add_field"":[
|
||||
""host"",
|
||||
""%{ComputerName}""
|
||||
]
|
||||
}
|
||||
}]
|
||||
}
|
||||
}";
|
||||
|
||||
Configuration c = Configuration.FromString(grokJson);
|
||||
Grok grok = c.Filters.First() as Grok;
|
||||
Assert.IsTrue(grok.AddField.Length % 2 == 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestAddTagCount()
|
||||
{
|
||||
string grokJson = @"{
|
||||
""TimberWinR"":{
|
||||
""Filters"":[
|
||||
{
|
||||
""grok"":{
|
||||
""condition"": ""[type] == \""Win32-FileLog\"""",
|
||||
""match"":[
|
||||
""Text"",
|
||||
""""
|
||||
],
|
||||
""add_tag"":[
|
||||
""rn_%{RecordNumber}"",
|
||||
""bar""
|
||||
]
|
||||
}
|
||||
}]
|
||||
}
|
||||
}";
|
||||
|
||||
Configuration c = Configuration.FromString(grokJson);
|
||||
Grok grok = c.Filters.First() as Grok;
|
||||
Assert.IsTrue(grok.AddTag.Length >= 1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,10 +94,15 @@ namespace TimberWinR
|
||||
c._events = x.TimberWinR.Inputs.WindowsEvents.ToList();
|
||||
c._iisw3clogs = x.TimberWinR.Inputs.IISW3CLogs.ToList();
|
||||
c._logs = x.TimberWinR.Inputs.Logs.ToList();
|
||||
c._redisOutputs = x.TimberWinR.Outputs.Redis.ToList();
|
||||
|
||||
c._tcps = x.TimberWinR.Inputs.Tcps.ToList();
|
||||
}
|
||||
|
||||
if (x.TimberWinR.Outputs != null)
|
||||
{
|
||||
c._redisOutputs = x.TimberWinR.Outputs.Redis.ToList();
|
||||
}
|
||||
|
||||
if (x.TimberWinR.Filters != null)
|
||||
c._filters = x.TimberWinR.AllFilters.ToList();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user