forked from Marusyk/grok.net
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created basic xUnit tests (Marusyk#6)
Initial xUnit test
- Loading branch information
1 parent
87ecd9d
commit 9383ff3
Showing
4 changed files
with
114 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,4 +57,5 @@ src/BenchmarkDotNet.Core/Disassemblers/* | |
# Cake | ||
tools/** | ||
!tools/packages.config | ||
.dotnet | ||
.dotnet | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.1</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" /> | ||
<PackageReference Include="xunit" Version="2.4.0" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Grok.Net\Grok.Net.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
using System; | ||
using Xunit; | ||
using GrokNet; | ||
|
||
namespace GrokNetTests | ||
{ | ||
public class UnitTests | ||
{ | ||
[Fact] | ||
public void ParseEmptyTest() | ||
{ | ||
string grokPattern = ""; | ||
Grok act = new Grok(grokPattern); | ||
string logs = ""; | ||
|
||
GrokResult grokResult = act.Parse(logs); | ||
|
||
Assert.NotNull(grokResult); | ||
Assert.Empty(grokResult); | ||
|
||
} | ||
|
||
[Fact] | ||
public void PatternCountTest() | ||
{ | ||
string grokPattern = "%{MONTHDAY:month}-%{MONTHDAY:day}-%{MONTHDAY:year} %{TIME:timestamp};%{WORD:id};%{LOGLEVEL:loglevel};%{WORD:func};%{GREEDYDATA:msg}"; | ||
Grok act = new Grok(grokPattern); | ||
string logs = @"06-21-19 21:00:13:589241;15;INFO;main;DECODED: 775233900043 DECODED BY: 18500738 DISTANCE: 1.5165 | ||
06-21-19 21:00:13:589265;156;WARN;main;DECODED: 775233900043 EMPTY DISTANCE: --------"; | ||
|
||
GrokResult grokResult = act.Parse(logs); | ||
|
||
Assert.Equal(16, grokResult.Count); | ||
} | ||
|
||
[Fact] | ||
public void MonthDayPatternTest() | ||
{ | ||
Grok act = new Grok("%{MONTHDAY:month}-%{MONTHDAY:day}-%{MONTHDAY:year} %{TIME:timestamp};%{WORD:id};%{LOGLEVEL:loglevel};%{WORD:func};%{GREEDYDATA:msg}"); | ||
string logs = @"06-21-19 21:00:13:589241;15;INFO;main;DECODED: 775233900043 DECODED BY: 18500738 DISTANCE: 1.5165 | ||
06-21-19 21:00:13:589265;156;WARN;main;DECODED: 775233900043 EMPTY DISTANCE: --------"; | ||
|
||
GrokResult grokResult = act.Parse(logs); | ||
|
||
Assert.Equal("month", grokResult[0].Key); | ||
Assert.Equal("06", grokResult[0].Value); | ||
Assert.Equal("day", grokResult[1].Key); | ||
Assert.Equal("21", grokResult[1].Value); | ||
Assert.Equal("year", grokResult[2].Key); | ||
Assert.Equal("19", grokResult[2].Value); | ||
Assert.Equal("month", grokResult[8].Key); | ||
Assert.Equal("06", grokResult[8].Value); | ||
Assert.Equal("day", grokResult[9].Key); | ||
Assert.Equal("21", grokResult[9].Value); | ||
Assert.Equal("year", grokResult[10].Key); | ||
Assert.Equal("19", grokResult[10].Value); | ||
} | ||
|
||
[Fact] | ||
public void TimePatternTest() | ||
{ | ||
Grok act = new Grok("%{MONTHDAY:month}-%{MONTHDAY:day}-%{MONTHDAY:year} %{TIME:timestamp};%{WORD:id};%{LOGLEVEL:loglevel};%{WORD:func};%{GREEDYDATA:msg}"); | ||
string logs = @"06-21-19 21:00:13:589241;15;INFO;main;DECODED: 775233900043 DECODED BY: 18500738 DISTANCE: 1.5165 | ||
06-21-19 21:00:13:589265;156;WARN;main;DECODED: 775233900043 EMPTY DISTANCE: --------"; | ||
|
||
GrokResult grokResult = act.Parse(logs); | ||
|
||
Assert.Equal("21:00:13:589241", grokResult[3].Value); | ||
Assert.Equal("21:00:13:589265", grokResult[11].Value); | ||
} | ||
|
||
[Fact] | ||
public void EmailPatternTest() | ||
{ | ||
Grok act = new Grok("%{EMAILADDRESS:email}:%{GREEDYDATA:comment}"); | ||
string logs = @"[email protected]:Free as in Free Beer"; | ||
|
||
GrokResult grokResult = act.Parse(logs); | ||
|
||
Assert.Equal("[email protected]", grokResult[0].Value); | ||
Assert.Equal("Free as in Free Beer", grokResult[1].Value); | ||
Assert.Equal("email", grokResult[0].Key); | ||
Assert.Equal("comment", grokResult[1].Key); | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters