From a8cb4e423e949e873e07c9f6a9184c8c0dcdc1c0 Mon Sep 17 00:00:00 2001 From: Dustin Strobel Date: Mon, 16 Oct 2023 17:29:10 +0200 Subject: [PATCH] test: add test for winrm default values --- connection/winrm_test.go | 63 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/connection/winrm_test.go b/connection/winrm_test.go index 213497c..538cec4 100644 --- a/connection/winrm_test.go +++ b/connection/winrm_test.go @@ -47,3 +47,66 @@ func TestNewWinRMClient(t *testing.T) { } }) } + +func TestNewWinRMClientWithDefaultValues(t *testing.T) { + t.Run("Defaults Used", func(t *testing.T) { + // Test case with minimal configuration, should use default values + config := &WinRMConfig{ + WinRMHost: "example.com", + WinRMUsername: "username", + WinRMPassword: "password", + } + + client, err := newWinRMClient(config) + + if err != nil { + t.Errorf("Expected no error, but got %v", err) + } + + if client == nil { + t.Error("Expected a non-nil client, but got nil") + } + + // Check that default values were applied + if config.WinRMPort != defaultWinRMPort { + t.Errorf("Expected WinRMPort to be %d, but got %d", defaultWinRMPort, config.WinRMPort) + } + + if config.WinRMUseTLS != defaultWinRMUseTLS { + t.Errorf("Expected WinRMUseTLS to be %v, but got %v", defaultWinRMUseTLS, config.WinRMUseTLS) + } + + if config.WinRMTimeout != defaultWinRMTimeout { + t.Errorf("Expected WinRMTimeout to be %v, but got %v", defaultWinRMTimeout, config.WinRMTimeout) + } + }) + + t.Run("TLS Used", func(t *testing.T) { + // Test case with minimal configuration, should use default values + config := &WinRMConfig{ + WinRMHost: "example.com", + WinRMUsername: "username", + WinRMPassword: "password", + WinRMUseTLS: true, + } + + client, err := newWinRMClient(config) + + if err != nil { + t.Errorf("Expected no error, but got %v", err) + } + + if client == nil { + t.Error("Expected a non-nil client, but got nil") + } + + // Check that default values were applied + if config.WinRMPort != defaultWinRMPortTLS { + t.Errorf("Expected WinRMPort to be %d, but got %d", defaultWinRMPortTLS, config.WinRMPort) + } + + if config.WinRMTimeout != defaultWinRMTimeout { + t.Errorf("Expected WinRMTimeout to be %v, but got %v", defaultWinRMTimeout, config.WinRMTimeout) + } + }) +}