From 37b3bf96698fc673ebdf3f5f85436b6cfe784031 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edu=20G=C3=B3mez=20Escandell?= Date: Mon, 16 Oct 2023 11:21:18 +0200 Subject: [PATCH] Add test cases for new failure modes --- .../proservices/landscape/landscape_test.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/windows-agent/internal/proservices/landscape/landscape_test.go b/windows-agent/internal/proservices/landscape/landscape_test.go index 057d02e19..6ba7f5d35 100644 --- a/windows-agent/internal/proservices/landscape/landscape_test.go +++ b/windows-agent/internal/proservices/landscape/landscape_test.go @@ -97,11 +97,12 @@ func TestConnect(t *testing.T) { } testCases := map[string]struct { - precancelContext bool - serverNotAvailable bool - landscapeURLErr bool - tokenErr bool - requireCertificate bool + precancelContext bool + serverNotAvailable bool + landscapeURLErr bool + tokenErr bool + requireCertificate bool + breakLandscapeClientConfig bool breakUIDFile bool uid string @@ -118,6 +119,10 @@ func TestConnect(t *testing.T) { "Error when the landscape URL cannot be retrieved": {landscapeURLErr: true, wantErr: true}, "Error when the server cannot be reached": {serverNotAvailable: true, wantErr: true}, "Error when the first-contact SendUpdatedInfo fails": {tokenErr: true, wantErr: true}, + "Error when the config cannot be accessed": {breakLandscapeClientConfig: true, wantErr: true}, + "Error when the config cannot be parsed": {wantErr: true}, + "Error when the SSL certificate cannot be read": {wantErr: true}, + "Error when the SSL certificate is not valid": {wantErr: true}, } for name, tc := range testCases { @@ -141,6 +146,9 @@ func TestConnect(t *testing.T) { // We trigger an earlier error by erroring out on LandscapeAgentURL landscapeURLErr: tc.landscapeURLErr, + + // We trigger an error when deciding to use a certificate or not + landscapeConfigErr: tc.breakLandscapeClientConfig, } out, err := os.ReadFile(filepath.Join(golden.TestFixturePath(t), "landscape.conf"))