Skip to content

Commit

Permalink
Merge 819ebb3 into 9ca6276
Browse files Browse the repository at this point in the history
  • Loading branch information
hartmantis committed Jun 22, 2015
2 parents 9ca6276 + 819ebb3 commit be2c79f
Show file tree
Hide file tree
Showing 17 changed files with 271 additions and 26 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Vlc Cookbook CHANGELOG

v?.?.? (????-??-??)
-------------------
- Give the `vlc_app` resource an optional `version` attribute
- Fix bug with OS X package's mount volume name

v0.2.0 (2015-06-21)
-------------------
Expand Down
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ Recipes

Installs VLC.

Attributes
==========

***default***

A specific version of VLC can be installed if you so desire:

default['vlc']['version'] = nil

Resources
=========

Expand All @@ -41,6 +50,7 @@ Used to install the VLC app.
Syntax:

vlc_app 'default' do
version '1.2.3'
action :install
end

Expand All @@ -53,9 +63,10 @@ Actions:

Attributes:

| Attribute | Default | Description |
|------------|------------|----------------------|
| action | `:install` | Action(s) to perform |
| Attribute | Default | Description |
|------------|------------|-------------------------------|
| version | `nil` | A specific version to install |
| action | `:install` | Action(s) to perform |

Providers
=========
Expand Down
21 changes: 21 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Encoding: UTF-8
#
# Cookbook Name:: vlc
# Attributes:: default
#
# 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.
#

default['vlc']['version'] = nil
11 changes: 11 additions & 0 deletions libraries/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,16 @@ def vlc_site_body
Net::HTTP.start(u.host, u.port, opts) { |h| h.get(u) }.body
end
end

#
# Determine whether a given string is a valid version.
#
# @param arg [String] a potential version string
#
# @return [TrueClass, FalseClass] whether the string is valid
#
def self.valid_version?(arg)
arg.match(/^[0-9]+\.[0-9]+\.[0-9]+$/) ? true : false
end
end
end
1 change: 1 addition & 0 deletions libraries/provider_vlc_app_debian.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Debian < VlcApp
def install!
include_recipe 'apt'
package 'vlc' do
version new_resource.version
action :install
end
end
Expand Down
1 change: 1 addition & 0 deletions libraries/provider_vlc_app_freebsd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Freebsd < VlcApp
def install!
include_recipe 'freebsd::portsnap'
package 'vlc' do
version new_resource.version
action :install
end
end
Expand Down
14 changes: 11 additions & 3 deletions libraries/provider_vlc_app_mac_os_x.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def install!
s = remote_path
dmg_package 'VLC' do
source s
volumes_dir 'vlc-2.2.1'
volumes_dir "vlc-#{version}"
action :install
end
end
Expand Down Expand Up @@ -75,8 +75,16 @@ def remove!
# @return [String] a download URL
#
def remote_path
"https://get.videolan.org/vlc/#{latest_version}/macosx/" \
"vlc-#{latest_version}.dmg"
"https://get.videolan.org/vlc/#{version}/macosx/vlc-#{version}.dmg"
end

#
# Return either the new_resource's version or get the latest one.
#
# @return [String] a version string for this provider to use
#
def version
new_resource.version || latest_version
end
end
end
Expand Down
13 changes: 11 additions & 2 deletions libraries/provider_vlc_app_windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,17 @@ def download_path
# @return [String] a download URL
#
def remote_path
"https://get.videolan.org/vlc/#{latest_version}/win64/" \
"vlc-#{latest_version}-win64.exe"
"https://get.videolan.org/vlc/#{version}/win64/vlc-#{version}-" \
'win64.exe'
end

#
# Return either the new_resource's version or get the latest one.
#
# @return [String] a version string for this provider to use
#
def version
new_resource.version || latest_version
end
end
end
Expand Down
11 changes: 11 additions & 0 deletions libraries/resource_vlc_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#

require 'chef/resource/lwrp_base'
require_relative 'helpers'

class Chef
class Resource
Expand All @@ -37,6 +38,16 @@ class VlcApp < Resource::LWRPBase
kind_of: [NilClass, TrueClass, FalseClass],
default: nil
alias_method :installed?, :installed

#
# Allow a user to install a specific version of VLC.
#
attribute :version,
kind_of: [NilClass, String],
default: nil,
callbacks: {
'Invalid version' => ->(a) { Vlc::Helpers.valid_version?(a) }
}
end
end
end
1 change: 1 addition & 0 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
#

vlc_app 'default' do
version node['vlc']['version']
action :install
end
29 changes: 29 additions & 0 deletions spec/libraries/helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,33 @@
expect(test_obj.vlc_site_body).to eq(body)
end
end

describe '#valid_version?' do
let(:version) { nil }
let(:res) { described_class.valid_version?(version) }

context 'a valid version string' do
let(:version) { '1.2.3' }

it 'returns true' do
expect(res).to eq(true)
end
end

context 'an invalid version string' do
let(:version) { 'x.y.z' }

it 'returns false' do
expect(res).to eq(false)
end
end

context 'a .beta version string' do
let(:version) { '1.2.3.beta.1' }

it 'returns false' do
expect(res).to eq(false)
end
end
end
end
32 changes: 26 additions & 6 deletions spec/libraries/provider_vlc_app_debian_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,32 @@
let(:provider) { described_class.new(new_resource, nil) }

describe '#install!' do
it 'uses an package to install VLC' do
p = provider
expect(p).to receive(:include_recipe).with('apt')
expect(p).to receive(:package).with('vlc').and_yield
expect(p).to receive(:action).with(:install)
p.send(:install!)
context 'default resource attributes' do
it 'uses an package to install VLC' do
p = provider
expect(p).to receive(:include_recipe).with('apt')
expect(p).to receive(:package).with('vlc').and_yield
expect(p).to receive(:version).with(nil)
expect(p).to receive(:action).with(:install)
p.send(:install!)
end
end

context 'a resource version attribute' do
let(:new_resource) do
r = super()
r.version('1.2.3')
r
end

it 'installs a specific version of VLC' do
p = provider
expect(p).to receive(:include_recipe).with('apt')
expect(p).to receive(:package).with('vlc').and_yield
expect(p).to receive(:version).with('1.2.3')
expect(p).to receive(:action).with(:install)
p.send(:install!)
end
end
end

Expand Down
32 changes: 26 additions & 6 deletions spec/libraries/provider_vlc_app_freebsd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,32 @@
let(:provider) { described_class.new(new_resource, nil) }

describe '#install!' do
it 'installs the VLC package' do
p = provider
expect(p).to receive(:include_recipe).with('freebsd::portsnap')
expect(p).to receive(:package).with('vlc').and_yield
expect(p).to receive(:action).with(:install)
p.send(:install!)
context 'default resource attributes' do
it 'installs the VLC package' do
p = provider
expect(p).to receive(:include_recipe).with('freebsd::portsnap')
expect(p).to receive(:package).with('vlc').and_yield
expect(p).to receive(:version).with(nil)
expect(p).to receive(:action).with(:install)
p.send(:install!)
end
end

context 'a resource version attribute' do
let(:new_resource) do
r = super()
r.version('1.2.3')
r
end

it 'installs a specific version of VLC' do
p = provider
expect(p).to receive(:include_recipe).with('freebsd::portsnap')
expect(p).to receive(:package).with('vlc').and_yield
expect(p).to receive(:version).with('1.2.3')
expect(p).to receive(:action).with(:install)
p.send(:install!)
end
end
end

Expand Down
31 changes: 29 additions & 2 deletions spec/libraries/provider_vlc_app_mac_os_x_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
before(:each) do
allow_any_instance_of(described_class).to receive(:remote_path)
.and_return('https://example.com/vlc.dmg')
allow_any_instance_of(described_class).to receive(:version)
.and_return('1.2.3')
end

it 'uses a dmg_package to install VLC' do
p = provider
expect(p).to receive(:dmg_package).with('VLC').and_yield
expect(p).to receive(:source).with('https://example.com/vlc.dmg')
expect(p).to receive(:volumes_dir).with('vlc-2.2.1')
expect(p).to receive(:volumes_dir).with('vlc-1.2.3')
expect(p).to receive(:action).with(:install)
p.send(:install!)
end
Expand All @@ -49,7 +51,7 @@

describe '#remote_path' do
before(:each) do
allow_any_instance_of(described_class).to receive(:latest_version)
allow_any_instance_of(described_class).to receive(:version)
.and_return('1.2.3')
end

Expand All @@ -58,4 +60,29 @@
expect(provider.send(:remote_path)).to eq(expected)
end
end

describe '#version' do
before(:each) do
allow_any_instance_of(described_class).to receive(:latest_version)
.and_return('2.3.4')
end

context 'no resource version override' do
it 'returns the latest version' do
expect(provider.send(:version)).to eq('2.3.4')
end
end

context 'a resource version override' do
let(:new_resource) do
r = super()
r.version('1.2.3')
r
end

it 'returns the overridden version' do
expect(provider.send(:version)).to eq('1.2.3')
end
end
end
end
27 changes: 26 additions & 1 deletion spec/libraries/provider_vlc_app_windows_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@

describe '#remote_path' do
before(:each) do
allow_any_instance_of(described_class).to receive(:latest_version)
allow_any_instance_of(described_class).to receive(:version)
.and_return('1.2.3')
end

Expand All @@ -102,4 +102,29 @@
expect(provider.send(:remote_path)).to eq(expected)
end
end

describe '#version' do
before(:each) do
allow_any_instance_of(described_class).to receive(:latest_version)
.and_return('2.3.4')
end

context 'no resource version override' do
it 'returns the latest version' do
expect(provider.send(:version)).to eq('2.3.4')
end
end

context 'a resource version override' do
let(:new_resource) do
r = super()
r.version('1.2.3')
r
end

it 'returns the overridden version' do
expect(provider.send(:version)).to eq('1.2.3')
end
end
end
end

0 comments on commit be2c79f

Please sign in to comment.