From 78c661a98164133b550a1cd0921af03538c881d8 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Fri, 28 Feb 2025 17:25:06 +0100 Subject: [PATCH 1/6] Fix localization strings --- CHANGELOG.md | 4 ++++ source/Classes/020.SqlAudit.ps1 | 4 ++-- source/Public/Save-SqlDscSqlServerMediaFile.ps1 | 8 ++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4dfe4952b5..b96afcddfa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - SqlServerDsc - Fix localization tests. +- `SqlAudit` + - Fix localization strings in `Assert` method. +- `Save-SqlDscSqlServerMediaFile` + - Fix localizations strings that used wrong keys. ## [17.0.0] - 2024-09-30 diff --git a/source/Classes/020.SqlAudit.ps1 b/source/Classes/020.SqlAudit.ps1 index cef0670f11..6bd95acf07 100644 --- a/source/Classes/020.SqlAudit.ps1 +++ b/source/Classes/020.SqlAudit.ps1 @@ -547,12 +547,12 @@ class SqlAudit : SqlResourceBase # ReserveDiskSpace can only be used with MaximumFiles. if ($properties.Keys -contains 'ReserveDiskSpace' -and $properties.Keys -notcontains 'MaximumFiles') { - $errorMessage = $this.localizedData.BothFileSizePropertiesMustBeSet + $errorMessage = $this.localizedData.ReservDiskSpaceWithoutMaximumFiles New-InvalidArgumentException -ArgumentName 'ReserveDiskSpace' -Message $errorMessage } - # Test so that the path exist. + # Test so that the path exists. if ($properties.Keys -contains 'Path' -and -not (Test-Path -Path $properties.Path)) { $errorMessage = $this.localizedData.PathInvalid -f $properties.Path diff --git a/source/Public/Save-SqlDscSqlServerMediaFile.ps1 b/source/Public/Save-SqlDscSqlServerMediaFile.ps1 index eb88325ff9..07ad5d734b 100644 --- a/source/Public/Save-SqlDscSqlServerMediaFile.ps1 +++ b/source/Public/Save-SqlDscSqlServerMediaFile.ps1 @@ -112,8 +112,8 @@ function Save-SqlDscSqlServerMediaFile if ((Test-Path -Path $destinationFilePath)) { $verboseDescriptionMessage = $script:localizedData.SqlServerMediaFile_Save_ShouldProcessVerboseDescription -f $destinationFilePath - $verboseWarningMessage = $script:localizedData.qlServerMedia_Save_ShouldProcessVerboseWarning -f $destinationFilePath - $captionMessage = $script:localizedData.qlServerMedia_Save_ShouldProcessCaption + $verboseWarningMessage = $script:localizedData.SqlServerMediaFile_Save_ShouldProcessVerboseWarning -f $destinationFilePath + $captionMessage = $script:localizedData.SqlServerMediaFile_Save_ShouldProcessCaption if ($PSCmdlet.ShouldProcess($verboseDescriptionMessage, $verboseWarningMessage, $captionMessage)) { @@ -125,8 +125,6 @@ function Save-SqlDscSqlServerMediaFile } } - Write-Verbose -Message ($script:localizedData.SqlServerMediaFile_Save_ShouldProcessVerboseDescription -f $destinationFilePath) - [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $isExecutable = $false @@ -156,6 +154,8 @@ function Save-SqlDscSqlServerMediaFile $ProgressPreference = 'SilentlyContinue' } + Write-Verbose -Message ($script:localizedData.SqlServerMediaFile_Save_DownloadingInformation -f $Url) + # Download the URL content. Invoke-WebRequest -Uri $Url -OutFile $downloadedFilePath | Out-Null From 2c3233d6d42e3429330ded0e0586044aa56a15b6 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Fri, 28 Feb 2025 18:20:21 +0100 Subject: [PATCH 2/6] Fix SqlConfiguration --- CHANGELOG.md | 2 ++ .../DSC_SqlConfiguration/DSC_SqlConfiguration.psm1 | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b96afcddfa..a82c0db0bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix localization strings in `Assert` method. - `Save-SqlDscSqlServerMediaFile` - Fix localizations strings that used wrong keys. +- `SqlConfiguration` + - Change the alias command to real command name, to pass HQRM tests. ## [17.0.0] - 2024-09-30 diff --git a/source/DSCResources/DSC_SqlConfiguration/DSC_SqlConfiguration.psm1 b/source/DSCResources/DSC_SqlConfiguration/DSC_SqlConfiguration.psm1 index ae94539843..0efca05561 100644 --- a/source/DSCResources/DSC_SqlConfiguration/DSC_SqlConfiguration.psm1 +++ b/source/DSCResources/DSC_SqlConfiguration/DSC_SqlConfiguration.psm1 @@ -74,7 +74,7 @@ function Get-TargetResource if (-not $option) { $errorMessage = $script:localizedData.ConfigurationOptionNotFound -f $OptionName - New-InvalidArgumentException -ArgumentName 'OptionName' -Message $errorMessage + New-ArgumentException -ArgumentName 'OptionName' -Message $errorMessage } Write-Verbose -Message ( @@ -157,7 +157,7 @@ function Set-TargetResource if (-not $option) { $errorMessage = $script:localizedData.ConfigurationOptionNotFound -f $OptionName - New-InvalidArgumentException -ArgumentName 'OptionName' -Message $errorMessage + New-ArgumentException -ArgumentName 'OptionName' -Message $errorMessage } $option.ConfigValue = $OptionValue From eb2034e2ef97aab2042b7a45499c2e0ff0823fdb Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Fri, 28 Feb 2025 18:27:23 +0100 Subject: [PATCH 3/6] Fix HQRM --- CHANGELOG.md | 12 +++++++++++ .../DSC_SqlDatabaseUser.psm1 | 12 +++++------ .../DSC_SqlMaxDop/DSC_SqlMaxDop.psm1 | 4 ++-- .../DSC_SqlMemory/DSC_SqlMemory.psm1 | 20 +++++++++---------- .../DSC_SqlRSSetup/DSC_SqlRSSetup.psm1 | 6 +++--- .../DSC_SqlReplication.psm1 | 2 +- .../DSC_SqlServiceAccount.psm1 | 4 ++-- 7 files changed, 36 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a82c0db0bf..e441789d39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix localizations strings that used wrong keys. - `SqlConfiguration` - Change the alias command to real command name, to pass HQRM tests. +- `SqlDatabaseUser` + - Change the alias command to real command name, to pass HQRM tests. +- `SqlMaxDop` + - Change the alias command to real command name, to pass HQRM tests. +- `SqlMemory` + - Change the alias command to real command name, to pass HQRM tests. +- `SqlReplication` + - Change the alias command to real command name, to pass HQRM tests. +- `SqlRSSetup` + - Change the alias command to real command name, to pass HQRM tests. +- `SqlServiceAccount` + - Change the alias command to real command name, to pass HQRM tests. ## [17.0.0] - 2024-09-30 diff --git a/source/DSCResources/DSC_SqlDatabaseUser/DSC_SqlDatabaseUser.psm1 b/source/DSCResources/DSC_SqlDatabaseUser/DSC_SqlDatabaseUser.psm1 index f62b4097b5..af52130914 100644 --- a/source/DSCResources/DSC_SqlDatabaseUser/DSC_SqlDatabaseUser.psm1 +++ b/source/DSCResources/DSC_SqlDatabaseUser/DSC_SqlDatabaseUser.psm1 @@ -687,37 +687,37 @@ function Assert-Parameters if ($UserType -ne 'Login' -and $PSBoundParameters.ContainsKey('LoginName')) { $errorMessage = $script:localizedData.LoginNameProvidedWithWrongUserType -f $UserType - New-InvalidArgumentException -ArgumentName 'Action' -Message $errorMessage + New-ArgumentException -ArgumentName 'Action' -Message $errorMessage } if ($UserType -ne 'Certificate' -and $PSBoundParameters.ContainsKey('CertificateName')) { $errorMessage = $script:localizedData.CertificateNameProvidedWithWrongUserType -f $UserType - New-InvalidArgumentException -ArgumentName 'Action' -Message $errorMessage + New-ArgumentException -ArgumentName 'Action' -Message $errorMessage } if ($UserType -ne 'AsymmetricKey' -and $PSBoundParameters.ContainsKey('AsymmetricKeyName')) { $errorMessage = $script:localizedData.AsymmetricKeyNameProvidedWithWrongUserType -f $UserType - New-InvalidArgumentException -ArgumentName 'Action' -Message $errorMessage + New-ArgumentException -ArgumentName 'Action' -Message $errorMessage } if ($UserType -eq 'Login' -and -not $PSBoundParameters.ContainsKey('LoginName')) { $errorMessage = $script:localizedData.LoginUserTypeWithoutLoginName -f $UserType - New-InvalidArgumentException -ArgumentName 'Action' -Message $errorMessage + New-ArgumentException -ArgumentName 'Action' -Message $errorMessage } if ($UserType -eq 'AsymmetricKey' -and -not $PSBoundParameters.ContainsKey('AsymmetricKeyName')) { $errorMessage = $script:localizedData.AsymmetricKeyUserTypeWithoutAsymmetricKeyName -f $UserType - New-InvalidArgumentException -ArgumentName 'Action' -Message $errorMessage + New-ArgumentException -ArgumentName 'Action' -Message $errorMessage } if ($UserType -eq 'Certificate' -and -not $PSBoundParameters.ContainsKey('CertificateName')) { $errorMessage = $script:localizedData.CertificateUserTypeWithoutCertificateName -f $UserType - New-InvalidArgumentException -ArgumentName 'Action' -Message $errorMessage + New-ArgumentException -ArgumentName 'Action' -Message $errorMessage } } diff --git a/source/DSCResources/DSC_SqlMaxDop/DSC_SqlMaxDop.psm1 b/source/DSCResources/DSC_SqlMaxDop/DSC_SqlMaxDop.psm1 index ef1a6ba97b..76390e9bbd 100644 --- a/source/DSCResources/DSC_SqlMaxDop/DSC_SqlMaxDop.psm1 +++ b/source/DSCResources/DSC_SqlMaxDop/DSC_SqlMaxDop.psm1 @@ -144,7 +144,7 @@ function Set-TargetResource if ($MaxDop) { $errorMessage = $script:localizedData.MaxDopParamMustBeNull - New-InvalidArgumentException -ArgumentName 'MaxDop' -Message $errorMessage + New-ArgumentException -ArgumentName 'MaxDop' -Message $errorMessage } $targetMaxDop = Get-SqlDscDynamicMaxDop -SqlServerObject $sqlServerObject @@ -302,7 +302,7 @@ function Test-TargetResource if ($MaxDop) { $errorMessage = $script:localizedData.MaxDopParamMustBeNull - New-InvalidArgumentException -ArgumentName 'MaxDop' -Message $errorMessage + New-ArgumentException -ArgumentName 'MaxDop' -Message $errorMessage } $MaxDop = Get-SqlDscDynamicMaxDop diff --git a/source/DSCResources/DSC_SqlMemory/DSC_SqlMemory.psm1 b/source/DSCResources/DSC_SqlMemory/DSC_SqlMemory.psm1 index 7bbe784432..3727ca86f7 100644 --- a/source/DSCResources/DSC_SqlMemory/DSC_SqlMemory.psm1 +++ b/source/DSCResources/DSC_SqlMemory/DSC_SqlMemory.psm1 @@ -166,13 +166,13 @@ function Set-TargetResource if ($MaxMemory) { $errorMessage = $script:localizedData.MaxMemoryParamMustBeNull - New-InvalidArgumentException -ArgumentName 'MaxMemory' -Message $errorMessage + New-ArgumentException -ArgumentName 'MaxMemory' -Message $errorMessage } if ($MaxMemoryPercent) { $errorMessage = $script:localizedData.MaxMemoryPercentParamMustBeNull - New-InvalidArgumentException -ArgumentName 'MaxMemoryPercent' -Message $errorMessage + New-ArgumentException -ArgumentName 'MaxMemoryPercent' -Message $errorMessage } $MaxMemory = Get-SqlDscDynamicMaxMemory @@ -186,7 +186,7 @@ function Set-TargetResource if ($PSBoundParameters.ContainsKey('MaxMemory') -and -not $MaxMemory) { $errorMessage = $script:localizedData.MaxMemoryParamMustNotBeNull - New-InvalidArgumentException -ArgumentName 'MaxMemory' -Message $errorMessage + New-ArgumentException -ArgumentName 'MaxMemory' -Message $errorMessage } } @@ -195,7 +195,7 @@ function Set-TargetResource if ($MaxMemoryPercent) { $errorMessage = $script:localizedData.MaxMemoryPercentParamMustBeNull - New-InvalidArgumentException -ArgumentName 'MaxMemoryPercent' -Message $errorMessage + New-ArgumentException -ArgumentName 'MaxMemoryPercent' -Message $errorMessage } $sqlServerObject.Configuration.MaxServerMemory.ConfigValue = $MaxMemory @@ -220,7 +220,7 @@ function Set-TargetResource if ($MinMemoryPercent) { $errorMessage = $script:localizedData.MinMemoryPercentParamMustBeNull - New-InvalidArgumentException -ArgumentName 'MinMemoryPercent' -Message $errorMessage + New-ArgumentException -ArgumentName 'MinMemoryPercent' -Message $errorMessage } $sqlServerObject.Configuration.MinServerMemory.ConfigValue = $MinMemory @@ -420,13 +420,13 @@ function Test-TargetResource if ($MaxMemory) { $errorMessage = $script:localizedData.MaxMemoryParamMustBeNull - New-InvalidArgumentException -ArgumentName 'MaxMemory' -Message $errorMessage + New-ArgumentException -ArgumentName 'MaxMemory' -Message $errorMessage } if ($MaxMemoryPercent) { $errorMessage = $script:localizedData.MaxMemoryPercentParamMustBeNull - New-InvalidArgumentException -ArgumentName 'MaxMemoryPercent' -Message $errorMessage + New-ArgumentException -ArgumentName 'MaxMemoryPercent' -Message $errorMessage } $MaxMemory = Get-SqlDscDynamicMaxMemory @@ -440,7 +440,7 @@ function Test-TargetResource if ($PSBoundParameters.ContainsKey('MaxMemory') -and -not $MaxMemory) { $errorMessage = $script:localizedData.MaxMemoryParamMustNotBeNull - New-InvalidArgumentException -ArgumentName 'MaxMemory' -Message $errorMessage + New-ArgumentException -ArgumentName 'MaxMemory' -Message $errorMessage } } @@ -449,7 +449,7 @@ function Test-TargetResource if ($MaxMemory -and $MaxMemoryPercent) { $errorMessage = $script:localizedData.MaxMemoryPercentParamMustBeNull - New-InvalidArgumentException -ArgumentName 'MaxMemoryPercent' -Message $errorMessage + New-ArgumentException -ArgumentName 'MaxMemoryPercent' -Message $errorMessage } if ($MaxMemoryPercent) @@ -472,7 +472,7 @@ function Test-TargetResource if ($MinMemory -and $MinMemoryPercent) { $errorMessage = $script:localizedData.MinMemoryPercentParamMustBeNull - New-InvalidArgumentException -ArgumentName 'MinMemoryPercent' -Message $errorMessage + New-ArgumentException -ArgumentName 'MinMemoryPercent' -Message $errorMessage } if ($MinMemoryPercent) diff --git a/source/DSCResources/DSC_SqlRSSetup/DSC_SqlRSSetup.psm1 b/source/DSCResources/DSC_SqlRSSetup/DSC_SqlRSSetup.psm1 index 64fb5ce42e..5a6b9517ec 100644 --- a/source/DSCResources/DSC_SqlRSSetup/DSC_SqlRSSetup.psm1 +++ b/source/DSCResources/DSC_SqlRSSetup/DSC_SqlRSSetup.psm1 @@ -287,20 +287,20 @@ function Set-TargetResource if ($Action -eq 'Install' -and $PSBoundParameters.ContainsKey('Edition') -and $PSBoundParameters.ContainsKey('ProductKey')) { $errorMessage = $script:localizedData.EditionInvalidParameter - New-InvalidArgumentException -ArgumentName 'Edition, ProductKey' -Message $errorMessage + New-ArgumentException -ArgumentName 'Edition, ProductKey' -Message $errorMessage } # Must either choose ProductKey or Edition, not none. if ($Action -eq 'Install' -and -not $PSBoundParameters.ContainsKey('Edition') -and -not $PSBoundParameters.ContainsKey('ProductKey')) { $errorMessage = $script:localizedData.EditionMissingParameter - New-InvalidArgumentException -ArgumentName 'Edition, ProductKey' -Message $errorMessage + New-ArgumentException -ArgumentName 'Edition, ProductKey' -Message $errorMessage } if (-not (Test-Path -Path $SourcePath) -or (Get-Item -Path $SourcePath).Extension -ne '.exe') { $errorMessage = $script:localizedData.SourcePathNotFound -f $SourcePath - New-InvalidArgumentException -ArgumentName 'SourcePath' -Message $errorMessage + New-ArgumentException -ArgumentName 'SourcePath' -Message $errorMessage } $InstanceName = $InstanceName.ToUpper() diff --git a/source/DSCResources/DSC_SqlReplication/DSC_SqlReplication.psm1 b/source/DSCResources/DSC_SqlReplication/DSC_SqlReplication.psm1 index 45a92e6d0b..5c14720c47 100644 --- a/source/DSCResources/DSC_SqlReplication/DSC_SqlReplication.psm1 +++ b/source/DSCResources/DSC_SqlReplication/DSC_SqlReplication.psm1 @@ -232,7 +232,7 @@ function Set-TargetResource if (($DistributorMode -eq 'Remote') -and (-not $RemoteDistributor)) { $errorMessage = $script:localizedData.NoRemoteDistributor - New-InvalidArgumentException -ArgumentName 'RemoteDistributor' -Message $errorMessage + New-ArgumentException -ArgumentName 'RemoteDistributor' -Message $errorMessage } $sqlMajorVersion = Get-SqlInstanceMajorVersion -InstanceName $InstanceName diff --git a/source/DSCResources/DSC_SqlServiceAccount/DSC_SqlServiceAccount.psm1 b/source/DSCResources/DSC_SqlServiceAccount/DSC_SqlServiceAccount.psm1 index b367e79eb6..c158540cac 100644 --- a/source/DSCResources/DSC_SqlServiceAccount/DSC_SqlServiceAccount.psm1 +++ b/source/DSCResources/DSC_SqlServiceAccount/DSC_SqlServiceAccount.psm1 @@ -322,7 +322,7 @@ function Get-ServiceObject if (($ServiceType -eq 'IntegrationServices') -and ([String]::IsNullOrEmpty($VersionNumber))) { $errorMessage = $script:localizedData.MissingParameter -f $ServiceType - New-InvalidArgumentException -Message $errorMessage -ArgumentName 'VersionNumber' + New-ArgumentException -Message $errorMessage -ArgumentName 'VersionNumber' } # Load the SMO libraries @@ -578,7 +578,7 @@ function Get-SqlServiceName else { $errorMessage = $script:localizedData.UnknownServiceType -f $ServiceType - New-InvalidArgumentException -Message $errorMessage -ArgumentName 'ServiceType' + New-ArgumentException -Message $errorMessage -ArgumentName 'ServiceType' } if ([System.String]::IsNullOrEmpty($serviceNamingScheme)) From 5741fb3cf78dbe92f2671c4fb72312531bb6724c Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Fri, 28 Feb 2025 20:50:09 +0100 Subject: [PATCH 4/6] Fix GitHub Actions workflows to patch ModuleBuilder --- .github/workflows/code-analysis-built-module.yml | 10 +++++++++- .github/workflows/code-analysis.yml | 10 +++++++++- CHANGELOG.md | 2 ++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/.github/workflows/code-analysis-built-module.yml b/.github/workflows/code-analysis-built-module.yml index e159b3bce9..3abc65aad7 100644 --- a/.github/workflows/code-analysis-built-module.yml +++ b/.github/workflows/code-analysis-built-module.yml @@ -7,7 +7,7 @@ on: branches: [ main ] workflow_dispatch: -# cSpell: ignore potatoqualitee codeql SARIF +# cSpell: ignore codeql SARIF jobs: pssa: name: PSScriptAnalyzer @@ -34,6 +34,14 @@ jobs: run: | Write-Information -MessageData 'Module is being built.' -InformationAction 'Continue' .\build.ps1 -ResolveDependency -Tasks 'build' + # This is a workaround for the issue: https://github.com/PoshCode/ModuleBuilder/pull/136 + - name: Patch ModuleBuilder + shell: powershell + run: | + Write-Information -MessageData 'Patching ModuleBuilder v3.1.7.' -InformationAction 'Continue' + .\build.ps1 -Tasks 'noop' + Install-PSResource -Name 'Viscalyx.Common' -Repository 'PSGallery' -TrustRepository -Quiet -Confirm:$false + Install-ModulePatch -Uri https://raw.githubusercontent.com/viscalyx/Viscalyx.Common/refs/heads/main/patches/ModuleBuilder_3.1.7_patch.json -Force - name: Run PSScriptAnalyzer shell: powershell run: | diff --git a/.github/workflows/code-analysis.yml b/.github/workflows/code-analysis.yml index f166385b8a..db154d11ce 100644 --- a/.github/workflows/code-analysis.yml +++ b/.github/workflows/code-analysis.yml @@ -7,7 +7,7 @@ on: branches: [ main ] workflow_dispatch: -# cSpell: ignore potatoqualitee codeql SARIF +# cSpell: ignore codeql SARIF jobs: pssa: name: PSScriptAnalyzer @@ -34,6 +34,14 @@ jobs: run: | Write-Information -MessageData 'Module is being built so that examples can be scanned.' -InformationAction 'Continue' .\build.ps1 -ResolveDependency -Tasks 'build' + # This is a workaround for the issue: https://github.com/PoshCode/ModuleBuilder/pull/136 + - name: Patch ModuleBuilder + shell: powershell + run: | + Write-Information -MessageData 'Patching ModuleBuilder v3.1.7.' -InformationAction 'Continue' + .\build.ps1 -Tasks 'noop' + Install-PSResource -Name 'Viscalyx.Common' -Repository 'PSGallery' -TrustRepository -Quiet -Confirm:$false + Install-ModulePatch -Uri https://raw.githubusercontent.com/viscalyx/Viscalyx.Common/refs/heads/main/patches/ModuleBuilder_3.1.7_patch.json -Force - name: Run PSScriptAnalyzer shell: powershell run: | diff --git a/CHANGELOG.md b/CHANGELOG.md index e441789d39..6a3bc1df88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Fixed workaround for the GitHub Actions to support building module in Windows + PowerShell. - SqlServerDsc - Fix localization tests. - `SqlAudit` From 18c694f1da8729a7c4dcaa1f0551dc81a7bfb1c8 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Fri, 28 Feb 2025 20:54:24 +0100 Subject: [PATCH 5/6] Fix github actions --- .github/workflows/code-analysis-built-module.yml | 11 ++++++++--- .github/workflows/code-analysis.yml | 11 ++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.github/workflows/code-analysis-built-module.yml b/.github/workflows/code-analysis-built-module.yml index 3abc65aad7..e266a179b5 100644 --- a/.github/workflows/code-analysis-built-module.yml +++ b/.github/workflows/code-analysis-built-module.yml @@ -29,11 +29,11 @@ jobs: shell: powershell run: | dotnet-gitversion | ConvertFrom-Json - - name: Build Module + - name: Resolve dependencies shell: powershell run: | - Write-Information -MessageData 'Module is being built.' -InformationAction 'Continue' - .\build.ps1 -ResolveDependency -Tasks 'build' + Write-Information -MessageData 'Resolving dependencies.' -InformationAction 'Continue' + .\build.ps1 -ResolveDependency -Tasks 'noop' # This is a workaround for the issue: https://github.com/PoshCode/ModuleBuilder/pull/136 - name: Patch ModuleBuilder shell: powershell @@ -42,6 +42,11 @@ jobs: .\build.ps1 -Tasks 'noop' Install-PSResource -Name 'Viscalyx.Common' -Repository 'PSGallery' -TrustRepository -Quiet -Confirm:$false Install-ModulePatch -Uri https://raw.githubusercontent.com/viscalyx/Viscalyx.Common/refs/heads/main/patches/ModuleBuilder_3.1.7_patch.json -Force + - name: Build Module + shell: powershell + run: | + Write-Information -MessageData 'Module is being built.' -InformationAction 'Continue' + .\build.ps1 -Tasks 'build' - name: Run PSScriptAnalyzer shell: powershell run: | diff --git a/.github/workflows/code-analysis.yml b/.github/workflows/code-analysis.yml index db154d11ce..03c071f1b9 100644 --- a/.github/workflows/code-analysis.yml +++ b/.github/workflows/code-analysis.yml @@ -29,11 +29,11 @@ jobs: shell: powershell run: | dotnet-gitversion | ConvertFrom-Json - - name: Build Module + - name: Resolve dependencies shell: powershell run: | - Write-Information -MessageData 'Module is being built so that examples can be scanned.' -InformationAction 'Continue' - .\build.ps1 -ResolveDependency -Tasks 'build' + Write-Information -MessageData 'Resolving dependencies.' -InformationAction 'Continue' + .\build.ps1 -ResolveDependency -Tasks 'noop' # This is a workaround for the issue: https://github.com/PoshCode/ModuleBuilder/pull/136 - name: Patch ModuleBuilder shell: powershell @@ -42,6 +42,11 @@ jobs: .\build.ps1 -Tasks 'noop' Install-PSResource -Name 'Viscalyx.Common' -Repository 'PSGallery' -TrustRepository -Quiet -Confirm:$false Install-ModulePatch -Uri https://raw.githubusercontent.com/viscalyx/Viscalyx.Common/refs/heads/main/patches/ModuleBuilder_3.1.7_patch.json -Force + - name: Build Module + shell: powershell + run: | + Write-Information -MessageData 'Module is being built.' -InformationAction 'Continue' + .\build.ps1 -Tasks 'build' - name: Run PSScriptAnalyzer shell: powershell run: | From 23d7eb17b586971bcb68c753978cba3e1629c1ac Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Sat, 1 Mar 2025 08:02:11 +0100 Subject: [PATCH 6/6] Fix unit test for SqlAudit --- tests/Unit/Classes/SqlAudit.Tests.ps1 | 70 ++++++++++++++------------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/tests/Unit/Classes/SqlAudit.Tests.ps1 b/tests/Unit/Classes/SqlAudit.Tests.ps1 index 827a6faa01..ae33ab4068 100644 --- a/tests/Unit/Classes/SqlAudit.Tests.ps1 +++ b/tests/Unit/Classes/SqlAudit.Tests.ps1 @@ -835,31 +835,31 @@ Describe 'SqlAudit\Modify()' -Tag 'Modify' { Context 'When the property is not in desired state' -ForEach @( @{ - MockPropertyName = 'Path' + MockPropertyName = 'Path' MockExpectedValue = 'C:\NewValue' } @{ - MockPropertyName = 'AuditFilter' + MockPropertyName = 'AuditFilter' MockExpectedValue = 'object -like ''something''' } @{ - MockPropertyName = 'MaximumFiles' + MockPropertyName = 'MaximumFiles' MockExpectedValue = 2 } @{ - MockPropertyName = 'MaximumRolloverFiles' + MockPropertyName = 'MaximumRolloverFiles' MockExpectedValue = 2 } @{ - MockPropertyName = 'OnFailure' + MockPropertyName = 'OnFailure' MockExpectedValue = 'FailOperation' } @{ - MockPropertyName = 'QueueDelay' + MockPropertyName = 'QueueDelay' MockExpectedValue = 2000 } @{ - MockPropertyName = 'AuditGuid' + MockPropertyName = 'AuditGuid' MockExpectedValue = 'cfa0d47e-bf93-41ab-bc9a-b8511acbcdd6' } ) { @@ -909,10 +909,10 @@ Describe 'SqlAudit\Modify()' -Tag 'Modify' { BeforeAll { InModuleScope -ScriptBlock { $script:mockSqlAuditInstance = [SqlAudit] @{ - Name = 'MockAuditName' - InstanceName = 'NamedInstance' - MaximumFileSize = 20 - MaximumFileSizeUnit = 'Megabyte' + Name = 'MockAuditName' + InstanceName = 'NamedInstance' + MaximumFileSize = 20 + MaximumFileSizeUnit = 'Megabyte' } | Add-Member -Force -MemberType 'ScriptMethod' -Name 'GetServerObject' -Value { return New-Object -TypeName 'Microsoft.SqlServer.Management.Smo.Server' @@ -953,10 +953,10 @@ Describe 'SqlAudit\Modify()' -Tag 'Modify' { BeforeAll { InModuleScope -ScriptBlock { $script:mockSqlAuditInstance = [SqlAudit] @{ - Name = 'MockAuditName' - InstanceName = 'NamedInstance' - MaximumFileSize = 20 - MaximumFileSizeUnit = 'Megabyte' + Name = 'MockAuditName' + InstanceName = 'NamedInstance' + MaximumFileSize = 20 + MaximumFileSizeUnit = 'Megabyte' } | Add-Member -Force -MemberType 'ScriptMethod' -Name 'GetServerObject' -Value { return New-Object -TypeName 'Microsoft.SqlServer.Management.Smo.Server' @@ -1041,9 +1041,9 @@ Describe 'SqlAudit\Modify()' -Tag 'Modify' { BeforeAll { InModuleScope -ScriptBlock { $script:mockSqlAuditInstance = [SqlAudit] @{ - Name = 'MockAuditName' - InstanceName = 'NamedInstance' - MaximumFiles = 20 + Name = 'MockAuditName' + InstanceName = 'NamedInstance' + MaximumFiles = 20 } | Add-Member -Force -MemberType 'ScriptMethod' -Name 'GetServerObject' -Value { return New-Object -TypeName 'Microsoft.SqlServer.Management.Smo.Server' @@ -1089,10 +1089,10 @@ Describe 'SqlAudit\Modify()' -Tag 'Modify' { BeforeAll { InModuleScope -ScriptBlock { $script:mockSqlAuditInstance = [SqlAudit] @{ - Name = 'MockAuditName' - InstanceName = 'NamedInstance' - Path = 'C:\Temp' - Force = $true + Name = 'MockAuditName' + InstanceName = 'NamedInstance' + Path = 'C:\Temp' + Force = $true } | Add-Member -Force -MemberType 'ScriptMethod' -Name 'GetServerObject' -Value { return New-Object -TypeName 'Microsoft.SqlServer.Management.Smo.Server' @@ -1145,10 +1145,10 @@ Describe 'SqlAudit\Modify()' -Tag 'Modify' { BeforeAll { InModuleScope -ScriptBlock { $script:mockSqlAuditInstance = [SqlAudit] @{ - Name = 'MockAuditName' - InstanceName = 'NamedInstance' - LogType = 'ApplicationLog' - Force = $true + Name = 'MockAuditName' + InstanceName = 'NamedInstance' + LogType = 'ApplicationLog' + Force = $true } | Add-Member -Force -MemberType 'ScriptMethod' -Name 'GetServerObject' -Value { return New-Object -TypeName 'Microsoft.SqlServer.Management.Smo.Server' @@ -1201,9 +1201,9 @@ Describe 'SqlAudit\Modify()' -Tag 'Modify' { BeforeAll { InModuleScope -ScriptBlock { $script:mockSqlAuditInstance = [SqlAudit] @{ - Name = 'MockAuditName' - InstanceName = 'NamedInstance' - Path = 'C:\Temp' + Name = 'MockAuditName' + InstanceName = 'NamedInstance' + Path = 'C:\Temp' } | Add-Member -Force -MemberType 'ScriptMethod' -Name 'GetServerObject' -Value { return New-Object -TypeName 'Microsoft.SqlServer.Management.Smo.Server' @@ -1490,23 +1490,25 @@ Describe 'SqlAudit\AssertProperties()' -Tag 'AssertProperties' { BeforeAll { InModuleScope -ScriptBlock { $script:mockSqlAuditInstance = [SqlAudit] @{ - Name = 'MockAuditName' - InstanceName = 'NamedInstance' - Path = 'C:\Temp' + Name = 'MockAuditName' + InstanceName = 'NamedInstance' + Path = 'C:\Temp' } } } It 'Should throw the correct error' { InModuleScope -ScriptBlock { - $mockErrorMessage = $script:mockSqlAuditInstance.localizedData.BothFileSizePropertiesMustBeSet + $mockErrorMessage = $script:mockSqlAuditInstance.localizedData.ReservDiskSpaceWithoutMaximumFiles $mockErrorMessage += ' (Parameter ''ReserveDiskSpace'')' { $mockSqlAuditInstance.AssertProperties( @{ - ReserveDiskSpace = $true + MaximumFileSize = 10 + MaximumFileSizeUnit = 'Megabyte' + ReserveDiskSpace = $true } ) } | Should -Throw -ExpectedMessage $mockErrorMessage