Added Tests for Date filter.
This commit is contained in:
49
TimberWinR.UnitTests/DateFilterTests.cs
Normal file
49
TimberWinR.UnitTests/DateFilterTests.cs
Normal 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");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -47,6 +47,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Configuration.cs" />
|
<Compile Include="Configuration.cs" />
|
||||||
|
<Compile Include="DateFilterTests.cs" />
|
||||||
<Compile Include="GrokFilterTests.cs" />
|
<Compile Include="GrokFilterTests.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ namespace TimberWinR.Parser
|
|||||||
{
|
{
|
||||||
string field = Match[0];
|
string field = Match[0];
|
||||||
|
|
||||||
CultureInfo ci = new CultureInfo(Locale);
|
CultureInfo ci = CultureInfo.CreateSpecificCulture(Locale);
|
||||||
|
|
||||||
JToken token = null;
|
JToken token = null;
|
||||||
if (json.TryGetValue(field, out token))
|
if (json.TryGetValue(field, out token))
|
||||||
|
|||||||
Reference in New Issue
Block a user