From baee8daae8f2de6047175fbf20df7fb30e4c9f72 Mon Sep 17 00:00:00 2001 From: Christoph Hartmann Date: Sun, 20 Sep 2015 17:42:56 +0200 Subject: [PATCH] add unit tests for windows feature --- test/helper.rb | 1 + test/unit/mock/cmd/get-windows-feature | 7 +++++++ test/unit/resource_windows_feature.rb | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 test/unit/mock/cmd/get-windows-feature create mode 100644 test/unit/resource_windows_feature.rb diff --git a/test/helper.rb b/test/helper.rb index 72bfcc693..d41643f5f 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -69,6 +69,7 @@ def loadResource (resource, *args) 'pip show jinja2' => cmd.call('pip-show-jinja2'), "Get-Package -Name 'Mozilla Firefox' | ConvertTo-Json" => cmd.call('get-package'), "New-Object -Type PSObject | Add-Member -MemberType NoteProperty -Name Service -Value (Get-Service -Name dhcp| Select-Object -Property Name, DisplayName, Status) -PassThru | Add-Member -MemberType NoteProperty -Name WMI -Value (Get-WmiObject -Class Win32_Service | Where-Object {$_.Name -eq 'dhcp' -or $_.DisplayName -eq 'dhcp'} | Select-Object -Property StartMode) -PassThru | ConvertTo-Json" => cmd.call('get-service-dhcp'), + "Get-WindowsFeature | Where-Object {$_.Name -eq 'dhcp' -or $_.DisplayName -eq 'dhcp'} | Select-Object -Property Name,DisplayName,Description,Installed,InstallState | ConvertTo-Json" => cmd.call('get-windows-feature'), } # load resource diff --git a/test/unit/mock/cmd/get-windows-feature b/test/unit/mock/cmd/get-windows-feature new file mode 100644 index 000000000..318359962 --- /dev/null +++ b/test/unit/mock/cmd/get-windows-feature @@ -0,0 +1,7 @@ +{ + "Name": "DHCP", + "DisplayName": "DHCP Server", + "Description": "Dynamic Host Configuration Protocol (DHCP) Server enables you to centrally configure, manage, and provide temporary IP addresses and related information for client computers.", + "Installed": false, + "InstallState": 0 +} diff --git a/test/unit/resource_windows_feature.rb b/test/unit/resource_windows_feature.rb new file mode 100644 index 000000000..988f7a252 --- /dev/null +++ b/test/unit/resource_windows_feature.rb @@ -0,0 +1,18 @@ +# encoding utf-8 + +require 'helper' +require 'vulcano/resource' + +describe 'Vulcano:Resources::Feature' do + describe 'feature' do + + let(:resource) { loadResource('windows_feature', 'dhcp') } + + # TODO: set windows as mock os + it 'verify windows feature parsing' do + pkg = { 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.', installed: false, type: 'windows-feature' } + _(resource.info).must_equal pkg + _(resource.installed?).must_equal false + end + end +end