Skip to content

Commit

Permalink
Merge 8a66e98 into 7931d36
Browse files Browse the repository at this point in the history
  • Loading branch information
hartmantis committed Jun 17, 2015
2 parents 7931d36 + 8a66e98 commit 4104bae
Show file tree
Hide file tree
Showing 12 changed files with 227 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ A Chef cookbook for VLC.
Requirements
============

This cookbook currently supports OS X only and uses the `dmg` cookbook to
implement that support.
This cookbook currently supports OS X and Windows only. It uses the `dmg` and
`windows` community cookbooks for that support.

Usage
=====
Expand Down Expand Up @@ -64,6 +64,10 @@ Providers

Provider for Mac OS X platforms.

***Chef::Provider::VlcApp::Windows***

Provider for Windows platforms.

***Chef::Provider::VlcApp***

A parent provider for all the platform-specific providers to subclass.
Expand Down
3 changes: 3 additions & 0 deletions libraries/provider_mapping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@
Chef::Platform.set(platform: :mac_os_x,
resource: :vlc_app,
provider: Chef::Provider::VlcApp::MacOsX)
Chef::Platform.set(platform: :windows,
resource: :vlc_app,
provider: Chef::Provider::VlcApp::Windows)
1 change: 1 addition & 0 deletions libraries/provider_vlc_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
require 'chef/provider/lwrp_base'
require_relative 'resource_vlc_app'
require_relative 'provider_vlc_app_mac_os_x'
require_relative 'provider_vlc_app_windows'

class Chef
class Provider
Expand Down
91 changes: 91 additions & 0 deletions libraries/provider_vlc_app_windows.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Encoding: UTF-8
#
# Cookbook Name:: vlc
# Library:: provider_vlc_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_vlc_app'

class Chef
class Provider
class VlcApp < Provider::LWRPBase
# An provider for VLC for Windows.
#
# @author Jonathan Hartman <j@p4nt5.com>
class Windows < VlcApp
URL ||= 'http://get.videolan.org/vlc/2.2.1/win64/vlc-2.2.1-win64.exe'
PATH ||= ::File.expand_path('/Program Files/VideoLAN/VLC')

private

#
# Download and then install the VLC package.
#
# (see VlcApp#install!)
#
def install!
download_package
install_package
end

#
# Use a windows_package resource to uninstall VLC.
#
# (see VlcApp#remove!)
#
def remove!
windows_package 'VLC media player' do
action :remove
end
end

#
# Use a windows_package resource to install the downloaded package.
#
def install_package
s = download_path
windows_package 'VLC media player' do
source s
installer_type :nsis
action :install
end
end

#
# Use a remote_file resource to download the package.
#
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
maintainer 'Jonathan Hartman'
maintainer_email 'j@p4nt5.com'
license 'apache2'
description 'Installs/Configures vlc'
long_description 'Installs/Configures vlc'
description 'Installs VLC'
long_description 'Installs VLC'
version '0.0.1'

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

supports 'mac_os_x'
supports 'windows'
# rubocop:enable SingleSpaceBeforeFirstArg
4 changes: 2 additions & 2 deletions spec/libraries/provider_mapping_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
context 'Windows' do
let(:platform) { :windows }

it 'returns nil' do
expect(app_provider).to eq(nil)
it 'uses the Windows app provider' do
expect(app_provider).to eq(Chef::Provider::VlcApp::Windows)
end
end

Expand Down
93 changes: 93 additions & 0 deletions spec/libraries/provider_vlc_app_windows_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Encoding: UTF-8

require_relative '../spec_helper'
require_relative '../../libraries/provider_vlc_app_windows'

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

describe 'URL' do
it 'returns the download page URL' do
expected = 'http://get.videolan.org/vlc/2.2.1/win64/vlc-2.2.1-win64.exe'
expect(described_class::URL).to eq(expected)
end
end

describe 'PATH' do
it 'returns the app directory' do
expected = File.expand_path('/Program Files/VideoLAN/VLC')
expect(described_class::PATH).to eq(expected)
end
end

describe '#install!' do
before(:each) do
[:download_package, :install_package].each do |m|
allow_any_instance_of(described_class).to receive(m)
end
end

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

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

describe '#remove!' do
it 'uses a windows_package to uninstall VLC' do
p = provider
expect(p).to receive(:windows_package).with('VLC media player').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/vlc.exe')
end

it 'uses a windows_package to install the package' do
p = provider
expect(p).to receive(:windows_package).with('VLC media player').and_yield
expect(p).to receive(:source).with('/tmp/vlc.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/vlc.exe')
end

it 'uses a remote_file to download the package' do
p = provider
expect(p).to receive(:remote_file).with('/tmp/vlc.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 in the Chef cache dir' do
expected = "#{Chef::Config[:file_cache_path]}/vlc-2.2.1-win64.exe"
expect(provider.send(:download_path)).to eq(expected)
end
end
end
11 changes: 11 additions & 0 deletions spec/support/cookbooks/windows/metadata.rb
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@
expect(subject).to be_directory
end
end

describe package('VLC media player'), 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
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@
expect(subject).not_to be_directory
end
end

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

0 comments on commit 4104bae

Please sign in to comment.