Skip to content

Commit

Permalink
Improved SNMP Test
Browse files Browse the repository at this point in the history
  • Loading branch information
DAQEM committed Nov 6, 2023
1 parent e7015d9 commit d88df09
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 54 deletions.
45 changes: 2 additions & 43 deletions .github/workflows/test_snmp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,46 +21,5 @@ jobs:
services: |
netmon-snmp-polling-service-snmpd-test
- name: ping test 1
run: |
echo "Sending ping..."
docker exec netmon-snmp-polling-service-snmpd-test ping 192.168.178.6 -c 3
- name: ping test 2
run: |
echo "Sending ping..."
docker exec netmon-snmp-polling-service apt-get install iputils-ping -y
docker exec netmon-snmp-polling-service ping 192.168.178.7 -c 3
- name: 'Setup jq'
uses: dcarbone/install-jq-action@v2.0.1

- name: 'Check jq'
# language=sh
run: |
which jq
jq --version
- name: Test API
run: |
echo "Sending HTTP POST request..."
json_output=$(docker exec netmon-snmp-polling-service-snmpd-test curl -s -X 'POST' 'http://192.168.178.6/Discover/Details' -H 'accept: */*' -H 'Content-Type: application/json' -d '{"version":"V2","ipAddress":"192.168.178.7","port":161,"community":"public"}')
expected_sysContact="Root <root@snmpd.test>"
expected_sysName="snmpd-test"
expected_sysLocation="SNMPD Test"
sysContact=$(echo "$json_output" | jq -r '.contact')
sysName=$(echo "$json_output" | jq -r '.name')
sysLocation=$(echo "$json_output" | jq -r '.location')
if [ "$sysContact" == "$expected_sysContact" ] && [ "$sysName" == "$expected_sysName" ] && [ "$sysLocation" == "$expected_sysLocation" ]; then
echo "All values are as expected!"
else
echo "json_output: $json_output"
echo "sysContact: $sysContact (Expected: $expected_sysContact)"
echo "sysName: $sysName (Expected: $expected_sysName)"
echo "sysLocation: $sysLocation (Expected: $expected_sysLocation)"
echo "Test failed!"
exit 1
fi
- name: Test SNMP Details
run: dotnet test Tests/Netmon.SNMPPolling.IntegrationTests
8 changes: 7 additions & 1 deletion Netmon.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Netmon.Data.EntityFramework
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Netmon.Data.EntityFramework.Write", "Shared\Netmon.Data.EntityFramework.Write\Netmon.Data.EntityFramework.Write.csproj", "{786BC353-1961-4CAB-9FFE-7E6199D6DC95}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Netmon.SNMPPolling.Tests", "Tests\Netmon.SNMPPolling.Tests\Netmon.SNMPPolling.Tests.csproj", "{F04F7CD1-8080-4341-9781-5C604BE144D1}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Netmon.SNMPPolling.UnitTests", "Tests\Netmon.SNMPPolling.UnitTests\Netmon.SNMPPolling.UnitTests.csproj", "{F04F7CD1-8080-4341-9781-5C604BE144D1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "APIGateway", "Services\APIGateway\APIGateway.csproj", "{39805855-A904-4126-A782-FDE701B62E85}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Netmon.SNMPPolling.IntegrationTests", "Tests\Netmon.SNMPPolling.IntegrationTests\Netmon.SNMPPolling.IntegrationTests.csproj", "{FA4A11D4-301E-4164-8E58-CE9250C879EF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -60,5 +62,9 @@ Global
{39805855-A904-4126-A782-FDE701B62E85}.Debug|Any CPU.Build.0 = Debug|Any CPU
{39805855-A904-4126-A782-FDE701B62E85}.Release|Any CPU.ActiveCfg = Release|Any CPU
{39805855-A904-4126-A782-FDE701B62E85}.Release|Any CPU.Build.0 = Release|Any CPU
{FA4A11D4-301E-4164-8E58-CE9250C879EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FA4A11D4-301E-4164-8E58-CE9250C879EF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FA4A11D4-301E-4164-8E58-CE9250C879EF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FA4A11D4-301E-4164-8E58-CE9250C879EF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions Netmon.sln.DotSettings.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=9b8a4c9e_002D5f16_002D474d_002D9068_002D5d039104f6f6/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="Get_EndpointsReturnSuccessAndCorrectContentType" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
&lt;TestAncestor&gt;&#xD;
&lt;TestId&gt;xUnit::FA4A11D4-301E-4164-8E58-CE9250C879EF::net7.0::Netmon.SNMPPolling.IntegrationTests.SNMPDiscoverIntegrationTests.Get_EndpointsReturnSuccessAndCorrectContentType&lt;/TestId&gt;&#xD;
&lt;/TestAncestor&gt;&#xD;
&lt;/SessionState&gt;</s:String></wpf:ResourceDictionary>
5 changes: 4 additions & 1 deletion Services/Netmon.SNMPPolling/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,7 @@
app.Run();


public partial class SNMPPollingProgram { }
namespace Netmon.SNMPPolling
{
public partial class SNMPPollingProgram { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.13" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2"/>
<PackageReference Include="xunit" Version="2.4.2"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Services\Netmon.SNMPPolling\Netmon.SNMPPolling.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Microsoft.AspNetCore.Mvc.Testing;
using Xunit;

namespace Netmon.SNMPPolling.Tests.Integration;
namespace Netmon.SNMPPolling.IntegrationTests;

public class SNMPDiscoverIntegrationTests : IClassFixture<WebApplicationFactory<SNMPPollingProgram>>
{
Expand All @@ -24,7 +24,7 @@ public async Task Get_EndpointsReturnSuccessAndCorrectContentType(string url)
HttpResponseMessage response = await client.PostAsJsonAsync(url, new
{
version = "V2",
ipAddress = "192.168.178.7",
ipAddress = "127.0.0.1",
port = 161,
community = "public"
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,20 @@
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>

<RootNamespace>Netmon.SNMPPolling.Tests</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.13" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="NUnit.Analyzers" Version="3.3.0" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
<PackageReference Include="xunit" Version="2.6.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Services\Netmon.SNMPPolling\Netmon.SNMPPolling.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Unit" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Netmon.SNMPPolling.SNMP.Security;
using NUnit.Framework;

namespace Netmon.SNMPPolling.Tests;
namespace Netmon.SNMPPolling.Tests.Security;

[TestFixture]
public class PrivacyProviderTests
Expand Down

0 comments on commit d88df09

Please sign in to comment.