Skip to content

Commit c328331

Browse files
committed
Replace testify with stdlib
1 parent fdc0d19 commit c328331

2 files changed

Lines changed: 84 additions & 27 deletions

File tree

check_test.go

Lines changed: 83 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,75 @@ import (
99
"time"
1010

1111
"github.com/spf13/pflag"
12-
"github.com/stretchr/testify/assert"
1312
)
1413

1514
const DefaultTimeout = 15 * time.Second
1615

1716
func 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

3454
func 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

4268
func 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("\nExpected '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("\nExpected 'powershell.exe -EncodedCommand': ", cmd)
80+
}
4881
}
4982

5083
func 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("\nExpected 'dial tcp 192.0.2.11:'", err.Error())
104+
}
65105
}
66106

67107
func 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

144192
func 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("\nExpected 'ConsoleHost'", output)
209+
}
152210
}
153211

154212
func 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
}

go.mod

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ require (
77
github.com/masterzen/winrm v0.0.0-20260407182533-5570be7f80cf
88
github.com/sirupsen/logrus v1.9.4
99
github.com/spf13/pflag v1.0.10
10-
github.com/stretchr/testify v1.11.1
1110
golang.org/x/crypto v0.50.0
1211
)
1312

@@ -16,7 +15,6 @@ require (
1615
github.com/ChrisTrenkamp/goxpath v0.0.0-20210404020558-97928f7e12b6 // indirect
1716
github.com/bodgit/ntlmssp v0.0.0-20240506230425-31973bb52d9b // indirect
1817
github.com/bodgit/windows v1.0.1 // indirect
19-
github.com/davecgh/go-spew v1.1.1 // indirect
2018
github.com/go-logr/logr v1.4.3 // indirect
2119
github.com/gofrs/uuid v4.4.0+incompatible // indirect
2220
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
@@ -28,10 +26,9 @@ require (
2826
github.com/jcmturner/gokrb5/v8 v8.4.4 // indirect
2927
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
3028
github.com/masterzen/simplexml v0.0.0-20190410153822-31eea3082786 // indirect
31-
github.com/pmezard/go-difflib v1.0.0 // indirect
29+
github.com/stretchr/testify v1.11.1 // indirect
3230
github.com/tidwall/transform v0.0.0-20201103190739-32f242e2dbde // indirect
3331
golang.org/x/net v0.53.0 // indirect
3432
golang.org/x/sys v0.43.0 // indirect
3533
golang.org/x/text v0.36.0 // indirect
36-
gopkg.in/yaml.v3 v3.0.1 // indirect
3734
)

0 commit comments

Comments
 (0)