-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
227 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters