From c3283312ab42929a11a6f8b341a25d4780711f12 Mon Sep 17 00:00:00 2001 From: Markus Opolka Date: Thu, 30 Apr 2026 16:14:39 +0200 Subject: [PATCH] Replace testify with stdlib --- check_test.go | 106 +++++++++++++++++++++++++++++++++++++++----------- go.mod | 5 +-- 2 files changed, 84 insertions(+), 27 deletions(-) diff --git a/check_test.go b/check_test.go index c8548db..65aa5af 100644 --- a/check_test.go +++ b/check_test.go @@ -9,14 +9,18 @@ import ( "time" "github.com/spf13/pflag" - "github.com/stretchr/testify/assert" ) const DefaultTimeout = 15 * time.Second func TestConfig_Validate(t *testing.T) { c := &Config{} - assert.Error(t, c.Validate()) + + errVal := c.Validate() + + if errVal == nil { + t.Error("Did expect error got nil") + } // Most basic settings c.Host = "localhost" @@ -24,27 +28,56 @@ func TestConfig_Validate(t *testing.T) { c.User = "administrator" c.Password = "verysecret" - assert.NoError(t, c.Validate()) - assert.Equal(t, c.Port, TlsPort) - assert.False(t, c.NoTls) - assert.Equal(t, c.AuthType, AuthDefault) - assert.True(t, c.validated) + errVal = c.Validate() + + if errVal != nil { + t.Error("Did not expect error got", errVal) + } + + if c.Port != TlsPort { + t.Error("Actual", c.Port, "Expected", TlsPort) + } + + if c.NoTls != false { + t.Error("Expected NoTls to be false, got true") + } + + if c.AuthType != AuthDefault { + t.Error("Actual", c.AuthType, "Expected", AuthDefault) + } + + if c.validated != true { + t.Error("Expected validated to be true, got false") + } } func TestBuildConfigFlags(t *testing.T) { fs := &pflag.FlagSet{} config := BuildConfigFlags(fs) - assert.True(t, fs.HasFlags()) - assert.False(t, config.validated) + if fs.HasFlags() != true { + t.Error("Expected hasFalgs to be true, got false") + } + + if config.validated != false { + t.Error("Expected config.validated to be false, got true") + } + } func TestConfig_BuildCommand(t *testing.T) { c := &Config{Command: "Get-Something"} - assert.Contains(t, c.BuildCommand(), "powershell.exe -EncodedCommand") + + cmd := c.BuildCommand() + if !strings.Contains(c.BuildCommand(), "powershell.exe -EncodedCommand") { + t.Error("\nExpected 'powershell.exe -EncodedCommand': ", cmd) + } c = &Config{IcingaCommand: "Icinga-CheckSomething"} - assert.Contains(t, c.BuildCommand(), "powershell.exe -EncodedCommand") + cmd = c.BuildCommand() + if !strings.Contains(cmd, "powershell.exe -EncodedCommand") { + t.Error("\nExpected 'powershell.exe -EncodedCommand': ", cmd) + } } func TestConfig_Run_WithError(t *testing.T) { @@ -57,11 +90,18 @@ func TestConfig_Run_WithError(t *testing.T) { } err := c.Validate() - assert.NoError(t, err) + if err != nil { + t.Error("Did not expect error got", err) + } _, _, err = c.Run(1 * time.Second) - assert.Error(t, err) - assert.Contains(t, err.Error(), "dial tcp 192.0.2.11:") + if err == nil { + t.Error("Did expect error got nil") + } + + if !strings.Contains(err.Error(), "dial tcp 192.0.2.11:") { + t.Error("\nExpected 'dial tcp 192.0.2.11:'", err.Error()) + } } func TestConfig_Run_Basic(t *testing.T) { @@ -90,7 +130,9 @@ func TestConfig_Run_Basic_WithTLS(t *testing.T) { setupTlsFromEnv(t, c) err := c.Validate() - assert.NoError(t, err) + if err != nil { + t.Error("Did not expect error got", err) + } fmt.Printf("%v\n", c) @@ -106,7 +148,9 @@ func TestConfig_Run_NTLM(t *testing.T) { c.NoTls = true err := c.Validate() - assert.NoError(t, err) + if err != nil { + t.Error("Did not expect error got", err) + } fmt.Printf("%v\n", c) @@ -118,7 +162,9 @@ func TestConfig_Run_NTLM_WithTls(t *testing.T) { setupTlsFromEnv(t, c) err := c.Validate() - assert.NoError(t, err) + if err != nil { + t.Error("Did not expect error got", err) + } fmt.Printf("%v\n", c) @@ -134,7 +180,9 @@ func TestConfig_Run_TLS(t *testing.T) { } err := c.Validate() - assert.NoError(t, err) + if err != nil { + t.Error("Did not expect error got", err) + } fmt.Printf("%v\n", c) @@ -143,12 +191,22 @@ func TestConfig_Run_TLS(t *testing.T) { func runCheck(t *testing.T, c *Config) { err := c.Validate() - assert.NoError(t, err) + if err != nil { + t.Error("Did not expect error got", err) + } rc, output, err := c.Run(DefaultTimeout) - assert.NoError(t, err) - assert.Equal(t, 0, rc) - assert.Contains(t, output, "ConsoleHost") + if err != nil { + t.Error("Did not expect error got", err) + } + + if 0 != rc { + t.Error("Actual", rc, "Expected", 0) + } + + if !strings.Contains(output, "ConsoleHost") { + t.Error("\nExpected 'ConsoleHost'", output) + } } func buildEnvConfig(t *testing.T, auth string) *Config { @@ -201,7 +259,9 @@ func setupTlsFromEnv(t *testing.T, c *Config) { if file := os.Getenv("WINRM_TLS_PORT"); file != "" { tmp, err := strconv.ParseInt(file, 10, 16) - assert.NoError(t, err) + if err != nil { + t.Error("Did not expect error got", err) + } c.Port = int(tmp) } diff --git a/go.mod b/go.mod index 600457a..1bd8f19 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,6 @@ require ( github.com/masterzen/winrm v0.0.0-20260407182533-5570be7f80cf github.com/sirupsen/logrus v1.9.4 github.com/spf13/pflag v1.0.10 - github.com/stretchr/testify v1.11.1 golang.org/x/crypto v0.50.0 ) @@ -16,7 +15,6 @@ require ( github.com/ChrisTrenkamp/goxpath v0.0.0-20210404020558-97928f7e12b6 // indirect github.com/bodgit/ntlmssp v0.0.0-20240506230425-31973bb52d9b // indirect github.com/bodgit/windows v1.0.1 // indirect - github.com/davecgh/go-spew v1.1.1 // indirect github.com/go-logr/logr v1.4.3 // indirect github.com/gofrs/uuid v4.4.0+incompatible // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect @@ -28,10 +26,9 @@ require ( github.com/jcmturner/gokrb5/v8 v8.4.4 // indirect github.com/jcmturner/rpc/v2 v2.0.3 // indirect github.com/masterzen/simplexml v0.0.0-20190410153822-31eea3082786 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/stretchr/testify v1.11.1 // indirect github.com/tidwall/transform v0.0.0-20201103190739-32f242e2dbde // indirect golang.org/x/net v0.53.0 // indirect golang.org/x/sys v0.43.0 // indirect golang.org/x/text v0.36.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect )