From 24507ec9d1e3836eb4226e418e692f267572fbbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Alem=C3=A1n?= Date: Mon, 5 Aug 2019 10:36:43 -0500 Subject: [PATCH] Update package resource --- documentation/resources/package.md | 70 ++++++++++++++++++++++++ resources/package.rb | 22 +++----- spec/unit/resources/package_spec.rb | 32 ++++------- test/integration/package/package_test.rb | 4 +- 4 files changed, 91 insertions(+), 37 deletions(-) create mode 100644 documentation/resources/package.md diff --git a/documentation/resources/package.md b/documentation/resources/package.md new file mode 100644 index 0000000..f5b652a --- /dev/null +++ b/documentation/resources/package.md @@ -0,0 +1,70 @@ +# asdf_package + +Installs, uninstalls and sets global an asdf package. +**See [Package Dependencies](#package-dependencies) below.** + +```ruby +asdf_package 'name' do + package String + version String + live_stream [true, false] + user String +end +``` + +## Actions + +| Action | Default | +| ------------ | -------- | +| `:install` | ✓ | +| `:global` | | +| `:uninstall` | | + +## Properties + +### `package` + +Which package to install. + +| property | value | +| ------------- | ---------- | +| Type | String | +| Default | `name` | +| Name Property | `true` | + +### `version` + +Which package version to install. + +| property | value | +| -------- | ------ | +| Type | String | +| Default | | +| Required | `true` | + +### `live_stream` + +Whether or not to output verbose stream. + +| property | value | +| -------- | ------------- | +| Type | [true, false] | +| Default | `true` | + +### `user` + +Which user to run asdf code as. + +| property | value | +| -------- | ------ | +| Type | String | +| Default | | + +## Package Dependencies + +Although this cookbook is slowly but surely trying to make sure that +dependencies are installed for each package on all supported operating systems, +you may still need to add dependencies that have not been pre-installed for a +particular package. If you do indeed get a package installed with dependencies +that have not yet been pre-installed via this cookbook, please open up a pull +request for review to be added. diff --git a/resources/package.rb b/resources/package.rb index 22d8378..b2dd2af 100644 --- a/resources/package.rb +++ b/resources/package.rb @@ -1,26 +1,18 @@ -# -# Cookbook:: asdf -# Resource:: package -# -# Copyright:: 2017-2018, Fernando Aleman, All Rights Reserved. - -provides :asdf_package - -property :live_stream, [true, false], - default: true, - description: 'Whether or not to output verbose stream.' - property :package, String, description: 'Which package to install.', name_property: true -property :user, String, - description: 'Which user to run asdf code as.' - property :version, String, description: 'Which package version to install.', required: true +property :live_stream, [true, false], + description: 'Whether or not to output verbose stream.', + default: true + +property :user, String, + description: 'Which user to run asdf code as.' + action :install do install_package_deps diff --git a/spec/unit/resources/package_spec.rb b/spec/unit/resources/package_spec.rb index 05806a6..0d8e765 100644 --- a/spec/unit/resources/package_spec.rb +++ b/spec/unit/resources/package_spec.rb @@ -1,27 +1,19 @@ -# -# Cookbook:: asdf -# Spec:: package -# -# Copyright:: 2018, Fernando Aleman, All Rights Reserved. - require 'spec_helper' -describe 'test::package' do - SUPPORTED_PLATFORMS.each do |platform, versions| - versions.each do |version| - context "Using #{platform} #{version}" do - let(:chef_run) do - runner = ChefSpec::ServerRunner.new(platform: platform, version: version) - runner.converge(described_recipe) - end +describe 'asdf_package' do + step_into :asdf_package + platform 'ubuntu' - it 'installs ruby package' do - expect(chef_run).to install_asdf_package('ruby').with( - version: '2.5.1', - action: [:install, :global] - ) - end + context 'with default properties' do + recipe do + asdf_package 'ruby' do + version '2.6.3' end end + + it do + is_expected.to run_asdf_script('install ruby 2.6.3') + .with_live_stream(true) + end end end diff --git a/test/integration/package/package_test.rb b/test/integration/package/package_test.rb index 743e72a..79fdd13 100644 --- a/test/integration/package/package_test.rb +++ b/test/integration/package/package_test.rb @@ -3,10 +3,10 @@ # Inspec test for test::package describe bash('sudo -H -u vagrant bash -c "source /etc/profile.d/asdf.sh && asdf list ruby"') do - its('stdout') { should include('2.5.1') } + its('stdout') { should include('2.6.3') } its('exit_status') { should eq 0 } end describe file('/home/vagrant/.tool-versions') do - its('content') { should include('ruby 2.5.1') } + its('content') { should include('ruby 2.6.3') } end