Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow exact Ruby package versions to be specified and held #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ driver:

provisioner:
name: chef_solo
require_chef_omnibus: 12
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a limitation of minitest-chef-handler, not this code.


platforms:
- name: ubuntu-12.04
- name: ubuntu-14.04
driver:
name: vagrant
driver_config:
gui: true

suites:
- name: testkitchen_ruby_ng_cookbook
- name: testkitchen_ruby_ng_cookbook_default_versions
run_list:
- recipe[ruby-ng_test]
- recipe[minitest-handler]
Expand All @@ -22,8 +27,19 @@ suites:
recipes:
- ruby-ng_test::default
ruby-ng:
ruby_version: 2.1
# 1.9.8 is the newest version as of 05/13/2015, but we are testing if we can install
# a specific older version.
bundler_version: 1.9.7

ruby_version: 2.3
- name: testkitchen_ruby_ng_cookbook_specific_versions
run_list:
- recipe[ruby-ng_test]
- recipe[minitest-handler]
attributes:
minitest:
recipes:
- ruby-ng_test::specific_versions
ruby-ng:
ruby_version: 2.3
ruby_package_version: "2.3.5-1bbox2~trusty1"
hold_ruby_packages: true
# 1.15.4 is the newest table version as of 09/21/2017, but we are testing
# if we can install a specific older version.
bundler_version: 1.15.3
8 changes: 8 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@
# the existing (potentially outdated) version of Bundler is kept.
default['ruby-ng']['bundler_version'] = 'latest'

# Likewise for the ruby packages themselves. However, this setting
# defaults to keeping the first version installed.
default['ruby-ng']['ruby_package_version'] = nil

# Whether to hold the ruby package(s) after installation. Holding
# prevents the packages from being upgraded externally, e.g.
# when running apt-get update at the CLI.
default['ruby-ng']['hold_ruby_packages'] = false
2 changes: 1 addition & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
license 'MIT'
description 'Installs Ruby from brightbox/ruby-ng PPA'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '0.3.0'
version '0.4.0'

supports 'ubuntu'

Expand Down
17 changes: 16 additions & 1 deletion recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,22 @@
pin_priority '666'
end

package "ruby#{node['ruby-ng']['ruby_version']}"
v = node['ruby-ng']['ruby_version']

execute "hold ruby#{v} package" do
command "apt-mark hold ruby#{v}"
action :nothing
end

package "ruby#{v}" do
if node['ruby-ng']['ruby_package_version']
version node['ruby-ng']['ruby_package_version']
end

if node['ruby-ng']['hold_ruby_packages']
notifies :run, "execute[hold ruby#{v} package]", :immediate
end
end

bundler_version = node['ruby-ng']['bundler_version']

Expand Down
17 changes: 16 additions & 1 deletion recipes/dev.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
include_recipe 'build-essential'
include_recipe 'ruby-ng::default'

package "ruby#{node['ruby-ng']['ruby_version']}-dev"
v = node['ruby-ng']['ruby_version']

execute "hold ruby#{v}-dev package" do
command "apt-mark hold ruby#{v}-dev"
action :nothing
end

package "ruby#{v}-dev" do
if node['ruby-ng']['ruby_package_version']
version node['ruby-ng']['ruby_package_version']
end

if node['ruby-ng']['hold_ruby_packages']
notifies :run, "execute[hold ruby#{v}-dev package]", :immediate
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,8 @@
package("ruby#{node['ruby-ng']['ruby_version']}").must_be_installed
end

# This test requires that node['ruby-ng']['bundler_version'] is set to a specific value, not to
# "latest".
it 'Installs the correct version of the bundler gem' do
cmd = 'gem list bundler'
gem_list_bundler_output = shell_out!(cmd).stdout
bundler_version = node['ruby-ng']['bundler_version']
assert(
gem_list_bundler_output.include?("bundler (#{bundler_version})"),
"Expected bundler version #{bundler_version} " \
"to be the only version reported in the results of command '#{cmd}'")
it 'Installs the bundler gem' do
shell_out!('gem list bundler').stdout.must_match(/bundler \(/)
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require_relative 'helpers'

describe_recipe "ruby-ng::default" do
include Helpers::RubyNgTests

it 'Installs the ruby<version> package' do
package("ruby#{node['ruby-ng']['ruby_version']}").must_be_installed.with(:version, [node['ruby-ng']['ruby_package_version']])
end

it 'holds the ruby<version>-dev package' do
shell_out!('apt-mark showhold').stdout.must_match("ruby#{node['ruby-ng']['ruby_version']}-dev")
end

# This test requires that node['ruby-ng']['bundler_version'] is set to a specific value, not to
# "latest".
it 'Installs the correct version of the bundler gem' do
cmd = 'gem list bundler'
gem_list_bundler_output = shell_out!(cmd).stdout
bundler_version = node['ruby-ng']['bundler_version']
assert(
gem_list_bundler_output.include?("bundler (#{bundler_version})"),
"Expected bundler version #{bundler_version} " \
"to be the only version reported in the results of command '#{cmd}'")
end
end

describe_recipe "ruby-ng::dev" do
include Helpers::RubyNgTests

it 'Installs the ruby<version>-dev package' do
package("ruby#{node['ruby-ng']['ruby_version']}-dev").must_be_installed.with(:version, [node['ruby-ng']['ruby_package_version']])
end

it 'holds the ruby<version>-dev package' do
shell_out!('apt-mark showhold').stdout.must_match("ruby#{node['ruby-ng']['ruby_version']}-dev")
end

it 'Installs the build-essential package' do
package('build-essential').must_be_installed
end
end