@@ -9,42 +9,75 @@ import (
99 "time"
1010
1111 "github.com/spf13/pflag"
12- "github.com/stretchr/testify/assert"
1312)
1413
1514const DefaultTimeout = 15 * time .Second
1615
1716func TestConfig_Validate (t * testing.T ) {
1817 c := & Config {}
19- assert .Error (t , c .Validate ())
18+
19+ errVal := c .Validate ()
20+
21+ if errVal == nil {
22+ t .Error ("Did expect error got nil" )
23+ }
2024
2125 // Most basic settings
2226 c .Host = "localhost"
2327 c .Command = "Get-Something"
2428 c .User = "administrator"
2529 c .Password = "verysecret"
2630
27- assert .NoError (t , c .Validate ())
28- assert .Equal (t , c .Port , TlsPort )
29- assert .False (t , c .NoTls )
30- assert .Equal (t , c .AuthType , AuthDefault )
31- assert .True (t , c .validated )
31+ errVal = c .Validate ()
32+
33+ if errVal != nil {
34+ t .Error ("Did not expect error got" , errVal )
35+ }
36+
37+ if c .Port != TlsPort {
38+ t .Error ("Actual" , c .Port , "Expected" , TlsPort )
39+ }
40+
41+ if c .NoTls != false {
42+ t .Error ("Expected NoTls to be false, got true" )
43+ }
44+
45+ if c .AuthType != AuthDefault {
46+ t .Error ("Actual" , c .AuthType , "Expected" , AuthDefault )
47+ }
48+
49+ if c .validated != true {
50+ t .Error ("Expected validated to be true, got false" )
51+ }
3252}
3353
3454func TestBuildConfigFlags (t * testing.T ) {
3555 fs := & pflag.FlagSet {}
3656 config := BuildConfigFlags (fs )
3757
38- assert .True (t , fs .HasFlags ())
39- assert .False (t , config .validated )
58+ if fs .HasFlags () != true {
59+ t .Error ("Expected hasFalgs to be true, got false" )
60+ }
61+
62+ if config .validated != false {
63+ t .Error ("Expected config.validated to be false, got true" )
64+ }
65+
4066}
4167
4268func TestConfig_BuildCommand (t * testing.T ) {
4369 c := & Config {Command : "Get-Something" }
44- assert .Contains (t , c .BuildCommand (), "powershell.exe -EncodedCommand" )
70+
71+ cmd := c .BuildCommand ()
72+ if ! strings .Contains (c .BuildCommand (), "powershell.exe -EncodedCommand" ) {
73+ t .Error ("\n Expected 'powershell.exe -EncodedCommand': " , cmd )
74+ }
4575
4676 c = & Config {IcingaCommand : "Icinga-CheckSomething" }
47- assert .Contains (t , c .BuildCommand (), "powershell.exe -EncodedCommand" )
77+ cmd = c .BuildCommand ()
78+ if ! strings .Contains (cmd , "powershell.exe -EncodedCommand" ) {
79+ t .Error ("\n Expected 'powershell.exe -EncodedCommand': " , cmd )
80+ }
4881}
4982
5083func TestConfig_Run_WithError (t * testing.T ) {
@@ -57,11 +90,18 @@ func TestConfig_Run_WithError(t *testing.T) {
5790 }
5891
5992 err := c .Validate ()
60- assert .NoError (t , err )
93+ if err != nil {
94+ t .Error ("Did not expect error got" , err )
95+ }
6196
6297 _ , _ , err = c .Run (1 * time .Second )
63- assert .Error (t , err )
64- assert .Contains (t , err .Error (), "dial tcp 192.0.2.11:" )
98+ if err == nil {
99+ t .Error ("Did expect error got nil" )
100+ }
101+
102+ if ! strings .Contains (err .Error (), "dial tcp 192.0.2.11:" ) {
103+ t .Error ("\n Expected 'dial tcp 192.0.2.11:'" , err .Error ())
104+ }
65105}
66106
67107func TestConfig_Run_Basic (t * testing.T ) {
@@ -90,7 +130,9 @@ func TestConfig_Run_Basic_WithTLS(t *testing.T) {
90130 setupTlsFromEnv (t , c )
91131
92132 err := c .Validate ()
93- assert .NoError (t , err )
133+ if err != nil {
134+ t .Error ("Did not expect error got" , err )
135+ }
94136
95137 fmt .Printf ("%v\n " , c )
96138
@@ -106,7 +148,9 @@ func TestConfig_Run_NTLM(t *testing.T) {
106148 c .NoTls = true
107149
108150 err := c .Validate ()
109- assert .NoError (t , err )
151+ if err != nil {
152+ t .Error ("Did not expect error got" , err )
153+ }
110154
111155 fmt .Printf ("%v\n " , c )
112156
@@ -118,7 +162,9 @@ func TestConfig_Run_NTLM_WithTls(t *testing.T) {
118162 setupTlsFromEnv (t , c )
119163
120164 err := c .Validate ()
121- assert .NoError (t , err )
165+ if err != nil {
166+ t .Error ("Did not expect error got" , err )
167+ }
122168
123169 fmt .Printf ("%v\n " , c )
124170
@@ -134,7 +180,9 @@ func TestConfig_Run_TLS(t *testing.T) {
134180 }
135181
136182 err := c .Validate ()
137- assert .NoError (t , err )
183+ if err != nil {
184+ t .Error ("Did not expect error got" , err )
185+ }
138186
139187 fmt .Printf ("%v\n " , c )
140188
@@ -143,12 +191,22 @@ func TestConfig_Run_TLS(t *testing.T) {
143191
144192func runCheck (t * testing.T , c * Config ) {
145193 err := c .Validate ()
146- assert .NoError (t , err )
194+ if err != nil {
195+ t .Error ("Did not expect error got" , err )
196+ }
147197
148198 rc , output , err := c .Run (DefaultTimeout )
149- assert .NoError (t , err )
150- assert .Equal (t , 0 , rc )
151- assert .Contains (t , output , "ConsoleHost" )
199+ if err != nil {
200+ t .Error ("Did not expect error got" , err )
201+ }
202+
203+ if 0 != rc {
204+ t .Error ("Actual" , rc , "Expected" , 0 )
205+ }
206+
207+ if ! strings .Contains (output , "ConsoleHost" ) {
208+ t .Error ("\n Expected 'ConsoleHost'" , output )
209+ }
152210}
153211
154212func buildEnvConfig (t * testing.T , auth string ) * Config {
@@ -201,7 +259,9 @@ func setupTlsFromEnv(t *testing.T, c *Config) {
201259
202260 if file := os .Getenv ("WINRM_TLS_PORT" ); file != "" {
203261 tmp , err := strconv .ParseInt (file , 10 , 16 )
204- assert .NoError (t , err )
262+ if err != nil {
263+ t .Error ("Did not expect error got" , err )
264+ }
205265
206266 c .Port = int (tmp )
207267 }
0 commit comments