Skip to content

Commit ed89c7e

Browse files
Justin-LloydMarusyk
authored andcommitted
IPv4 Pattern test (#8)
IPV4 patterrn test
1 parent 9383ff3 commit ed89c7e

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

src/Grok.Net.Tests/UnitTests.cs

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using Xunit;
34
using GrokNet;
45

@@ -27,10 +28,11 @@ public void PatternCountTest()
2728
Grok act = new Grok(grokPattern);
2829
string logs = @"06-21-19 21:00:13:589241;15;INFO;main;DECODED: 775233900043 DECODED BY: 18500738 DISTANCE: 1.5165
2930
06-21-19 21:00:13:589265;156;WARN;main;DECODED: 775233900043 EMPTY DISTANCE: --------";
31+
const int elements = 16;
3032

3133
GrokResult grokResult = act.Parse(logs);
3234

33-
Assert.Equal(16, grokResult.Count);
35+
Assert.Equal(elements, grokResult.Count);
3436
}
3537

3638
[Fact]
@@ -39,21 +41,24 @@ public void MonthDayPatternTest()
3941
Grok act = new Grok("%{MONTHDAY:month}-%{MONTHDAY:day}-%{MONTHDAY:year} %{TIME:timestamp};%{WORD:id};%{LOGLEVEL:loglevel};%{WORD:func};%{GREEDYDATA:msg}");
4042
string logs = @"06-21-19 21:00:13:589241;15;INFO;main;DECODED: 775233900043 DECODED BY: 18500738 DISTANCE: 1.5165
4143
06-21-19 21:00:13:589265;156;WARN;main;DECODED: 775233900043 EMPTY DISTANCE: --------";
44+
const string month = "06";
45+
const string day = "21";
46+
const string year = "19";
4247

4348
GrokResult grokResult = act.Parse(logs);
4449

4550
Assert.Equal("month", grokResult[0].Key);
46-
Assert.Equal("06", grokResult[0].Value);
51+
Assert.Equal(month, grokResult[0].Value);
4752
Assert.Equal("day", grokResult[1].Key);
48-
Assert.Equal("21", grokResult[1].Value);
53+
Assert.Equal(day, grokResult[1].Value);
4954
Assert.Equal("year", grokResult[2].Key);
50-
Assert.Equal("19", grokResult[2].Value);
55+
Assert.Equal(year, grokResult[2].Value);
5156
Assert.Equal("month", grokResult[8].Key);
52-
Assert.Equal("06", grokResult[8].Value);
57+
Assert.Equal(month, grokResult[8].Value);
5358
Assert.Equal("day", grokResult[9].Key);
54-
Assert.Equal("21", grokResult[9].Value);
59+
Assert.Equal(day, grokResult[9].Value);
5560
Assert.Equal("year", grokResult[10].Key);
56-
Assert.Equal("19", grokResult[10].Value);
61+
Assert.Equal(year, grokResult[10].Value);
5762
}
5863

5964
[Fact]
@@ -73,15 +78,31 @@ public void TimePatternTest()
7378
public void EmailPatternTest()
7479
{
7580
Grok act = new Grok("%{EMAILADDRESS:email}:%{GREEDYDATA:comment}");
76-
string logs = @"[email protected]:Free as in Free Beer";
81+
const string emailAddress ="[email protected]";
82+
const string comment = "Free as in Free Beer";
83+
string logs = emailAddress + ":" + comment;
7784

7885
GrokResult grokResult = act.Parse(logs);
7986

80-
Assert.Equal("[email protected]", grokResult[0].Value);
81-
Assert.Equal("Free as in Free Beer", grokResult[1].Value);
87+
Assert.Equal(emailAddress, grokResult[0].Value);
88+
Assert.Equal(comment, grokResult[1].Value);
8289
Assert.Equal("email", grokResult[0].Key);
8390
Assert.Equal("comment", grokResult[1].Key);
84-
8591
}
92+
93+
[Fact]
94+
public void IPv4PatternTest()
95+
{
96+
const string ipAddress = "172.26.34.32";
97+
const string comment = "Free as in Free Beer";
98+
string logs = $"{ipAddress}:{comment}";
99+
string grokPattern = "%{IPV4:IP}:%{GREEDYDATA:comment}";
100+
Grok act = new Grok(grokPattern);
101+
102+
GrokResult grokResult = act.Parse(logs);
103+
104+
Assert.Equal(ipAddress, grokResult[0].Value);
105+
Assert.Equal(comment, grokResult[1].Value);
106+
}
86107
}
87108
}

0 commit comments

Comments
 (0)