Skip to content

Commit

Permalink
Merge pull request #1 from RoboticCheese/jdh-add-windows-support
Browse files Browse the repository at this point in the history
Add Windows support
  • Loading branch information
hartmantis committed May 29, 2015
2 parents 352819a + fe36216 commit 0f6f2f5
Show file tree
Hide file tree
Showing 15 changed files with 227 additions and 35 deletions.
3 changes: 3 additions & 0 deletions .kitchen.yml
Expand Up @@ -11,6 +11,9 @@ platforms:
box: roboticcheese/macosx-10.10
ssh:
insert_key: false
- name: windows-8
driver:
box: roboticcheese/windows-8

suites:
- name: default
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -26,6 +26,7 @@ group :test do
gem 'kitchen-digitalocean', '>= 0.8.0'
gem 'kitchen-localhost'
gem 'kitchen-vagrant'
gem 'winrm-transport'
end

group :integration do
Expand Down
9 changes: 6 additions & 3 deletions README.md
Expand Up @@ -15,8 +15,7 @@ A Chef cookbook for installing Steam.
Requirements
============

This cookbook currently supports OS X only. Windows and Ubuntu support is
coming.
This cookbook currently supports OS X and Windows. Ubuntu support is coming.

Usage
=====
Expand Down Expand Up @@ -62,7 +61,11 @@ Providers

***Chef::Provider::SteamApp::MacOsX***

Provider for the Mac OS X platform.
Provider for Mac OS X platforms.

***Chef::Provider::SteamApp::Windows***

Provider for Windows platforms.

***Chef::Provider::SteamApp***

Expand Down
6 changes: 3 additions & 3 deletions libraries/provider_mapping.rb
Expand Up @@ -25,9 +25,9 @@
Chef::Platform.set(platform: :mac_os_x,
resource: :steam_app,
provider: Chef::Provider::SteamApp::MacOsX)
# TODO: Chef::Platform.set(platform: :windows,
# resource: :steam_app,
# provider: Chef::Provider::SteamApp::Windows)
Chef::Platform.set(platform: :windows,
resource: :steam_app,
provider: Chef::Provider::SteamApp::Windows)
# TODO: Chef::Platform.set(platform: :ubuntu,
# resource: :steam_app,
# provider: Chef::Provider::SteamApp::Debian)
Expand Down
2 changes: 1 addition & 1 deletion libraries/provider_steam_app.rb
Expand Up @@ -21,7 +21,7 @@
require 'chef/provider/lwrp_base'
require_relative 'resource_steam_app'
require_relative 'provider_steam_app_mac_os_x'
# TODO: require_relative 'provider_steam_app_windows'
require_relative 'provider_steam_app_windows'
# TODO: require_relative 'provider_steam_app_debian'

class Chef
Expand Down
93 changes: 93 additions & 0 deletions libraries/provider_steam_app_windows.rb
@@ -0,0 +1,93 @@
# Encoding: UTF-8
#
# Cookbook Name:: steam
# Library:: provider_steam_app_windows
#
# Copyright 2015 Jonathan Hartman
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require 'chef/provider/lwrp_base'
require_relative 'provider_steam_app'

class Chef
class Provider
class SteamApp < Provider::LWRPBase
# An provider for Steam on Windows.
#
# @author Jonathan Hartman <j@p4nt5.com>
class Windows < SteamApp
URL ||= 'https://steamcdn-a.akamaihd.net/client/installer/' \
'SteamSetup.exe'
PATH ||= ::File.expand_path('/Program Files (x86)/Steam')

private

#
# Download and install the remote package.
#
# (see SteamApp#install!)
#
def install!
download_package
install_package
end

#
# Use a windows_package resource to uninstall Steam.
#
# (see SteamApp#remove!)
#
def remove!
windows_package 'Steam' do
action :remove
end
end

#
# Use a windows_package resource to install the .exe file.
#
def install_package
s = download_path
windows_package 'Steam' do
source s
installer_type :nsis
action :install
end
end

#
# Use a remote_file resource to download the .exe file to Chef's cache
# dir.
#
def download_package
remote_file download_path do
source URL
action :create
only_if { !::File.exist?(PATH) }
end
end

#
# Construct a download destination under Chef's cache dir.
#
# @return [String]
#
def download_path
::File.join(Chef::Config[:file_cache_path], ::File.basename(URL))
end
end
end
end
end
6 changes: 4 additions & 2 deletions metadata.rb
Expand Up @@ -5,11 +5,13 @@
maintainer 'Jonathan Hartman'
maintainer_email 'j@p4nt5.com'
license 'apache2'
description 'Installs/Configures steam'
long_description 'Installs/Configures steam'
description 'Installs/Configures Steam'
long_description 'Installs/Configures Steam'
version '0.0.1'

depends 'dmg', '~> 2.2'
depends 'windows', '~> 1.37'

supports 'mac_os_x'
supports 'windows'
# rubocop:enable SingleSpaceBeforeFirstArg
1 change: 0 additions & 1 deletion spec/libraries/provider_mapping_spec.rb
Expand Up @@ -22,7 +22,6 @@
let(:platform) { :windows }

it 'uses the Windows app provider' do
pending
expect(app_provider).to eq(Chef::Provider::SteamApp::Windows)
end
end
Expand Down
68 changes: 68 additions & 0 deletions spec/libraries/provider_steam_app_windows_spec.rb
@@ -0,0 +1,68 @@
# Encoding: UTF-8

require_relative '../spec_helper'
require_relative '../../libraries/provider_steam_app_windows'

describe Chef::Provider::SteamApp::Windows do
let(:name) { 'default' }
let(:new_resource) { Chef::Resource::SteamApp.new(name, nil) }
let(:provider) { described_class.new(new_resource, nil) }

describe '#install!' do
it 'downloads and installs the package' do
p = provider
expect(p).to receive(:download_package)
expect(p).to receive(:install_package)
p.send(:install!)
end
end

describe '#remove!' do
it 'uses a windows_package to uninstall the package' do
p = provider
expect(p).to receive(:windows_package).with('Steam').and_yield
expect(p).to receive(:action).with(:remove)
p.send(:remove!)
end
end

describe '#install_package' do
before(:each) do
allow_any_instance_of(described_class).to receive(:download_path)
.and_return('/tmp/SteamSetup.exe')
end

it 'uses a windows_package to install the package' do
p = provider
expect(p).to receive(:windows_package).with('Steam').and_yield
expect(p).to receive(:source).with('/tmp/SteamSetup.exe')
expect(p).to receive(:installer_type).with(:nsis)
expect(p).to receive(:action).with(:install)
p.send(:install_package)
end
end

describe '#download_package' do
before(:each) do
allow_any_instance_of(described_class).to receive(:download_path)
.and_return('/tmp/SteamSetup.exe')
end

it 'uses a remote_file to download the package' do
p = provider
expect(p).to receive(:remote_file).with('/tmp/SteamSetup.exe').and_yield
expect(p).to receive(:source).with(described_class::URL)
expect(p).to receive(:action).with(:create)
expect(p).to receive(:only_if).and_yield
expect(File).to receive(:exist?).with(described_class::PATH)
p.send(:download_package)
end
end

describe '#download_path' do
it 'returns a path under the Chef cache dir' do
expected = "#{Chef::Config[:file_cache_path]}/SteamSetup.exe"
expect(provider.send(:download_path)).to eq(expected)
end
end
end
28 changes: 3 additions & 25 deletions spec/spec_helper.rb
Expand Up @@ -2,7 +2,6 @@

require 'chef'
require 'chefspec'
require 'json'
require 'tempfile'
require 'simplecov'
require 'simplecov-console'
Expand All @@ -19,29 +18,8 @@
metadata.from_file(File.expand_path('../../metadata.rb', __FILE__))
link_path = File.join(COOKBOOK_PATH, metadata.name)
FileUtils.ln_s(File.expand_path('../..', __FILE__), link_path)
c.cookbook_path = COOKBOOK_PATH
end

c.before(:each) do
# Don't worry about external cookbook dependencies
allow_any_instance_of(Chef::Cookbook::Metadata).to receive(:depends)

# Prep lookup() for the stubs below
allow_any_instance_of(Chef::ResourceCollection).to receive(:lookup)
.and_call_original

# Test each recipe in isolation, regardless of includes
@included_recipes = []
allow_any_instance_of(Chef::RunContext).to receive(:loaded_recipe?)
.and_return(false)
allow_any_instance_of(Chef::Recipe).to receive(:include_recipe) do |_, i|
allow_any_instance_of(Chef::RunContext).to receive(:loaded_recipe?)
.with(i)
.and_return(true)
@included_recipes << i
end
allow_any_instance_of(Chef::RunContext).to receive(:loaded_recipes)
.and_return(@included_recipes)
c.cookbook_path = [COOKBOOK_PATH,
File.expand_path('../support/cookbooks', __FILE__)]
end

c.after(:suite) { FileUtils.rm_r(COOKBOOK_PATH) }
Expand All @@ -52,7 +30,7 @@
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::Console
]
SimpleCov.minimum_coverage 90
SimpleCov.minimum_coverage(100)
SimpleCov.start

at_exit { ChefSpec::Coverage.report! }
11 changes: 11 additions & 0 deletions spec/support/cookbooks/apt/metadata.rb
@@ -0,0 +1,11 @@
# Encoding: UTF-8
#
# rubocop:disable SingleSpaceBeforeFirstArg
name 'apt'
maintainer 'test'
maintainer_email 'example@example.com'
license 'apache2'
description 'apt'
long_description 'apt'
version '0.0.1'
# rubocop:enable SingleSpaceBeforeFirstArg
11 changes: 11 additions & 0 deletions spec/support/cookbooks/dmg/metadata.rb
@@ -0,0 +1,11 @@
# Encoding: UTF-8
#
# rubocop:disable SingleSpaceBeforeFirstArg
name 'dmg'
maintainer 'test'
maintainer_email 'example@example.com'
license 'apache2'
description 'dmg'
long_description 'dmg'
version '0.0.1'
# rubocop:enable SingleSpaceBeforeFirstArg
11 changes: 11 additions & 0 deletions spec/support/cookbooks/windows/metadata.rb
@@ -0,0 +1,11 @@
# Encoding: UTF-8
#
# rubocop:disable SingleSpaceBeforeFirstArg
name 'windows'
maintainer 'test'
maintainer_email 'example@example.com'
license 'apache2'
description 'windows'
long_description 'windows'
version '0.0.1'
# rubocop:enable SingleSpaceBeforeFirstArg
6 changes: 6 additions & 0 deletions test/integration/default/serverspec/localhost/app_spec.rb
Expand Up @@ -8,4 +8,10 @@
expect(subject).to be_directory
end
end

describe package('Steam'), if: os[:family] == 'windows' do
it 'is installed' do
expect(subject).to be_installed
end
end
end
6 changes: 6 additions & 0 deletions test/integration/uninstall/serverspec/localhost/app_spec.rb
Expand Up @@ -8,4 +8,10 @@
expect(subject).not_to be_directory
end
end

describe package('Steam'), if: os[:family] == 'windows' do
it 'is not installed' do
expect(subject).to be_installed
end
end
end

0 comments on commit 0f6f2f5

Please sign in to comment.