Skip to content
This repository was archived by the owner on May 30, 2019. It is now read-only.

Commit 73bfa05

Browse files
committed
Moving tests into a single module test and using InModuleScope
1 parent ba471f2 commit 73bfa05

File tree

3 files changed

+147
-154
lines changed

3 files changed

+147
-154
lines changed

Functions/ConvertTo-GraphiteMetric.Tests.ps1

Lines changed: 0 additions & 112 deletions
This file was deleted.

Functions/Internal.Tests.ps1

Lines changed: 0 additions & 42 deletions
This file was deleted.

Graphite-Powershell.Tests.ps1

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
Import-Module .\Graphite-Powershell.psd1
2+
3+
InModuleScope Graphite-PowerShell {
4+
Describe "ConvertTo-GraphiteMetric" {
5+
Context "Metric Transformation - Base Function" {
6+
$TestMetric = ConvertTo-GraphiteMetric -MetricToClean "\\myServer\network interface(realtek pcie gbe family controller)\bytes received/sec"
7+
8+
It "Should Return Something" {
9+
$TestMetric | Should Not BeNullOrEmpty
10+
}
11+
It "Should Provide myServer.networkinterface.realtekpciegbefamilycontroller.bytesreceived-sec as Output" {
12+
$TestMetric | Should MatchExactly "myServer.networkinterface.realtekpciegbefamilycontroller.bytesreceived-sec"
13+
}
14+
It "Should Not Contain Left Parentheses" {
15+
$TestMetric | Should Not Match "\("
16+
}
17+
It "Should Not Contain Right Parentheses" {
18+
$TestMetric | Should Not Match "\)"
19+
}
20+
It "Should Not Contain Forward Slash" {
21+
$TestMetric | Should Not Match "\/"
22+
}
23+
It "Should Not Contain Back Slash" {
24+
$TestMetric | Should Not Match "\\"
25+
}
26+
It "Should Contain a Period" {
27+
$TestMetric | Should Match "\."
28+
}
29+
}
30+
Context "Metric Transformation - Using MetricReplacementHash" {
31+
32+
$MockHashTable = [ordered]@{
33+
"^\\\\" = "";
34+
"\\\\" = "";
35+
"\/" = "-";
36+
":" = ".";
37+
"\\" = ".";
38+
"\(" = ".";
39+
"\)" = "";
40+
"\]" = "";
41+
"\[" = "";
42+
"\%" = "";
43+
"\s+" = "";
44+
"\.\." = ".";
45+
"_" = ""
46+
}
47+
48+
It "Should Return Something" {
49+
ConvertTo-GraphiteMetric -MetricToClean "\\myServer\network interface(realtek pcie gbe family controller)\bytes received/sec" -MetricReplacementHash $MockHashTable | Should Not BeNullOrEmpty
50+
}
51+
It "Should Provide myServer.networkinterface.realtekpciegbefamilycontroller.bytesreceived-sec as Output" {
52+
ConvertTo-GraphiteMetric -MetricToClean "\\myServer\network interface(realtek pcie gbe family controller)\bytes received/sec" -MetricReplacementHash $MockHashTable | Should MatchExactly "myServer.networkinterface.realtekpciegbefamilycontroller.bytesreceived-sec"
53+
}
54+
It "Should Not Contain Left Parentheses" {
55+
ConvertTo-GraphiteMetric -MetricToClean "\\myServer\network interface(realtek pcie gbe family controller)\bytes received/sec" -MetricReplacementHash $MockHashTable | Should Not Match "\("
56+
}
57+
It "Should Not Contain Right Parentheses" {
58+
ConvertTo-GraphiteMetric -MetricToClean "\\myServer\network interface(realtek pcie gbe family controller)\bytes received/sec" -MetricReplacementHash $MockHashTable | Should Not Match "\)"
59+
}
60+
It "Should Not Contain Forward Slash" {
61+
ConvertTo-GraphiteMetric -MetricToClean "\\myServer\network interface(realtek pcie gbe family controller)\bytes received/sec" -MetricReplacementHash $MockHashTable | Should Not Match "\/"
62+
}
63+
It "Should Not Contain Back Slash" {
64+
ConvertTo-GraphiteMetric -MetricToClean "\\myServer\network interface(realtek pcie gbe family controller)\bytes received/sec" -MetricReplacementHash $MockHashTable | Should Not Match "\\"
65+
}
66+
It "Should Contain a Period" {
67+
ConvertTo-GraphiteMetric -MetricToClean "\\myServer\network interface(realtek pcie gbe family controller)\bytes received/sec" -MetricReplacementHash $MockHashTable | Should Match "\."
68+
}
69+
}
70+
Context "Metric Transformation - Remove Underscores" {
71+
$TestMetric = ConvertTo-GraphiteMetric -MetricToClean "\\myServer\Processor(_Total)\% Processor Time" -RemoveUnderscores
72+
73+
It "Should Return Something" {
74+
$TestMetric | Should Not BeNullOrEmpty
75+
}
76+
It "Should Return myServer.production.net.Processor.Total.ProcessorTime as Output" {
77+
$TestMetric | Should MatchExactly "myServer.Processor.Total.ProcessorTime"
78+
}
79+
It "Should Not Contain Underscores" {
80+
$TestMetric | Should Not Match "_"
81+
}
82+
}
83+
Context "Metric Transformation - Provide Nice Output for Physical Disks" {
84+
$TestMetric = ConvertTo-GraphiteMetric -MetricToClean "\\myServer\physicaldisk(1 e:)\avg. disk write queue length" -RemoveUnderscores -NicePhysicalDisks
85+
86+
It "Should Return Something" {
87+
$TestMetric | Should Not BeNullOrEmpty
88+
}
89+
It "Should Return myServer.physicaldisk.e-drive.diskwritequeuelength as Output" {
90+
$TestMetric | Should MatchExactly "myServer.physicaldisk.e-drive.diskwritequeuelength"
91+
}
92+
}
93+
Context "Metric Transformation - Replace HostName" {
94+
$TestMetric = ConvertTo-GraphiteMetric -MetricToClean "\\$($env:COMPUTERNAME)\physicaldisk(1 e:)\avg. disk write queue length" -RemoveUnderscores -NicePhysicalDisks -HostName "my.new.hostname"
95+
96+
It "Should Return Something" {
97+
$TestMetric | Should Not BeNullOrEmpty
98+
}
99+
It "Should Return my.new.hostname.physicaldisk.e-drive.diskwritequeuelength as Output" {
100+
$TestMetric | Should MatchExactly "my.new.hostname.physicaldisk.e-drive.diskwritequeuelength"
101+
}
102+
103+
$TestMetric = ConvertTo-GraphiteMetric -MetricToClean "\\$($env:COMPUTERNAME)\physicaldisk(1 e:)\avg. disk write queue length" -RemoveUnderscores -NicePhysicalDisks -HostName "host_with_underscores"
104+
105+
It "Should Return host_with_underscores.physicaldisk.e-drive.diskwritequeuelength as Output when RemoveUnderscores is enabled and host has underscores" {
106+
$TestMetric | Should MatchExactly "host_with_underscores.physicaldisk.e-drive.diskwritequeuelength"
107+
}
108+
}
109+
}
110+
111+
Describe "Import-XMLConfig" {
112+
Context "Loading a Configuration File" {
113+
$_config = Import-XMLConfig -ConfigPath "./StatsToGraphiteConfig.xml"
114+
115+
It "Loaded Configuration File Should Not Be Empty" {
116+
$_config | Should Not BeNullOrEmpty
117+
}
118+
It "Should Have 16 Properties" {
119+
$_config.Count | Should Be 17
120+
}
121+
It "SendUsingUDP should be Boolean" {
122+
$_config.SendUsingUDP -is [Boolean] | Should Be $true
123+
}
124+
It "MSSQLMetricSendIntervalSeconds should be Int32" {
125+
$_config.MSSQLMetricSendIntervalSeconds -is [Int32] | Should Be $true
126+
}
127+
It "MSSQLConnectTimeout should be Int32" {
128+
$_config.MSSQLConnectTimeout -is [Int32] | Should Be $true
129+
}
130+
It "MSSQLQueryTimeout should be Int32" {
131+
$_config.MSSQLQueryTimeout -is [Int32] | Should Be $true
132+
}
133+
It "MetricSendIntervalSeconds should be Int32" {
134+
$_config.MetricSendIntervalSeconds -is [Int32] | Should Be $true
135+
}
136+
It "MetricTimeSpan should be TimeSpan" {
137+
$_config.MetricTimeSpan -is [TimeSpan] | Should Be $true
138+
}
139+
It "MSSQLMetricTimeSpan should be TimeSpan" {
140+
$_config.MSSQLMetricTimeSpan -is [TimeSpan] | Should Be $true
141+
}
142+
It "MetricReplace should be HashTable" {
143+
$_config.MetricReplace -is [System.Collections.Specialized.OrderedDictionary] | Should Be $true
144+
}
145+
}
146+
}
147+
}

0 commit comments

Comments
 (0)