Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/src/Grok.Net.Tests/bin/Debug/netcoreapp2.1/Grok.Net.Tests.dll",
"args": [],
"cwd": "${workspaceFolder}/src/Grok.Net.Tests",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
42 changes: 42 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/src/Grok.Net.Tests/Grok.Net.Tests.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/src/Grok.Net.Tests/Grok.Net.Tests.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/src/Grok.Net.Tests/Grok.Net.Tests.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}
19 changes: 19 additions & 0 deletions src/Grok.Net.Tests/Grok.Net.Tests.csproj
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>
67 changes: 67 additions & 0 deletions src/Grok.Net.Tests/UnitTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using Xunit;
using GrokNet;

namespace GrokNetTests
{
public class UnitTests
{
[Fact]
public void ParseEmptyTest()
{
Grok act = new Grok("");
GrokResult result = act.Parse("");

Assert.NotNull(result);
Assert.Empty(result);
}

[Fact]
public void PatternCountTest()
{
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(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);
}


}
}
6 changes: 6 additions & 0 deletions src/Grok.Net.sln
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
..\build.sh = ..\build.sh
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Grok.Net.Tests", "Grok.Net.Tests\Grok.Net.Tests.csproj", "{F7A8D826-C853-4AB6-9DB9-EFD3D7C11D12}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -22,6 +24,10 @@ Global
{80980CE7-4509-4CBC-BEE7-E3DFD2213AE5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{80980CE7-4509-4CBC-BEE7-E3DFD2213AE5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{80980CE7-4509-4CBC-BEE7-E3DFD2213AE5}.Release|Any CPU.Build.0 = Release|Any CPU
{F7A8D826-C853-4AB6-9DB9-EFD3D7C11D12}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F7A8D826-C853-4AB6-9DB9-EFD3D7C11D12}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F7A8D826-C853-4AB6-9DB9-EFD3D7C11D12}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F7A8D826-C853-4AB6-9DB9-EFD3D7C11D12}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down