2018-07-06 20:02:34 +02:00
|
|
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
# Licensed under the MIT License.
|
|
|
|
|
2019-04-05 08:01:01 +02:00
|
|
|
Import-Module HelpersCommon
|
|
|
|
|
2018-12-05 21:20:58 +01:00
|
|
|
Describe "Get-ExperimentalFeature Tests" -tags "Feature","RequireAdminOnWindows" {
|
2018-07-06 20:02:34 +02:00
|
|
|
|
|
|
|
BeforeAll {
|
2020-01-05 08:17:41 +01:00
|
|
|
$pwsh = "$PSHOME/pwsh"
|
2018-12-05 21:20:58 +01:00
|
|
|
$systemConfigPath = "$PSHOME/powershell.config.json"
|
|
|
|
if ($IsWindows) {
|
|
|
|
$userConfigPath = "~/Documents/powershell/powershell.config.json"
|
2018-07-06 20:02:34 +02:00
|
|
|
}
|
2018-12-05 21:20:58 +01:00
|
|
|
else {
|
|
|
|
$userConfigPath = "~/.config/powershell/powershell.config.json"
|
|
|
|
}
|
|
|
|
|
|
|
|
$systemConfigExists = $false
|
|
|
|
if (Test-Path $systemConfigPath) {
|
|
|
|
$systemConfigExists = $true
|
|
|
|
Move-Item $systemConfigPath "$systemConfigPath.backup" -Force -ErrorAction SilentlyContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
$userConfigExists = $false
|
|
|
|
if (Test-Path $userConfigPath) {
|
|
|
|
$userConfigExists = $true
|
|
|
|
Move-Item $userConfigPath "$userConfigPath.backup" -Force -ErrorAction SilentlyContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
$testModulePath = Join-Path -Path $PSScriptRoot -ChildPath "assets"
|
|
|
|
$testModuleManifestPath = Join-Path -Path $testModulePath "ExpTest" "ExpTest.psd1"
|
|
|
|
$originalModulePath = $env:PSModulePath
|
|
|
|
$env:PSModulePath = $testModulePath
|
2018-07-06 20:02:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
AfterAll {
|
2019-04-05 08:01:01 +02:00
|
|
|
if ($systemConfigExists -and (Test-CanWriteToPsHome)) {
|
2018-12-05 21:20:58 +01:00
|
|
|
Move-Item "$systemConfigPath.backup" $systemConfigPath -Force -ErrorAction SilentlyContinue
|
2018-07-06 20:02:34 +02:00
|
|
|
}
|
|
|
|
|
2018-12-05 21:20:58 +01:00
|
|
|
if ($userConfigExists) {
|
|
|
|
Move-Item "$userConfigPath.backup" $userConfigPath -Force -ErrorAction SilentlyContinue
|
|
|
|
}
|
2018-07-06 20:02:34 +02:00
|
|
|
|
2018-12-05 21:20:58 +01:00
|
|
|
$env:PSModulePath = $originalModulePath
|
|
|
|
}
|
2018-07-06 20:02:34 +02:00
|
|
|
|
2018-12-05 21:20:58 +01:00
|
|
|
AfterEach {
|
2019-04-05 08:01:01 +02:00
|
|
|
if (Test-CanWriteToPsHome) {
|
|
|
|
Remove-Item $systemConfigPath -Force -ErrorAction SilentlyContinue
|
|
|
|
}
|
|
|
|
|
2018-12-05 21:20:58 +01:00
|
|
|
Remove-Item $userConfigPath -Force -ErrorAction SilentlyContinue
|
2018-07-06 20:02:34 +02:00
|
|
|
}
|
|
|
|
|
2018-12-05 21:20:58 +01:00
|
|
|
Context "Feature disabled tests" {
|
2018-07-06 20:02:34 +02:00
|
|
|
|
2018-12-05 21:20:58 +01:00
|
|
|
It "'Get-ExperimentalFeature' should return all available features from module path" {
|
2020-01-05 08:17:41 +01:00
|
|
|
$features = & $pwsh -noprofile -output xml -command Get-ExperimentalFeature "ExpTest*"
|
2018-12-05 21:20:58 +01:00
|
|
|
$features | Should -Not -BeNullOrEmpty
|
|
|
|
$features[0].Name | Should -BeExactly "ExpTest.FeatureOne"
|
|
|
|
$features[0].Enabled | Should -BeFalse
|
|
|
|
$features[0].Source | Should -BeExactly $testModuleManifestPath
|
2018-07-06 20:02:34 +02:00
|
|
|
|
2018-12-05 21:20:58 +01:00
|
|
|
$features[1].Name | Should -BeExactly "ExpTest.FeatureTwo"
|
|
|
|
$features[1].Enabled | Should -BeFalse
|
|
|
|
$features[1].Source | Should -BeExactly $testModuleManifestPath
|
|
|
|
}
|
2018-07-06 20:02:34 +02:00
|
|
|
|
2018-12-05 21:20:58 +01:00
|
|
|
It "'Get-ExperimentalFeature' pipeline input" {
|
2020-01-05 08:17:41 +01:00
|
|
|
$features = & $pwsh -noprofile -output xml -command { "ExpTest.FeatureOne", "ExpTest.FeatureTwo" | Get-ExperimentalFeature }
|
2018-12-05 21:20:58 +01:00
|
|
|
$features | Should -Not -BeNullOrEmpty
|
|
|
|
$features[0].Name | Should -BeExactly "ExpTest.FeatureOne"
|
|
|
|
$features[0].Enabled | Should -BeFalse
|
|
|
|
$features[0].Source | Should -BeExactly $testModuleManifestPath
|
|
|
|
|
|
|
|
$features[1].Name | Should -BeExactly "ExpTest.FeatureTwo"
|
|
|
|
$features[1].Enabled | Should -BeFalse
|
|
|
|
$features[1].Source | Should -BeExactly $testModuleManifestPath
|
2018-07-06 20:02:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-05 21:20:58 +01:00
|
|
|
Context "Feature enabled tests" {
|
|
|
|
BeforeEach {
|
|
|
|
'{"ExperimentalFeatures":["ExpTest.FeatureOne"]}' > $userConfigPath
|
2018-07-06 20:02:34 +02:00
|
|
|
}
|
|
|
|
|
2018-12-05 21:20:58 +01:00
|
|
|
It "'Get-ExperimentalFeature' should return enabled features 'ExpTest.FeatureOne'" {
|
2020-01-05 08:17:41 +01:00
|
|
|
& $pwsh -noprofile -command '$EnabledExperimentalFeatures.Count' | Should -Be 1
|
|
|
|
$feature = & $pwsh -noprofile -output xml -command Get-ExperimentalFeature "ExpTest.FeatureOne"
|
2018-12-05 21:20:58 +01:00
|
|
|
$feature | Should -Not -BeNullOrEmpty
|
|
|
|
$feature.Enabled | Should -BeTrue
|
|
|
|
$feature.Source | Should -BeExactly $testModuleManifestPath
|
|
|
|
}
|
|
|
|
|
|
|
|
It "'Get-ExperimentalFeature' should return all available features from module path" {
|
2020-01-05 08:17:41 +01:00
|
|
|
$features = & $pwsh -noprofile -output xml -command Get-ExperimentalFeature "ExpTest*"
|
2018-12-05 21:20:58 +01:00
|
|
|
$features | Should -Not -BeNullOrEmpty
|
|
|
|
$features[0].Name | Should -BeExactly "ExpTest.FeatureOne"
|
|
|
|
$features[0].Enabled | Should -BeTrue
|
|
|
|
$features[0].Source | Should -BeExactly $testModuleManifestPath
|
|
|
|
|
|
|
|
$features[1].Name | Should -BeExactly "ExpTest.FeatureTwo"
|
|
|
|
$features[1].Enabled | Should -BeFalse
|
|
|
|
$features[1].Source | Should -BeExactly $testModuleManifestPath
|
|
|
|
}
|
2018-07-06 20:02:34 +02:00
|
|
|
|
2018-12-05 21:20:58 +01:00
|
|
|
It "'Get-ExperimentalFeature' pipeline input" {
|
2020-01-05 08:17:41 +01:00
|
|
|
$features = & $pwsh -noprofile -output xml -command { "ExpTest.FeatureOne", "ExpTest.FeatureTwo" | Get-ExperimentalFeature }
|
2018-12-05 21:20:58 +01:00
|
|
|
$features | Should -Not -BeNullOrEmpty
|
|
|
|
$features[0].Name | Should -BeExactly "ExpTest.FeatureOne"
|
|
|
|
$features[0].Enabled | Should -BeTrue
|
|
|
|
$features[0].Source | Should -BeExactly $testModuleManifestPath
|
2018-07-06 20:02:34 +02:00
|
|
|
|
2018-12-05 21:20:58 +01:00
|
|
|
$features[1].Name | Should -BeExactly "ExpTest.FeatureTwo"
|
|
|
|
$features[1].Enabled | Should -BeFalse
|
|
|
|
$features[1].Source | Should -BeExactly $testModuleManifestPath
|
|
|
|
}
|
2018-07-06 20:02:34 +02:00
|
|
|
}
|
|
|
|
|
2018-12-05 21:20:58 +01:00
|
|
|
Context "User config takes precedence over system config" {
|
2019-04-05 08:01:01 +02:00
|
|
|
It "Feature is enabled in user config only" -Skip:(!(Test-CanWriteToPsHome)) {
|
2018-12-05 21:20:58 +01:00
|
|
|
'{"ExperimentalFeatures":["ExpTest.FeatureOne"]}' > $userConfigPath
|
|
|
|
'{"ExperimentalFeatures":["ExpTest.FeatureTwo"]}' > $systemConfigPath
|
2018-07-06 20:02:34 +02:00
|
|
|
|
2020-01-05 08:17:41 +01:00
|
|
|
$feature = & $pwsh -noprofile -output xml -command Get-ExperimentalFeature ExpTest.FeatureOne
|
2018-12-05 21:20:58 +01:00
|
|
|
$feature.Enabled | Should -BeTrue -Because "FeatureOne is enabled in user config"
|
2020-01-05 08:17:41 +01:00
|
|
|
$feature = & $pwsh -noprofile -output xml -command Get-ExperimentalFeature ExpTest.FeatureTwo
|
2018-12-05 21:20:58 +01:00
|
|
|
$feature.Enabled | Should -BeFalse -Because "System config is not read when user config exists"
|
|
|
|
}
|
2018-07-06 20:02:34 +02:00
|
|
|
}
|
|
|
|
}
|
2019-08-08 20:37:25 +02:00
|
|
|
|
|
|
|
Describe "Default enablement of Experimental Features" -Tags CI {
|
|
|
|
BeforeAll {
|
2020-01-14 17:40:50 +01:00
|
|
|
$isPreview = $PSVersionTable.GitCommitId -match "preview|daily"
|
2019-08-08 20:37:25 +02:00
|
|
|
|
|
|
|
Function BeEnabled {
|
|
|
|
[CmdletBinding()]
|
|
|
|
Param(
|
|
|
|
$ActualValue,
|
|
|
|
$Name,
|
|
|
|
[switch]$Negate
|
|
|
|
)
|
|
|
|
|
|
|
|
$failure = if ($Negate) {
|
|
|
|
"Expected: Feature $Name to not be Enabled"
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
"Expected: Feature $Name to be Enabled"
|
|
|
|
}
|
|
|
|
|
|
|
|
return [PSCustomObject]@{
|
|
|
|
Succeeded = if ($Negate) {
|
|
|
|
$ActualValue -eq $false
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$ActualValue -eq $true
|
|
|
|
}
|
|
|
|
FailureMessage = $failure
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Add-AssertionOperator -Name 'BeEnabled' -Test $Function:BeEnabled
|
|
|
|
}
|
|
|
|
|
|
|
|
It "On stable builds, Experimental Features are not enabled" -Skip:($isPreview) {
|
|
|
|
foreach ($expFeature in Get-ExperimentalFeature) {
|
|
|
|
$expFeature.Enabled | Should -Not -BeEnabled -Name $expFeature.Name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
It "On preview builds, Experimental Features are enabled" -Skip:(!$isPreview) {
|
|
|
|
(Join-Path -Path $PSHOME -ChildPath 'powershell.config.json') | Should -Exist
|
|
|
|
|
|
|
|
foreach ($expFeature in Get-ExperimentalFeature) {
|
|
|
|
$expFeature.Enabled | Should -BeEnabled -Name $expFeature.Name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|