2019-06-11 22:24:35 +00:00
require " helper "
require " inspec/resource "
require " inspec/resources/windows_feature "
2015-09-20 15:42:56 +00:00
2019-06-11 22:24:35 +00:00
describe " Inspec::Resources::WindowsFeature " do
it " can retrieve feature info using PowerShell " do
2018-07-25 20:00:06 +00:00
resource = MockLoader . new ( :windows ) . load_resource (
2019-06-11 22:24:35 +00:00
" windows_feature " ,
" DHCP " ,
:powershell
2018-07-25 20:00:06 +00:00
)
params = {
2019-06-11 22:24:35 +00:00
name : " DHCP " ,
description : " Dynamic Host Configuration Protocol (DHCP) Server enables you to centrally configure, manage, and provide temporary IP addresses and related information for client computers. " ,
2018-07-25 20:00:06 +00:00
installed : false ,
method : :powershell ,
}
_ ( resource . info ) . must_equal params
_ ( resource . installed? ) . must_equal false
end
2019-06-11 22:24:35 +00:00
it " can retrieve feature info using DISM " do
2018-07-25 20:00:06 +00:00
resource = MockLoader . new ( :windows ) . load_resource (
2019-06-11 22:24:35 +00:00
" windows_feature " ,
" IIS-WebServer " ,
:dism
2018-07-25 20:00:06 +00:00
)
params = {
2019-06-11 22:24:35 +00:00
name : " IIS-WebServer " ,
description : " Installs the IIS 10.0 World Wide Web Services. Provides support for HTML web sites and optional support for ASP.NET, Classic ASP, and web server extensions. " ,
2018-07-25 20:00:06 +00:00
installed : true ,
method : :dism ,
}
_ ( resource . info ) . must_equal params
_ ( resource . installed? ) . must_equal true
end
2019-06-11 22:24:35 +00:00
it " uses DISM when Get-WindowsFeature does not exist " do
2018-07-25 20:00:06 +00:00
resource = MockLoader . new ( :windows )
2019-07-09 00:20:30 +00:00
. load_resource ( " windows_feature " , " IIS-WebServer " )
2018-07-25 20:00:06 +00:00
params = {
2019-06-11 22:24:35 +00:00
name : " IIS-WebServer " ,
description : " Installs the IIS 10.0 World Wide Web Services. Provides support for HTML web sites and optional support for ASP.NET, Classic ASP, and web server extensions. " ,
2018-07-25 20:00:06 +00:00
installed : true ,
method : :dism ,
}
_ ( resource . info ) . must_equal params
_ ( resource . installed? ) . must_equal true
end
2019-06-11 22:24:35 +00:00
it " fails the resource if PowerShell method is used but command not found " do
2018-07-25 20:00:06 +00:00
resource = MockLoader . new ( :windows ) . load_resource (
2019-06-11 22:24:35 +00:00
" windows_feature " ,
" IIS-WebServer " ,
:powershell
2018-07-25 20:00:06 +00:00
)
2019-09-30 22:31:55 +00:00
e = _ { resource . info } . must_raise ( Inspec :: Exceptions :: ResourceFailed )
2018-07-25 20:00:06 +00:00
2019-09-30 22:31:55 +00:00
_ ( e . message ) . must_match ( / Could not find `Get-WindowsFeature` / )
2015-09-20 15:42:56 +00:00
end
end