Skip to content

Commit 67e6ea7

Browse files
author
Riddhi Nilawar
committed
Added tests
1 parent fcfb55c commit 67e6ea7

File tree

2 files changed

+188
-0
lines changed

2 files changed

+188
-0
lines changed

src/Network/Network.Test/ScenarioTests/NetworkWatcherAPITests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,5 +225,21 @@ public void TestVnetFlowLogWithEmptyFilteringCondition()
225225
{
226226
TestRunner.RunTestScript("Test-VnetFlowLogWithEmptyFilteringCondition");
227227
}
228+
229+
[Fact]
230+
[Trait(Category.AcceptanceType, Category.LiveOnly)]
231+
[Trait(Category.Owner, NrpTeamAlias.netanalyticsdev)]
232+
public void TestVnetFlowLogWithRecordType()
233+
{
234+
TestRunner.RunTestScript("Test-VnetFlowLogWithRecordType");
235+
}
236+
237+
[Fact]
238+
[Trait(Category.AcceptanceType, Category.LiveOnly)]
239+
[Trait(Category.Owner, NrpTeamAlias.netanalyticsdev)]
240+
public void TestVnetFlowLogWithEmptyRecordTypeCondition()
241+
{
242+
TestRunner.RunTestScript("Test-VnetFlowLogWithEmptyRecordTypeCondition");
243+
}
228244
}
229245
}

src/Network/Network.Test/ScenarioTests/NetworkWatcherAPITests.ps1

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,6 +1725,178 @@ function Test-VnetFlowLogWithEmptyFilteringCondition {
17251725
}
17261726
}
17271727

1728+
<#
1729+
.SYNOPSIS
1730+
Test Flow log CRUD API.
1731+
#>
1732+
function Test-VnetFlowLogWithRecordType
1733+
{
1734+
# Setup
1735+
$resourceGroupName = Get-NrpResourceGroupName
1736+
$nwName = Get-NrpResourceName
1737+
$nwRgName = Get-NrpResourceGroupName
1738+
$flowLogName = Get-NrpResourceName
1739+
$domainNameLabel = Get-NrpResourceName
1740+
$vnetName = Get-NrpResourceName
1741+
$stoname = Get-NrpResourceName
1742+
$location = Get-ProviderLocation "Microsoft.Network/networkWatchers" "eastus2euap"
1743+
1744+
try
1745+
{
1746+
# Create Resource group
1747+
New-AzResourceGroup -Name $resourceGroupName -Location "$location"
1748+
1749+
# Create the Virtual Network
1750+
$subnet = New-AzVirtualNetworkSubnetConfig -Name "FlowLogSubnet" -AddressPrefix 10.0.0.0/24
1751+
$vnet = New-AzVirtualNetwork -Name $vnetName -ResourceGroupName $resourceGroupName -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet
1752+
Start-Sleep -Seconds 10
1753+
$vnet = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $resourceGroupName
1754+
1755+
# Create Resource group for Network Watcher
1756+
New-AzResourceGroup -Name $nwRgName -Location "$location"
1757+
Start-Sleep -Seconds 5
1758+
1759+
# Get Network Watcher
1760+
$nw = Get-CreateTestNetworkWatcher -location $location -nwName $nwName -nwRgName $nwRgName
1761+
Start-Sleep -Seconds 5
1762+
1763+
# Create storage
1764+
$stoname = 'sto' + $stoname
1765+
$stotype = 'Standard_GRS'
1766+
1767+
New-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $stoname -Location $location -Type $stotype;
1768+
$sto = Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $stoname;
1769+
Start-Sleep -Seconds 10
1770+
1771+
# Create flow log
1772+
$job = New-AzNetworkWatcherFlowLog -NetworkWatcher $nw -Name $flowLogName -TargetResourceId $vnet.Id -StorageId $sto.Id -Enabled $true -RecordType "B,E"
1773+
$job | Wait-Job
1774+
$config = $job | Receive-Job
1775+
Start-Sleep -Seconds 5
1776+
1777+
# Validation set operation
1778+
Assert-AreEqual $config.TargetResourceId $vnet.Id
1779+
Assert-AreEqual $config.StorageId $sto.Id
1780+
Assert-AreEqual $config.Enabled $true
1781+
Assert-AreEqual $config.Format.Type "JSON"
1782+
Assert-AreEqual $config.Format.Version 1
1783+
1784+
# Get flow log
1785+
$flowLog = Get-AzNetworkWatcherFlowLog -NetworkWatcher $nw -Name $flowLogName
1786+
1787+
# Validation get operation
1788+
Assert-AreEqual $flowLog.TargetResourceId $vnet.Id
1789+
Assert-AreEqual $flowLog.StorageId $sto.Id
1790+
Assert-AreEqual $flowLog.RecordType "B,E"
1791+
Assert-AreEqual $flowLog.Enabled $true
1792+
Assert-AreEqual $flowLog.Format.Type "JSON"
1793+
Assert-AreEqual $flowLog.Format.Version 1
1794+
1795+
# Set flow log
1796+
$flowLog.Enabled = $false
1797+
$flowLog | Set-AzNetworkWatcherFlowLog -Force
1798+
1799+
# Get updated flowLog
1800+
$updatedFlowLog = Get-AzNetworkWatcherFlowLog -NetworkWatcher $nw -Name $flowLogName
1801+
Assert-AreEqual $updatedFlowLog.Enabled $false
1802+
1803+
# Delete flow log
1804+
Remove-AzNetworkWatcherFlowLog -NetworkWatcher $nw -Name $flowLogName
1805+
}
1806+
finally
1807+
{
1808+
# Cleanup
1809+
Clean-ResourceGroup $resourceGroupName
1810+
Clean-ResourceGroup $nwRgName
1811+
}
1812+
}
1813+
1814+
<#
1815+
.SYNOPSIS
1816+
Test Flow log CRUD API.
1817+
#>
1818+
function Test-VnetFlowLogWithEmptyRecordType
1819+
{
1820+
# Setup
1821+
$resourceGroupName = Get-NrpResourceGroupName
1822+
$nwName = Get-NrpResourceName
1823+
$nwRgName = Get-NrpResourceGroupName
1824+
$flowLogName = Get-NrpResourceName
1825+
$domainNameLabel = Get-NrpResourceName
1826+
$vnetName = Get-NrpResourceName
1827+
$stoname = Get-NrpResourceName
1828+
$location = Get-ProviderLocation "Microsoft.Network/networkWatchers" "eastus2euap"
1829+
1830+
try
1831+
{
1832+
# Create Resource group
1833+
New-AzResourceGroup -Name $resourceGroupName -Location "$location"
1834+
1835+
# Create the Virtual Network
1836+
$subnet = New-AzVirtualNetworkSubnetConfig -Name "FlowLogSubnet" -AddressPrefix 10.0.0.0/24
1837+
$vnet = New-AzVirtualNetwork -Name $vnetName -ResourceGroupName $resourceGroupName -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet
1838+
Start-Sleep -Seconds 10
1839+
$vnet = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $resourceGroupName
1840+
1841+
# Create Resource group for Network Watcher
1842+
New-AzResourceGroup -Name $nwRgName -Location "$location"
1843+
Start-Sleep -Seconds 5
1844+
1845+
# Get Network Watcher
1846+
$nw = Get-CreateTestNetworkWatcher -location $location -nwName $nwName -nwRgName $nwRgName
1847+
Start-Sleep -Seconds 5
1848+
1849+
# Create storage
1850+
$stoname = 'sto' + $stoname
1851+
$stotype = 'Standard_GRS'
1852+
1853+
New-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $stoname -Location $location -Type $stotype;
1854+
$sto = Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $stoname;
1855+
Start-Sleep -Seconds 10
1856+
1857+
# Create flow log
1858+
$job = New-AzNetworkWatcherFlowLog -NetworkWatcher $nw -Name $flowLogName -TargetResourceId $vnet.Id -StorageId $sto.Id -Enabled $true -RecordType ""
1859+
$job | Wait-Job
1860+
$config = $job | Receive-Job
1861+
Start-Sleep -Seconds 5
1862+
1863+
# Validation set operation
1864+
Assert-AreEqual $config.TargetResourceId $vnet.Id
1865+
Assert-AreEqual $config.StorageId $sto.Id
1866+
Assert-AreEqual $config.Enabled $true
1867+
Assert-AreEqual $config.Format.Type "JSON"
1868+
Assert-AreEqual $config.Format.Version 1
1869+
1870+
# Get flow log
1871+
$flowLog = Get-AzNetworkWatcherFlowLog -NetworkWatcher $nw -Name $flowLogName
1872+
1873+
# Validation get operation
1874+
Assert-AreEqual $flowLog.TargetResourceId $vnet.Id
1875+
Assert-AreEqual $flowLog.StorageId $sto.Id
1876+
Assert-AreEqual $flowLog.RecordType ""
1877+
Assert-AreEqual $flowLog.Enabled $true
1878+
Assert-AreEqual $flowLog.Format.Type "JSON"
1879+
Assert-AreEqual $flowLog.Format.Version 1
1880+
1881+
# Set flow log
1882+
$flowLog.Enabled = $false
1883+
$flowLog | Set-AzNetworkWatcherFlowLog -Force
1884+
1885+
# Get updated flowLog
1886+
$updatedFlowLog = Get-AzNetworkWatcherFlowLog -NetworkWatcher $nw -Name $flowLogName
1887+
Assert-AreEqual $updatedFlowLog.Enabled $false
1888+
1889+
# Delete flow log
1890+
Remove-AzNetworkWatcherFlowLog -NetworkWatcher $nw -Name $flowLogName
1891+
}
1892+
finally
1893+
{
1894+
# Cleanup
1895+
Clean-ResourceGroup $resourceGroupName
1896+
Clean-ResourceGroup $nwRgName
1897+
}
1898+
}
1899+
17281900
<#
17291901
.SYNOPSIS
17301902
Test ConnectivityCheck NetworkWatcher API.

0 commit comments

Comments
 (0)