-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-Implemented BackupConfigDatabase, ClearSystemCache, LoadConfigFiles,…
… RestartProbe and RestartCore methods -Implemented Backup-PrtgConfig, Clear-PrtgCache, Load-PrtgConfigFile, Restart-Probe and Restart-PrtgCore cmdlets For #5
- Loading branch information
Showing
32 changed files
with
1,397 additions
and
10 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
PrtgAPI.Tests.IntegrationTests/ActionTests/AdminToolTests.cs
This file contains 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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace PrtgAPI.Tests.IntegrationTests.ActionTests | ||
{ | ||
[TestClass] | ||
public class AdminToolTests : BasePrtgClientTest | ||
{ | ||
private static string PrtgBackups => $"\\\\{Settings.Server}\\c$\\ProgramData\\Paessler\\PRTG Network Monitor\\Configuration Auto-Backups"; | ||
|
||
[TestMethod] | ||
public void Action_BackupConfig_SuccessfullyBacksUpConfig() | ||
{ | ||
var originalFiles = GetBackupFiles(); | ||
|
||
client.BackupConfigDatabase(); | ||
|
||
ValidateBackupCreated(originalFiles); | ||
} | ||
|
||
[TestMethod] | ||
public async Task Action_BackupConfig_SuccessfullyBacksUpConfigAsync() | ||
{ | ||
var originalFiles = GetBackupFiles(); | ||
|
||
await client.BackupConfigDatabaseAsync(); | ||
|
||
ValidateBackupCreated(originalFiles); | ||
} | ||
|
||
public static List<FileInfo> GetBackupFiles() => Impersonator.ExecuteAction(new DirectoryInfo(PrtgBackups).GetFiles).ToList(); | ||
|
||
public static void RemoveBackupFile(string fileName) => Impersonator.ExecuteAction(() => File.Delete(fileName)); | ||
|
||
private void ValidateBackupCreated(List<FileInfo> originalFiles) | ||
{ | ||
Logger.LogTest("Pausing for 10 seconds while backup is created"); | ||
Thread.Sleep(10000); | ||
|
||
var newFiles = GetBackupFiles(); | ||
|
||
Assert2.AreEqual(originalFiles.Count + 1, newFiles.Count, "New backup file was not created"); | ||
|
||
var diff = newFiles.Select(f => f.FullName).Except(originalFiles.Select(fn => fn.FullName)).ToList(); | ||
|
||
Assert2.AreEqual(1, diff.Count, "Backup file was not successfully created"); | ||
|
||
var firstFile = diff.First(); | ||
|
||
RemoveBackupFile(firstFile); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
PrtgAPI.Tests.IntegrationTests/PowerShell/Backup-PrtgConfig.Tests.ps1
This file contains 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
. $PSScriptRoot\Support\IntegrationTestSafe.ps1 | ||
|
||
Describe "Backup-PrtgConfig_IT" { | ||
It "can execute" { | ||
$originalFiles = [PrtgAPI.Tests.IntegrationTests.ActionTests.AdminToolTests]::GetBackupFiles() | select -ExpandProperty FullName | ||
|
||
$originalFiles.Count | Should BeGreaterThan 0 | ||
|
||
Backup-PrtgConfig | ||
|
||
LogTest "Pausing for 10 seconds while backup is created" | ||
Sleep 10 | ||
|
||
$newFiles = [PrtgAPI.Tests.IntegrationTests.ActionTests.AdminToolTests]::GetBackupFiles() | select -ExpandProperty FullName | ||
|
||
$newFiles.Count | Should Be ($originalFiles.Count + 1) | ||
|
||
$diff = @($newFiles | where { $originalFiles -notcontains $_ }) | ||
|
||
$diff.Count | Should Be 1 | ||
|
||
$firstFile = $diff | select -First 1 | ||
|
||
[PrtgAPI.Tests.IntegrationTests.ActionTests.AdminToolTests]::RemoveBackupFile($firstFile) | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
PrtgAPI.Tests.IntegrationTests/PowerShell/Clear-PrtgCache.Tests.ps1
This file contains 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
. $PSScriptRoot\Support\IntegrationTest.ps1 | ||
|
||
Describe "Clear-PrtgCache_IT" { | ||
It "clears general caches" { | ||
Clear-PrtgCache General | ||
} | ||
|
||
It "clears graph data" { | ||
Clear-PrtgCache GraphData -Force | ||
|
||
# Wait on the service restarting | ||
Restart-PrtgCore -Force -Wait | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
PrtgAPI.Tests.IntegrationTests/PowerShell/Load-PrtgConfigFile.Tests.ps1
This file contains 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
. $PSScriptRoot\Support\IntegrationTest.ps1 | ||
|
||
Describe "Load-PrtgConfigFile_IT" { | ||
It "loads general files" { | ||
Load-PrtgConfigFile General | ||
} | ||
|
||
It "loads sensor lookups" { | ||
Load-PrtgConfigFile Lookups | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
PrtgAPI.Tests.IntegrationTests/PowerShell/Restart-Probe.Tests.ps1
This file contains 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
. $PSScriptRoot\Support\IntegrationTest.ps1 | ||
|
||
Describe "Restart-Probe_IT" { | ||
It "waits for all probes to restart" { | ||
Restart-Probe | ||
|
||
$probes = Get-Probe | ||
|
||
foreach($probe in $probes) | ||
{ | ||
$probe.Condition | Should Be Connected | ||
} | ||
} | ||
|
||
It "waits for a probe to restart" { | ||
$probe = Get-Probe -Id (Settings Probe) | ||
|
||
$probe | Restart-Probe | ||
|
||
$newProbe = Get-Probe -Id (Settings Probe) | ||
|
||
$probe.Condition | Should Be Connected | ||
} | ||
|
||
It "times out restarting a probe" { | ||
{ Restart-Probe -Timeout 1 } | Should Throw "Timed out waiting for 1 probe to restart" | ||
|
||
# Wait for the server to come back online | ||
Restart-Probe -Wait | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
PrtgAPI.Tests.IntegrationTests/PowerShell/Restart-PrtgCore.Tests.ps1
This file contains 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
. $PSScriptRoot\Support\IntegrationTest.ps1 | ||
|
||
Describe "Restart-PrtgCore_IT" { | ||
|
||
It "waits for PRTG to restart" { | ||
Restart-PrtgCore | ||
|
||
$sensor = Get-Sensor -Id (Settings UpSensor) | ||
|
||
$sensor.Id | Should Be (Settings UpSensor) | ||
} | ||
|
||
It "times out restarting PRTG" { | ||
{ Restart-PrtgCore -Timeout 1 } | Should Throw "Timed out waiting for PRTG Core Service to restart" | ||
|
||
# Wait for the server to come back online | ||
Restart-PrtgCore -Wait | ||
} | ||
} |
This file contains 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
This file contains 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
80 changes: 80 additions & 0 deletions
80
PrtgAPI.Tests.UnitTests/ObjectTests/CSharp/AdminToolTests.cs
This file contains 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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using PrtgAPI.Tests.UnitTests.ObjectTests.TestResponses; | ||
|
||
namespace PrtgAPI.Tests.UnitTests.ObjectTests.CSharp | ||
{ | ||
[TestClass] | ||
public class AdminToolTests : BaseTest | ||
{ | ||
PrtgClient client = Initialize_Client(new BasicResponse(string.Empty)); | ||
|
||
[TestMethod] | ||
public void AdminTool_BackupConfig_CanExecute() | ||
{ | ||
client.BackupConfigDatabase(); | ||
} | ||
|
||
[TestMethod] | ||
public async Task AdminTool_BackupConfig_CanExecuteAsync() | ||
{ | ||
await client.BackupConfigDatabaseAsync(); | ||
} | ||
|
||
[TestMethod] | ||
public void AdminTool_ClearCache_CanExecute() | ||
{ | ||
client.ClearSystemCache(SystemCacheType.General); | ||
client.ClearSystemCache(SystemCacheType.GraphData); | ||
} | ||
|
||
[TestMethod] | ||
public async Task AdminTool_ClearCache_CanExecuteAsync() | ||
{ | ||
await client.ClearSystemCacheAsync(SystemCacheType.General); | ||
await client.ClearSystemCacheAsync(SystemCacheType.GraphData); | ||
} | ||
|
||
[TestMethod] | ||
public void AdminTool_LoadConfigFiles_CanExecute() | ||
{ | ||
client.LoadConfigFiles(ConfigFileType.General); | ||
client.LoadConfigFiles(ConfigFileType.Lookups); | ||
} | ||
|
||
[TestMethod] | ||
public async Task AdminTool_LoadConfigFiles_CanExecuteAsync() | ||
{ | ||
await client.LoadConfigFilesAsync(ConfigFileType.General); | ||
await client.LoadConfigFilesAsync(ConfigFileType.Lookups); | ||
} | ||
|
||
[TestMethod] | ||
public void AdminTool_RestartCore_CanExecute() | ||
{ | ||
client.RestartCore(); | ||
} | ||
|
||
[TestMethod] | ||
public async Task AdminTool_RestartCore_CanExecuteAsync() | ||
{ | ||
await client.RestartCoreAsync(); | ||
} | ||
|
||
[TestMethod] | ||
public void AdminTool_RestartProbe_CanExecute() | ||
{ | ||
client.RestartProbe(1001); | ||
} | ||
|
||
[TestMethod] | ||
public async Task AdminTool_RestartProbe_CanExecuteAsync() | ||
{ | ||
await client.RestartProbeAsync(1001); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
PrtgAPI.Tests.UnitTests/ObjectTests/PowerShell/Backup-PrtgConfig.Tests.ps1
This file contains 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
. $PSScriptRoot\Support\Standalone.ps1 | ||
|
||
Describe "Backup-PrtgConfig" -Tag @("PowerShell", "UnitTest") { | ||
It "can execute" { | ||
SetAddressValidatorResponse "api/savenow.htm?" $true | ||
|
||
Backup-PrtgConfig | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
PrtgAPI.Tests.UnitTests/ObjectTests/PowerShell/Clear-PrtgCache.Tests.ps1
This file contains 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
. $PSScriptRoot\Support\Standalone.ps1 | ||
|
||
Describe "Clear-PrtgCache" -Tag @("PowerShell", "UnitTest") { | ||
It "clears general caches" { | ||
SetAddressValidatorResponse "api/clearcache.htm?" $true | ||
|
||
Clear-PrtgCache General | ||
} | ||
|
||
It "clears the graph cache" { | ||
SetAddressValidatorResponse "api/recalccache.htm?" $true | ||
|
||
Clear-PrtgCache GraphData -Force | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
PrtgAPI.Tests.UnitTests/ObjectTests/PowerShell/Load-PrtgConfigFile.Tests.ps1
This file contains 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
. $PSScriptRoot\Support\Standalone.ps1 | ||
|
||
Describe "Load-PrtgConfigFile" -Tag @("PowerShell", "UnitTest") { | ||
It "loads general files" { | ||
SetAddressValidatorResponse "api/reloadfilelists.htm?" $true | ||
|
||
Load-PrtgConfigFile General | ||
} | ||
|
||
It "loads sensor lookups" { | ||
SetAddressValidatorResponse "api/loadlookups.htm?" $true | ||
|
||
Load-PrtgConfigFile Lookups | ||
} | ||
} |
5 changes: 0 additions & 5 deletions
5
PrtgAPI.Tests.UnitTests/ObjectTests/PowerShell/New-SearchFilter.Tests.ps1
This file contains 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
Oops, something went wrong.