Skip to content

Commit 3c30e8e

Browse files
authored
Merge pull request #38 from dataplat/28-WorkspaceName-validation
Fixed validation for WorkspaceName in Get-FabricWorkspace cmdlet #28
2 parents 178a393 + 1b6035a commit 3c30e8e

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

source/Public/Workspace/Get-FabricWorkspace.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function Get-FabricWorkspace {
3838

3939
[Parameter(Mandatory = $false)]
4040
[ValidateNotNullOrEmpty()]
41-
[ValidatePattern('^[a-zA-Z0-9_ ]*$')]
41+
[ValidatePattern('^[a-zA-Z0-9_\- ]*$')]
4242
[string]$WorkspaceName
4343
)
4444

@@ -140,4 +140,4 @@ function Get-FabricWorkspace {
140140
$errorDetails = $_.Exception.Message
141141
Write-Message -Message "Failed to retrieve workspace. Error: $errorDetails" -Level Error
142142
}
143-
}
143+
}

tests/Unit/Get-FabricWorkspace.Tests.ps1

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ param(
1616
"OutVariable"
1717
"OutBuffer"
1818
"PipelineVariable"
19-
19+
2020
)
2121
)
2222

@@ -43,5 +43,17 @@ Describe "Get-FabricWorkspace" -Tag "UnitTests" {
4343
Compare-Object -ReferenceObject $expected -DifferenceObject $hasparms | Should -BeNullOrEmpty
4444
}
4545
}
46-
}
4746

47+
Context "WorkspaceName parameter validation" {
48+
It "Throws error when WorkspaceName does not match ValidatePattern" {
49+
# Assuming the ValidatePattern allows only alphanumeric, underscore, space and hyphen
50+
{ Get-FabricWorkspace -WorkspaceName "InvalidName!" } | Should -Throw
51+
{ Get-FabricWorkspace -WorkspaceName "Another@Invalid" } | Should -Throw
52+
}
53+
54+
It "Does not throw when WorkspaceName matches ValidatePattern" {
55+
{ Get-FabricWorkspace -WorkspaceName "Valid_Name-123" } | Should -Not -Throw
56+
{ Get-FabricWorkspace -WorkspaceName "Another Valid Name" } | Should -Not -Throw
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)