Skip to content

Commit

Permalink
Update package resource
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandoaleman committed Aug 5, 2019
1 parent af000f8 commit 24507ec
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 37 deletions.
70 changes: 70 additions & 0 deletions 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.
22 changes: 7 additions & 15 deletions 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

Expand Down
32 changes: 12 additions & 20 deletions 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
4 changes: 2 additions & 2 deletions test/integration/package/package_test.rb
Expand Up @@ -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

0 comments on commit 24507ec

Please sign in to comment.