Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions test/powershell/engine/Module/ModuleSpecification.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -228,19 +228,23 @@ Describe "ModuleSpecification objects and logic" -Tag "CI" {
$testCases = @(
@{
TestName = "Version+RequiredVersion"
ModuleSpecification = @{ Name = "BadVersionModule"; ModuleVersion = "3.1"; RequiredVersion = "3.1" }
ModuleSpecification = @{ ModuleName = "BadVersionModule"; ModuleVersion = "3.1"; RequiredVersion = "3.1" }
ErrorId = 'ArgumentException'
},
@{
TestName = "NoName"
ModuleSpecification = @{ ModuleVersion = "0.2" }
ErrorId = 'MissingMemberException'
},
@{
TestName = "BadField"
ModuleSpecification = @{ Name = "StrangeFieldModule"; RequiredVersion = "7.4"; Duck = "1.2" }
ModuleSpecification = @{ ModuleName = "StrangeFieldModule"; RequiredVersion = "7.4"; Duck = "1.2" }
ErrorId = 'ArgumentException'
},
@{
TestName = "BadType"
ModuleSpecification = @{ Name = "BadTypeModule"; RequiredVersion = "Hello!" }
ModuleSpecification = @{ ModuleName = "BadTypeModule"; RequiredVersion = "Hello!" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make the tests more effective we modify L255 to be something like below for the specific expected failure. This will ensure such failures are not hidden due to faulty test code.

Should -Throw -ErrorId ArgumentException

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding first and third tests:

@{TestName = "Version+RequiredVersion"
ModuleSpecification = @{ ModuleName = "BadVersionModule"; ModuleVersion = "3.1"; RequiredVersion = "3.1" }}
@{TestName = "BadField"
ModuleSpecification = @{ ModuleName = "StrangeFieldModule"; RequiredVersion = "7.4"; Duck = "1.2" }}

They return ArgumentException, just like when we use Name instead of ModuleName in the hastable, but I agree, that specifying expected ErrorId is a good addition.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

ErrorId = 'PSInvalidCastException'
}
)
}
Expand All @@ -252,7 +256,7 @@ Describe "ModuleSpecification objects and logic" -Tag "CI" {
It "Cannot create from invalid module hashtables: <TestName>" -TestCases $testCases {
param([string]$TestName, [hashtable]$ModuleSpecification)

{ [ModuleSpecification]::new($ModuleSpecification) } | Should -Throw
{ [ModuleSpecification]::new($ModuleSpecification) } | Should -Throw -ErrorId $ErrorId
}
}
}