Skip to content

Commit

Permalink
Create unit tests for TCP collector.
Browse files Browse the repository at this point in the history
  • Loading branch information
EEParker committed Apr 5, 2024
1 parent aaa9e96 commit e5234a9
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 1 deletion.
9 changes: 8 additions & 1 deletion serilog-sinks-splunk.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{B9B133
.editorconfig = .editorconfig
Build.ps1 = Build.ps1
CHANGES.md = CHANGES.md
global.json = global.json
README.md = README.md
assets\Serilog.snk = assets\Serilog.snk
global.json = global.json
Setup.ps1 = Setup.ps1
EndProjectSection
EndProject
Expand Down Expand Up @@ -42,6 +42,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{A9F9
.github\workflows\ci.yml = .github\workflows\ci.yml
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Sinks.Splunk.TCP.Tests", "test\Serilog.Sinks.Splunk.TCP.Tests\Serilog.Sinks.Splunk.TCP.Tests.csproj", "{9F0EA87D-1D36-47C0-887E-29A1F7DB6979}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -72,6 +74,10 @@ Global
{1B9DEFA3-D600-45FA-93A5-79006076FB5C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1B9DEFA3-D600-45FA-93A5-79006076FB5C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1B9DEFA3-D600-45FA-93A5-79006076FB5C}.Release|Any CPU.Build.0 = Release|Any CPU
{9F0EA87D-1D36-47C0-887E-29A1F7DB6979}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9F0EA87D-1D36-47C0-887E-29A1F7DB6979}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9F0EA87D-1D36-47C0-887E-29A1F7DB6979}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9F0EA87D-1D36-47C0-887E-29A1F7DB6979}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -83,6 +89,7 @@ Global
{F74FCFD0-536B-4311-AA66-0BD16112D895} = {7A774CBB-A6E9-4854-B4DB-4CF860B0C1C5}
{FE1504A6-5444-4B87-819C-E6F477662B7F} = {7A774CBB-A6E9-4854-B4DB-4CF860B0C1C5}
{21EEF50A-C0FC-4406-97A1-8F5F499AE2FC} = {1C75E4A9-4CB1-497C-AD17-B438882051A1}
{9F0EA87D-1D36-47C0-887E-29A1F7DB6979} = {B9451AD8-09B9-4C09-A152-FBAE24806614}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D7BFF439-D18D-4124-A36F-15CFB8E84BCC}
Expand Down
11 changes: 11 additions & 0 deletions test/Serilog.Sinks.Splunk.TCP.Tests/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"profiles": {
"test": {
"commandName": "test"
},
"test-dnxcore50": {
"commandName": "test",
"sdkVersion": "dnx-coreclr-win-x86.1.0.0-rc1-final"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net462</TargetFramework>
<AssemblyName>Serilog.Sinks.Splunk.Tests</AssemblyName>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<IsPackable>false</IsPackable>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.msbuild" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Serilog.Sinks.TCP\Serilog.Sinks.Splunk.TCP.csproj" />
</ItemGroup>
</Project>
55 changes: 55 additions & 0 deletions test/Serilog.Sinks.Splunk.TCP.Tests/TCPCollectorTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Serilog.Events;
using Xunit;

namespace Serilog.Sinks.Splunk.TCP.Tests;

public class TCPCollectorTests
{
[Fact]
public void LoggerExtensionTest()
{
using (var TestEnvironment = new TestEnvironment())
{
var log = new LoggerConfiguration()
.WriteTo.SplunkViaTcp(
new Serilog.Sinks.Splunk.SplunkTcpSinkConnectionInfo("127.0.0.1", 10001),
restrictedToMinimumLevel: LevelAlias.Minimum,
formatProvider: null,
renderTemplate: true)
.CreateLogger();

log.Information("Hello World");
}
}

}

class TestEnvironment : IDisposable
{
TcpListener TcpServer;

readonly public int TcpServerAddress;

public TestEnvironment(int TcpServerAddress = 10001)
{
this.TcpServerAddress = TcpServerAddress;

TcpServer = new TcpListener(IPAddress.Loopback, TcpServerAddress);

TcpServer.Start();
}

public void Dispose()
{
TcpServer.Stop();
}
}

0 comments on commit e5234a9

Please sign in to comment.