-
Notifications
You must be signed in to change notification settings - Fork 57
IPv4 Pattern test #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
3db13d2
Initial xUnit test
a583941
Additional pattern tests
35e7994
Initial xUnit test
be3d610
Refactor and vscode added to gitignore
617efa2
-
60d87c2
Delete launch.json
Justin-Lloyd ea776e8
Delete tasks.json
Justin-Lloyd 735e343
Email pattern test
Justin-Lloyd 260cc1a
updated email address
Justin-Lloyd 3fae098
Merge pull request #1 from Marusyk/master
Justin-Lloyd 60e70d2
Email and IPV4 patterrn tests
67cbe1d
IPV4 patterrn test
089de06
Merge branch 'master' of https://github.com/Justin-Lloyd/grok.net
36e6015
Refactored test data
0b45b25
constants declared
5bb8250
Changes as requested
ca97c3b
-
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using Xunit; | ||
| using GrokNet; | ||
|
|
||
|
|
@@ -27,10 +28,11 @@ public void PatternCountTest() | |
| 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: --------"; | ||
| int elements = 16; | ||
|
|
||
| GrokResult grokResult = act.Parse(logs); | ||
|
|
||
| Assert.Equal(16, grokResult.Count); | ||
| Assert.Equal(elements, grokResult.Count); | ||
| } | ||
|
|
||
| [Fact] | ||
|
|
@@ -39,21 +41,24 @@ 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: --------"; | ||
| string month="06"; | ||
| string day = "21"; | ||
| string year = "19"; | ||
|
|
||
| GrokResult grokResult = act.Parse(logs); | ||
|
|
||
| Assert.Equal("month", grokResult[0].Key); | ||
| Assert.Equal("06", grokResult[0].Value); | ||
| Assert.Equal(month, grokResult[0].Value); | ||
| Assert.Equal("day", grokResult[1].Key); | ||
| Assert.Equal("21", grokResult[1].Value); | ||
| Assert.Equal(day, grokResult[1].Value); | ||
| Assert.Equal("year", grokResult[2].Key); | ||
| Assert.Equal("19", grokResult[2].Value); | ||
| Assert.Equal(year, grokResult[2].Value); | ||
| Assert.Equal("month", grokResult[8].Key); | ||
| Assert.Equal("06", grokResult[8].Value); | ||
| Assert.Equal(month, grokResult[8].Value); | ||
| Assert.Equal("day", grokResult[9].Key); | ||
| Assert.Equal("21", grokResult[9].Value); | ||
| Assert.Equal(day, grokResult[9].Value); | ||
| Assert.Equal("year", grokResult[10].Key); | ||
| Assert.Equal("19", grokResult[10].Value); | ||
| Assert.Equal(year, grokResult[10].Value); | ||
| } | ||
|
|
||
| [Fact] | ||
|
|
@@ -73,29 +78,47 @@ public void TimePatternTest() | |
| public void EmailPatternTest() | ||
| { | ||
| Grok act = new Grok("%{EMAILADDRESS:email}:%{GREEDYDATA:comment}"); | ||
| string logs = @"[email protected]:Free as in Free Beer"; | ||
| string emailAddress ="[email protected]"; | ||
| string comment = "Free as in Free Beer"; | ||
| string logs = emailAddress + ":" + comment; | ||
|
|
||
| GrokResult grokResult = act.Parse(logs); | ||
|
|
||
| Assert.Equal("[email protected]", grokResult[0].Value); | ||
| Assert.Equal("Free as in Free Beer", grokResult[1].Value); | ||
| Assert.Equal(emailAddress, grokResult[0].Value); | ||
| Assert.Equal(comment, grokResult[1].Value); | ||
| Assert.Equal("email", grokResult[0].Key); | ||
| Assert.Equal("comment", grokResult[1].Key); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void IPv4PatternTest() | ||
| [Theory] | ||
| [MemberData(nameof(GetIpv4PatternTestData))] | ||
| public void IPv4PatternTest(string grokPattern, string logs, string ipAddress, string comment, int grokElementOffset) | ||
| { | ||
| Grok act = new Grok("%{IPV4:IP}:%{GREEDYDATA:comment}"); | ||
| string logs = @"172.26.34.32:Free as in Free Beer | ||
| 10.0.12.17:In for the win"; | ||
| Grok act = new Grok(grokPattern); | ||
|
|
||
| GrokResult grokResult = act.Parse(logs); | ||
|
|
||
| Assert.Equal("172.26.34.32", grokResult[0].Value); | ||
| Assert.Equal("Free as in Free Beer", grokResult[1].Value); | ||
| Assert.Equal("10.0.12.17", grokResult[2].Value); | ||
| Assert.Equal("In for the win", grokResult[3].Value); | ||
| Assert.Equal(ipAddress, grokResult[grokElementOffset].Value); | ||
| Assert.Equal(comment, grokResult[grokElementOffset+1].Value); | ||
| } | ||
| public static IEnumerable<object[]> GetIpv4PatternTestData() | ||
Marusyk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| string grokPattern="%{IPV4:IP}:%{GREEDYDATA:comment}"; | ||
Marusyk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| string ip1 ="172.26.34.32"; | ||
| string comment1 = "Free as in Free Beer"; | ||
| string ip2="10.0.12.17"; | ||
| string comment2="In for the win"; | ||
| string logs = ip1 + ":" + comment1 +"\n"+ ip2 + ":" + comment2; | ||
| int elementOffset = 0; | ||
|
|
||
| var data = new List<object[]> | ||
| { | ||
| new object[]{grokPattern, logs, ip1, comment1, elementOffset}, | ||
Marusyk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| new object[]{grokPattern, logs, ip2, comment2, elementOffset+2}, | ||
| }; | ||
|
|
||
| return data; | ||
| } | ||
|
|
||
Marusyk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.