Added Tests for Date filter.

This commit is contained in:
Eric Fontana
2014-07-31 13:18:04 -04:00
parent 31643a3753
commit 820797fe63
3 changed files with 51 additions and 1 deletions

View File

@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
using TimberWinR.Parser;
using Newtonsoft.Json.Linq;
namespace TimberWinR.UnitTests
{
[TestFixture]
public class DateFilterTests
{
[Test]
public void TestDate1()
{
JObject json = new JObject
{
{"message", "2014-01-31 08:23:47,123"}
};
string grokJson = @"{
""TimberWinR"":{
""Filters"":[
{
""date"":{
""match"":[
""message"",
""yyyy-MM-dd HH:mm:ss,fff""
]
}
}]
}
}";
Configuration c = Configuration.FromString(grokJson);
DateFilter date = c.Filters.First() as DateFilter;
Assert.IsTrue(date.Apply(json));
var ts = json["@timestamp"].ToString();
Assert.AreEqual(ts, "1/31/2014 8:23:47 AM");
}
}
}

View File

@@ -47,6 +47,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Configuration.cs" />
<Compile Include="DateFilterTests.cs" />
<Compile Include="GrokFilterTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>

View File

@@ -48,7 +48,7 @@ namespace TimberWinR.Parser
{
string field = Match[0];
CultureInfo ci = new CultureInfo(Locale);
CultureInfo ci = CultureInfo.CreateSpecificCulture(Locale);
JToken token = null;
if (json.TryGetValue(field, out token))