berkshelf 2.0.18 → 3.0.0.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.ruby-version +1 -1
- data/.travis.yml +4 -1
- data/CHANGELOG.md +2 -26
- data/Gemfile +12 -2
- data/README.md +9 -1
- data/berkshelf.gemspec +9 -18
- data/bin/berks +3 -13
- data/features/apply_command.feature +11 -9
- data/features/berksfile.feature +8 -10
- data/features/config.feature +1 -2
- data/features/configure_command.feature +13 -14
- data/features/contingent_command.feature +13 -1
- data/features/cookbook_command.feature +2 -4
- data/features/groups_install.feature +10 -2
- data/features/help.feature +1 -1
- data/features/init_command.feature +5 -7
- data/features/install_command.feature +157 -228
- data/features/json_formatter.feature +27 -15
- data/features/licenses.feature +18 -12
- data/features/list_command.feature +6 -1
- data/features/lockfile.feature +116 -72
- data/features/outdated_command.feature +3 -47
- data/features/package_command.feature +10 -7
- data/features/shelf/show.feature +2 -2
- data/features/shelf/uninstall.feature +2 -2
- data/features/show_command.feature +10 -3
- data/features/step_definitions/chef/config_steps.rb +12 -0
- data/features/step_definitions/chef_server_steps.rb +16 -16
- data/features/step_definitions/cli_steps.rb +3 -79
- data/features/step_definitions/config_steps.rb +43 -0
- data/features/step_definitions/environment_steps.rb +7 -0
- data/features/step_definitions/filesystem_steps.rb +12 -57
- data/features/step_definitions/gem_steps.rb +1 -2
- data/features/step_definitions/json_steps.rb +3 -1
- data/features/step_definitions/lockfile_steps.rb +4 -0
- data/features/step_definitions/utility_steps.rb +0 -19
- data/features/support/aruba.rb +12 -0
- data/features/support/env.rb +52 -57
- data/features/update_command.feature +37 -23
- data/features/upload_command.feature +96 -160
- data/generator_files/Berksfile.erb +2 -1
- data/generator_files/Vagrantfile.erb +3 -0
- data/generator_files/default_test.rb.erb +1 -1
- data/generator_files/helpers.rb.erb +1 -1
- data/lib/berkshelf.rb +43 -24
- data/lib/berkshelf/api_client.rb +67 -0
- data/lib/berkshelf/api_client/remote_cookbook.rb +42 -0
- data/lib/berkshelf/berksfile.rb +232 -420
- data/lib/berkshelf/cached_cookbook.rb +22 -10
- data/lib/berkshelf/chef/config.rb +1 -0
- data/lib/berkshelf/cli.rb +66 -68
- data/lib/berkshelf/commands/shelf.rb +1 -1
- data/lib/berkshelf/community_rest.rb +10 -17
- data/lib/berkshelf/config.rb +23 -27
- data/lib/berkshelf/cookbook_generator.rb +3 -4
- data/lib/berkshelf/cookbook_store.rb +74 -17
- data/lib/berkshelf/core_ext/file.rb +2 -2
- data/lib/berkshelf/core_ext/pathname.rb +7 -5
- data/lib/berkshelf/{cookbook_source.rb → dependency.rb} +47 -67
- data/lib/berkshelf/downloader.rb +49 -106
- data/lib/berkshelf/errors.rb +64 -71
- data/lib/berkshelf/formatters.rb +11 -9
- data/lib/berkshelf/formatters/human_readable.rb +9 -9
- data/lib/berkshelf/formatters/json.rb +14 -4
- data/lib/berkshelf/init_generator.rb +3 -3
- data/lib/berkshelf/installer.rb +136 -0
- data/lib/berkshelf/location.rb +91 -131
- data/lib/berkshelf/locations/git_location.rb +9 -11
- data/lib/berkshelf/locations/github_location.rb +1 -1
- data/lib/berkshelf/locations/path_location.rb +10 -27
- data/lib/berkshelf/lockfile.rb +92 -70
- data/lib/berkshelf/logger.rb +4 -7
- data/lib/berkshelf/mixin/config.rb +21 -4
- data/lib/berkshelf/resolver.rb +60 -150
- data/lib/berkshelf/resolver/graph.rb +44 -0
- data/lib/berkshelf/source.rb +55 -0
- data/lib/berkshelf/source_uri.rb +38 -0
- data/lib/berkshelf/version.rb +1 -1
- data/spec/config/knife.rb +1 -1
- data/spec/fixtures/cassettes/Berkshelf_Resolver/_initialize/adds_the_dependencies_of_the_dependency_as_dependencies.yml +3694 -0
- data/spec/fixtures/cookbooks/example_cookbook/Berksfile.lock +1 -1
- data/spec/fixtures/lockfiles/default.lock +1 -1
- data/spec/spec_helper.rb +20 -121
- data/spec/support/chef_api.rb +3 -4
- data/spec/support/chef_server.rb +20 -11
- data/spec/support/git.rb +127 -0
- data/spec/support/kitchen.rb +12 -0
- data/spec/support/path_helpers.rb +69 -0
- data/spec/unit/berkshelf/api_client/remote_cookbook_spec.rb +23 -0
- data/spec/unit/berkshelf/api_client_spec.rb +57 -0
- data/spec/unit/berkshelf/berksfile_spec.rb +206 -324
- data/spec/unit/berkshelf/cached_cookbook_spec.rb +73 -38
- data/spec/unit/berkshelf/community_rest_spec.rb +30 -71
- data/spec/unit/berkshelf/config_spec.rb +3 -14
- data/spec/unit/berkshelf/cookbook_generator_spec.rb +1 -2
- data/spec/unit/berkshelf/cookbook_store_spec.rb +12 -7
- data/spec/unit/berkshelf/dependency_spec.rb +285 -0
- data/spec/unit/berkshelf/downloader_spec.rb +4 -183
- data/spec/unit/berkshelf/formatters/null_spec.rb +1 -1
- data/spec/unit/berkshelf/formatters_spec.rb +4 -2
- data/spec/unit/berkshelf/git_spec.rb +15 -15
- data/spec/unit/berkshelf/installer_spec.rb +39 -0
- data/spec/unit/berkshelf/location_spec.rb +87 -114
- data/spec/unit/berkshelf/locations/git_location_spec.rb +41 -53
- data/spec/unit/berkshelf/locations/path_location_spec.rb +13 -23
- data/spec/unit/berkshelf/lockfile_spec.rb +38 -40
- data/spec/unit/berkshelf/resolver/graph_spec.rb +44 -0
- data/spec/unit/berkshelf/resolver_spec.rb +34 -83
- data/spec/unit/berkshelf/source_spec.rb +23 -0
- data/spec/unit/berkshelf/source_uri_spec.rb +29 -0
- metadata +149 -188
- checksums.yaml +0 -7
- data/features/default_locations.feature +0 -127
- data/features/step_definitions/berksfile_steps.rb +0 -8
- data/features/step_definitions/configure_cli_steps.rb +0 -19
- data/features/vendor_install.feature +0 -19
- data/lib/berkshelf/core_ext/openuri.rb +0 -36
- data/lib/berkshelf/core_ext/rbzip2.rb +0 -8
- data/lib/berkshelf/locations/chef_api_location.rb +0 -228
- data/lib/berkshelf/locations/site_location.rb +0 -92
- data/lib/berkshelf/test.rb +0 -35
- data/spec/knife.rb.sample +0 -12
- data/spec/support/test_generators.rb +0 -27
- data/spec/unit/berkshelf/cli_spec.rb +0 -16
- data/spec/unit/berkshelf/cookbook_source_spec.rb +0 -358
- data/spec/unit/berkshelf/core_ext/pathname_spec.rb +0 -46
- data/spec/unit/berkshelf/locations/chef_api_location_spec.rb +0 -139
- data/spec/unit/berkshelf/locations/site_location_spec.rb +0 -19
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
module Berkshelf
|
|
2
|
-
class SiteLocation
|
|
3
|
-
extend Forwardable
|
|
4
|
-
include Location
|
|
5
|
-
|
|
6
|
-
set_location_key :site
|
|
7
|
-
|
|
8
|
-
def_delegator :conn, :api_uri
|
|
9
|
-
attr_accessor :version_constraint
|
|
10
|
-
|
|
11
|
-
SHORTNAMES = {opscode: CommunityREST::V1_API}.freeze
|
|
12
|
-
|
|
13
|
-
# @param [#to_s] name
|
|
14
|
-
# @param [Solve::Constraint] version_constraint
|
|
15
|
-
# @param [Hash] options
|
|
16
|
-
#
|
|
17
|
-
# @option options [String, Symbol] :site
|
|
18
|
-
# a URL pointing to a community API endpoint. Alternatively the symbol :opscode can
|
|
19
|
-
# be provided to initialize a SiteLocation pointing to the Opscode Community Site.
|
|
20
|
-
def initialize(name, version_constraint, options = {})
|
|
21
|
-
@name = name
|
|
22
|
-
@version_constraint = version_constraint
|
|
23
|
-
|
|
24
|
-
api_uri = if options[:site].nil?
|
|
25
|
-
SHORTNAMES[:opscode]
|
|
26
|
-
elsif SHORTNAMES.has_key?(options[:site])
|
|
27
|
-
SHORTNAMES[options[:site]]
|
|
28
|
-
elsif options[:site].kind_of?(Symbol)
|
|
29
|
-
raise InvalidSiteShortnameError.new(options[:site])
|
|
30
|
-
else
|
|
31
|
-
options[:site]
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
@conn = Berkshelf::CommunityREST.new(api_uri)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
# @param [#to_s] destination
|
|
38
|
-
#
|
|
39
|
-
# @return [Berkshelf::CachedCookbook]
|
|
40
|
-
def download(destination)
|
|
41
|
-
version = target_version
|
|
42
|
-
berks_path = File.join(destination, "#{name}-#{version}")
|
|
43
|
-
|
|
44
|
-
temp_path = conn.download(name, version)
|
|
45
|
-
FileUtils.mv(File.join(temp_path, name), berks_path)
|
|
46
|
-
|
|
47
|
-
cached = CachedCookbook.from_store_path(berks_path)
|
|
48
|
-
validate_cached(cached)
|
|
49
|
-
|
|
50
|
-
cached
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
# Return the latest version that the site location has for the the cookbook
|
|
54
|
-
#
|
|
55
|
-
# @return [String]
|
|
56
|
-
def latest_version
|
|
57
|
-
conn.latest_version(name)
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
# Returns a string representing the version of the cookbook that should be downloaded
|
|
61
|
-
# for this location
|
|
62
|
-
#
|
|
63
|
-
# @return [String]
|
|
64
|
-
def target_version
|
|
65
|
-
version = if version_constraint
|
|
66
|
-
conn.satisfy(name, version_constraint)
|
|
67
|
-
else
|
|
68
|
-
latest_version
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
if version.nil?
|
|
72
|
-
msg = "Cookbook '#{name}' found at #{self}"
|
|
73
|
-
msg << " that would satisfy constraint (#{version_constraint}" if version_constraint
|
|
74
|
-
raise CookbookNotFound, msg
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
version
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def to_hash
|
|
81
|
-
super.merge(value: self.api_uri)
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def to_s
|
|
85
|
-
"#{self.class.location_key}: '#{api_uri}'"
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
private
|
|
89
|
-
|
|
90
|
-
attr_reader :conn
|
|
91
|
-
end
|
|
92
|
-
end
|
data/lib/berkshelf/test.rb
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
module Berkshelf
|
|
2
|
-
# Because aruba runs in a sub-process, there's no easy way to share mocks and
|
|
3
|
-
# stubs across a run (See RiotGames/berkshelf#208). As a work-around, we pass
|
|
4
|
-
# "special" mocks and stubs into the TEST environment variable. This class
|
|
5
|
-
# parses and then requires the appropriate mocks during the run.
|
|
6
|
-
class Mocks
|
|
7
|
-
require 'rspec/mocks/standalone'
|
|
8
|
-
|
|
9
|
-
class << self
|
|
10
|
-
def env_keys
|
|
11
|
-
self.instance_methods(false).map { |key| key.to_s.upcase }
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def initialize(keys)
|
|
16
|
-
keys.each do |key|
|
|
17
|
-
self.send(key.downcase.to_sym, ENV[key.to_s])
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
# Trick bundler into thinking gems are missing.
|
|
22
|
-
#
|
|
23
|
-
# @param [String] gems
|
|
24
|
-
# a CSV list of gems to be missing
|
|
25
|
-
def missing_gems(gems)
|
|
26
|
-
gems.split(',').each do |gem|
|
|
27
|
-
Gem::Specification.stub(:find_by_name).with(gem).and_raise(Gem::LoadError)
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
unless (keys = Berkshelf::Mocks.env_keys & ENV.keys).empty?
|
|
34
|
-
Berkshelf::Mocks.new(keys)
|
|
35
|
-
end
|
data/spec/knife.rb.sample
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
current_dir = File.expand_path(File.dirname(__FILE__))
|
|
2
|
-
|
|
3
|
-
log_level :info
|
|
4
|
-
log_location STDOUT
|
|
5
|
-
node_name "berkshelf"
|
|
6
|
-
client_key "#{current_dir}/berkshelf.pem"
|
|
7
|
-
validation_client_name "chef-validator"
|
|
8
|
-
validation_key "#{current_dir}/chef-validator.pem"
|
|
9
|
-
chef_server_url "http://localhost:4000"
|
|
10
|
-
cache_type 'BasicFile'
|
|
11
|
-
cache_options( :path => "#{ENV['HOME']}/.chef/checksums" )
|
|
12
|
-
cookbook_path []
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
module Berkshelf
|
|
2
|
-
module TestGenerators
|
|
3
|
-
def generate_berks_config(path)
|
|
4
|
-
Berkshelf::Config.new(path,
|
|
5
|
-
ssl: {
|
|
6
|
-
verify: false
|
|
7
|
-
}
|
|
8
|
-
).save
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
# Generate a minimal, default, Chef configuration file
|
|
12
|
-
#
|
|
13
|
-
# @param [#to_s] path
|
|
14
|
-
# path to the configuration to generate
|
|
15
|
-
def generate_chef_config(path)
|
|
16
|
-
contents = <<-TXT
|
|
17
|
-
chef_server_url "http://localhost:4000"
|
|
18
|
-
validation_key "/etc/chef/validation.pem"
|
|
19
|
-
validation_client_name "chef-validator"
|
|
20
|
-
client_key "/etc/chef/client.pem"
|
|
21
|
-
TXT
|
|
22
|
-
File.open(path, 'w+') do |f|
|
|
23
|
-
f.write(contents)
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe Berkshelf::Cli do
|
|
4
|
-
let(:subject) { described_class.new }
|
|
5
|
-
let(:berksfile) { double('Berksfile') }
|
|
6
|
-
let(:cookbooks) { ['mysql'] }
|
|
7
|
-
describe '#upload' do
|
|
8
|
-
it 'calls to upload with params if passed in cli' do
|
|
9
|
-
Berkshelf::Berksfile.should_receive(:from_file).and_return(berksfile)
|
|
10
|
-
berksfile.should_receive(:upload).with(include(:skip_syntax_check => true, :freeze => false, :cookbooks => cookbooks))
|
|
11
|
-
subject.options[:skip_syntax_check] = true
|
|
12
|
-
subject.options[:no_freeze] = true
|
|
13
|
-
subject.upload('mysql')
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
@@ -1,358 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe Berkshelf::CookbookSource do
|
|
4
|
-
let(:cookbook_name) { 'nginx' }
|
|
5
|
-
let(:berksfile) { double('berksfile', filepath: fixtures_path.join('Berksfile').to_s) }
|
|
6
|
-
|
|
7
|
-
describe '.initialize' do
|
|
8
|
-
let(:source) { Berkshelf::CookbookSource.new(berksfile, cookbook_name) }
|
|
9
|
-
|
|
10
|
-
context 'given no location key (i.e. :git, :path, :site)' do
|
|
11
|
-
it 'sets a nil valie for location' do
|
|
12
|
-
expect(source.location).to be_nil
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
context 'given no value for :locked_version' do
|
|
17
|
-
it 'returns a wildcard match for any version' do
|
|
18
|
-
expect(source.locked_version).to be_nil
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
context 'given no value for :constraint' do
|
|
23
|
-
it 'returns a wildcard match for any version' do
|
|
24
|
-
expect(source.version_constraint.to_s).to eq('>= 0.0.0')
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
context 'given a value for :constraint' do
|
|
29
|
-
let(:source) { Berkshelf::CookbookSource.new(berksfile, cookbook_name, constraint: '~> 1.0.84') }
|
|
30
|
-
|
|
31
|
-
it 'returns a Solve::Constraint for the given version for version_constraint' do
|
|
32
|
-
expect(source.version_constraint.to_s).to eq('~> 1.0.84')
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
context 'given a location key :git' do
|
|
37
|
-
let(:url) { 'git://url_to_git' }
|
|
38
|
-
let(:source) { Berkshelf::CookbookSource.new(berksfile, cookbook_name, git: url) }
|
|
39
|
-
|
|
40
|
-
it 'initializes a GitLocation for location' do
|
|
41
|
-
expect(source.location).to be_a(Berkshelf::GitLocation)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it 'points to the given Git URL' do
|
|
45
|
-
expect(source.location.uri).to eq(url)
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
context 'given a location key :path' do
|
|
50
|
-
context 'given a value for path that contains a cookbook' do
|
|
51
|
-
let(:path) { fixtures_path.join('cookbooks', 'example_cookbook').to_s }
|
|
52
|
-
let(:location) { Berkshelf::CookbookSource.new(berksfile, cookbook_name, path: path).location }
|
|
53
|
-
|
|
54
|
-
it 'initializes a PathLocation for location' do
|
|
55
|
-
expect(location).to be_a(Berkshelf::PathLocation)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
it 'points to the specified path' do
|
|
59
|
-
expect(location.path).to eq(path)
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
context 'given a value for path that does not contain a cookbook' do
|
|
64
|
-
let(:path) { '/does/not/exist' }
|
|
65
|
-
|
|
66
|
-
it 'raises Berkshelf::CookbookNotFound' do
|
|
67
|
-
expect {
|
|
68
|
-
Berkshelf::CookbookSource.new(berksfile, cookbook_name, path: path)
|
|
69
|
-
}.to raise_error(Berkshelf::CookbookNotFound)
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
context 'given an invalid option' do
|
|
74
|
-
it 'raises BerkshelfError with a friendly message' do
|
|
75
|
-
expect {
|
|
76
|
-
Berkshelf::CookbookSource.new(berksfile, cookbook_name, invalid_opt: 'thisisnotvalid')
|
|
77
|
-
}.to raise_error(Berkshelf::BerkshelfError, "Invalid options for Cookbook Source: 'invalid_opt'.")
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
it 'raises BerkshelfError with a messaging containing all of the invalid options' do
|
|
81
|
-
expect {
|
|
82
|
-
Berkshelf::CookbookSource.new(berksfile, cookbook_name, invalid_one: 'one', invalid_two: 'two')
|
|
83
|
-
}.to raise_error(Berkshelf::BerkshelfError, "Invalid options for Cookbook Source: 'invalid_one', 'invalid_two'.")
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
describe '.add_valid_option' do
|
|
90
|
-
before do
|
|
91
|
-
@original = Berkshelf::CookbookSource.class_variable_get :@@valid_options
|
|
92
|
-
Berkshelf::CookbookSource.class_variable_set :@@valid_options, []
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
after do
|
|
96
|
-
Berkshelf::CookbookSource.class_variable_set :@@valid_options, @original
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
it 'adds an option to the list of valid options' do
|
|
100
|
-
Berkshelf::CookbookSource.add_valid_option(:one)
|
|
101
|
-
|
|
102
|
-
expect(Berkshelf::CookbookSource.valid_options).to have(1).item
|
|
103
|
-
expect(Berkshelf::CookbookSource.valid_options).to include(:one)
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
it 'does not add duplicate options to the list of valid options' do
|
|
107
|
-
Berkshelf::CookbookSource.add_valid_option(:one)
|
|
108
|
-
Berkshelf::CookbookSource.add_valid_option(:one)
|
|
109
|
-
|
|
110
|
-
expect(Berkshelf::CookbookSource.valid_options).to have(1).item
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
describe '.add_location_key' do
|
|
115
|
-
before do
|
|
116
|
-
@original = Berkshelf::CookbookSource.class_variable_get :@@location_keys
|
|
117
|
-
Berkshelf::CookbookSource.class_variable_set :@@location_keys, {}
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
after do
|
|
121
|
-
Berkshelf::CookbookSource.class_variable_set :@@location_keys, @original
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
it 'adds a location key and the associated class to the list of valid locations' do
|
|
125
|
-
Berkshelf::CookbookSource.add_location_key(:git, Berkshelf::CookbookSource)
|
|
126
|
-
|
|
127
|
-
expect(Berkshelf::CookbookSource.location_keys).to have(1).item
|
|
128
|
-
expect(Berkshelf::CookbookSource.location_keys).to include(:git)
|
|
129
|
-
expect(Berkshelf::CookbookSource.location_keys[:git]).to eq(Berkshelf::CookbookSource)
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
it 'does not add duplicate location keys to the list of location keys' do
|
|
133
|
-
Berkshelf::CookbookSource.add_location_key(:git, Berkshelf::CookbookSource)
|
|
134
|
-
Berkshelf::CookbookSource.add_location_key(:git, Berkshelf::CookbookSource)
|
|
135
|
-
|
|
136
|
-
expect(Berkshelf::CookbookSource.location_keys).to have(1).item
|
|
137
|
-
expect(Berkshelf::CookbookSource.location_keys).to include(:git)
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
context 'given a location key :site' do
|
|
141
|
-
let(:url) { 'http://path_to_api/v1' }
|
|
142
|
-
let(:source) { Berkshelf::CookbookSource.new(berksfile, cookbook_name, site: url) }
|
|
143
|
-
|
|
144
|
-
before do
|
|
145
|
-
Berkshelf::CookbookSource.add_location_key(:site, Berkshelf::SiteLocation)
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
it 'initializes a SiteLocation for location' do
|
|
149
|
-
expect(source.location).to be_a(Berkshelf::SiteLocation)
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
it 'points to the specified URI' do
|
|
153
|
-
expect(source.location.api_uri.to_s).to eq(url)
|
|
154
|
-
end
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
context 'given multiple location options' do
|
|
158
|
-
it 'raises with an Berkshelf::BerkshelfError' do
|
|
159
|
-
expect {
|
|
160
|
-
Berkshelf::CookbookSource.new(berksfile, cookbook_name, site: 'something', git: 'something')
|
|
161
|
-
}.to raise_error(Berkshelf::BerkshelfError)
|
|
162
|
-
end
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
context 'given a group option containing a single group' do
|
|
166
|
-
let(:group) { :production }
|
|
167
|
-
let(:source) { Berkshelf::CookbookSource.new(berksfile, cookbook_name, group: group) }
|
|
168
|
-
|
|
169
|
-
it 'assigns the single group to the groups attribute' do
|
|
170
|
-
expect(source.groups).to include(group)
|
|
171
|
-
end
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
context 'given a group option containing an array of groups' do
|
|
175
|
-
let(:groups) { [ :development, :test ] }
|
|
176
|
-
let(:source) { Berkshelf::CookbookSource.new(berksfile, cookbook_name, group: groups) }
|
|
177
|
-
|
|
178
|
-
it 'assigns all the groups to the group attribute' do
|
|
179
|
-
expect(source.groups).to eq(groups)
|
|
180
|
-
end
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
context 'given no group option' do
|
|
184
|
-
let(:source) { Berkshelf::CookbookSource.new(berksfile, cookbook_name) }
|
|
185
|
-
|
|
186
|
-
it 'has the default group assigned' do
|
|
187
|
-
expect(source.groups).to include(:default)
|
|
188
|
-
end
|
|
189
|
-
end
|
|
190
|
-
end
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
subject { Berkshelf::CookbookSource.new(berksfile, cookbook_name) }
|
|
195
|
-
|
|
196
|
-
describe '#add_group' do
|
|
197
|
-
it 'stores strings as symbols' do
|
|
198
|
-
subject.add_group 'foo'
|
|
199
|
-
expect(subject.groups).to eq([:default, :foo])
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
it 'does not store duplicate groups' do
|
|
203
|
-
subject.add_group 'bar'
|
|
204
|
-
subject.add_group 'bar'
|
|
205
|
-
subject.add_group :bar
|
|
206
|
-
expect(subject.groups).to eq([:default, :bar])
|
|
207
|
-
end
|
|
208
|
-
|
|
209
|
-
it 'adds multiple groups' do
|
|
210
|
-
subject.add_group 'baz', 'quux'
|
|
211
|
-
expect(subject.groups).to eq([:default, :baz, :quux])
|
|
212
|
-
end
|
|
213
|
-
|
|
214
|
-
it 'handles multiple groups as an array' do
|
|
215
|
-
subject.add_group ['baz', 'quux']
|
|
216
|
-
expect(subject.groups).to eq([:default, :baz, :quux])
|
|
217
|
-
end
|
|
218
|
-
end
|
|
219
|
-
|
|
220
|
-
describe '#cached_and_location' do
|
|
221
|
-
let(:options) { Hash.new }
|
|
222
|
-
|
|
223
|
-
before do
|
|
224
|
-
Berkshelf::CachedCookbook.stub(:from_path).and_return(double('cached_cookbook'))
|
|
225
|
-
end
|
|
226
|
-
|
|
227
|
-
context 'when given a value for :path' do
|
|
228
|
-
before do
|
|
229
|
-
berksfile.stub(filepath: '/rspec/Berksfile')
|
|
230
|
-
options[:path] = 'cookbooks/whatever'
|
|
231
|
-
end
|
|
232
|
-
|
|
233
|
-
it 'returns a PathLocation with a path relative to the Berksfile.filepath' do
|
|
234
|
-
_, location = subject.cached_and_location(options)
|
|
235
|
-
|
|
236
|
-
expect(location.path).to eq('cookbooks/whatever')
|
|
237
|
-
expect(location.relative_path(berksfile)).to eq('../cookbooks/whatever')
|
|
238
|
-
end
|
|
239
|
-
end
|
|
240
|
-
end
|
|
241
|
-
|
|
242
|
-
describe '#downloaded?' do
|
|
243
|
-
it 'returns true if self.cached_cookbook is not nil' do
|
|
244
|
-
subject.stub(:cached_cookbook) { double('cb') }
|
|
245
|
-
expect(subject.downloaded?).to be_true
|
|
246
|
-
end
|
|
247
|
-
|
|
248
|
-
it 'returns false if self.cached_cookbook is nil' do
|
|
249
|
-
subject.stub(:cached_cookbook) { nil }
|
|
250
|
-
expect(subject.downloaded?).to be_false
|
|
251
|
-
end
|
|
252
|
-
end
|
|
253
|
-
|
|
254
|
-
describe '#to_hash' do
|
|
255
|
-
let(:hash) { subject.to_hash }
|
|
256
|
-
|
|
257
|
-
it 'does not include default values' do
|
|
258
|
-
[:constraint, :locked_version, :site, :git, :ref, :path].each do |key|
|
|
259
|
-
expect(hash).to_not have_key(key)
|
|
260
|
-
end
|
|
261
|
-
end
|
|
262
|
-
|
|
263
|
-
it 'includes the locked version' do
|
|
264
|
-
subject.cached_cookbook = double('cached', version: '1.2.3')
|
|
265
|
-
|
|
266
|
-
expect(hash).to have_key(:locked_version)
|
|
267
|
-
expect(hash[:locked_version]).to eq('1.2.3')
|
|
268
|
-
end
|
|
269
|
-
|
|
270
|
-
it 'does not include the site if it is the default' do
|
|
271
|
-
location = double('site', api_uri: Berkshelf::CommunityREST::V1_API)
|
|
272
|
-
location.stub(:kind_of?).and_return(false)
|
|
273
|
-
location.stub(:kind_of?).with(Berkshelf::SiteLocation).and_return(true)
|
|
274
|
-
subject.stub(:location).and_return(location)
|
|
275
|
-
|
|
276
|
-
expect(hash).to_not have_key(:site)
|
|
277
|
-
end
|
|
278
|
-
|
|
279
|
-
it 'includes the site' do
|
|
280
|
-
location = double('site', api_uri: 'www.example.com')
|
|
281
|
-
location.stub(:kind_of?).and_return(false)
|
|
282
|
-
location.stub(:kind_of?).with(Berkshelf::SiteLocation).and_return(true)
|
|
283
|
-
subject.stub(:location).and_return(location)
|
|
284
|
-
|
|
285
|
-
expect(hash).to have_key(:site)
|
|
286
|
-
expect(hash[:site]).to eq('www.example.com')
|
|
287
|
-
end
|
|
288
|
-
|
|
289
|
-
it 'includes the git url and ref' do
|
|
290
|
-
location = double('git', uri: 'git://github.com/foo/bar.git', ref: 'abcd1234', rel: nil)
|
|
291
|
-
location.stub(:kind_of?).and_return(false)
|
|
292
|
-
location.stub(:kind_of?).with(Berkshelf::GitLocation).and_return(true)
|
|
293
|
-
subject.stub(:location).and_return(location)
|
|
294
|
-
|
|
295
|
-
expect(hash).to have_key(:git)
|
|
296
|
-
expect(hash[:git]).to eq('git://github.com/foo/bar.git')
|
|
297
|
-
expect(hash).to have_key(:ref)
|
|
298
|
-
expect(hash[:ref]).to eq('abcd1234')
|
|
299
|
-
end
|
|
300
|
-
|
|
301
|
-
it 'includes the git url and rel' do
|
|
302
|
-
location = double('git', uri: 'git://github.com/foo/bar.git', ref: nil, rel: 'cookbooks/foo')
|
|
303
|
-
location.stub(:kind_of?).and_return(false)
|
|
304
|
-
location.stub(:kind_of?).with(Berkshelf::GitLocation).and_return(true)
|
|
305
|
-
subject.stub(:location).and_return(location)
|
|
306
|
-
|
|
307
|
-
expect(hash).to have_key(:git)
|
|
308
|
-
expect(hash[:git]).to eq('git://github.com/foo/bar.git')
|
|
309
|
-
expect(hash).to have_key(:rel)
|
|
310
|
-
expect(hash[:rel]).to eq('cookbooks/foo')
|
|
311
|
-
end
|
|
312
|
-
|
|
313
|
-
it 'includes a relative path' do
|
|
314
|
-
location = double('path', relative_path: '../dev/foo')
|
|
315
|
-
location.stub(:kind_of?).and_return(false)
|
|
316
|
-
location.stub(:kind_of?).with(Berkshelf::PathLocation).and_return(true)
|
|
317
|
-
subject.stub(:location).and_return(location)
|
|
318
|
-
|
|
319
|
-
expect(hash).to have_key(:path)
|
|
320
|
-
expect(hash[:path]).to eq('../dev/foo')
|
|
321
|
-
end
|
|
322
|
-
end
|
|
323
|
-
|
|
324
|
-
describe '#to_s' do
|
|
325
|
-
it 'contains the name, constraint, and groups' do
|
|
326
|
-
source = Berkshelf::CookbookSource.new(berksfile, 'artifact', constraint: '= 0.10.0')
|
|
327
|
-
expect(source.to_s).to eq('#<Berkshelf::CookbookSource: artifact (= 0.10.0)>')
|
|
328
|
-
end
|
|
329
|
-
|
|
330
|
-
context 'given a CookbookSource with an explicit location' do
|
|
331
|
-
it 'contains the name, constraint, groups, and location' do
|
|
332
|
-
source = Berkshelf::CookbookSource.new(berksfile, 'artifact', constraint: '= 0.10.0', site: 'http://cookbooks.opscode.com/api/v1/cookbooks')
|
|
333
|
-
expect(source.to_s).to eq('#<Berkshelf::CookbookSource: artifact (= 0.10.0)>')
|
|
334
|
-
end
|
|
335
|
-
end
|
|
336
|
-
end
|
|
337
|
-
|
|
338
|
-
describe '#inspect' do
|
|
339
|
-
it 'contains the name, constraint, and groups' do
|
|
340
|
-
source = Berkshelf::CookbookSource.new(berksfile, 'artifact', constraint: '= 0.10.0')
|
|
341
|
-
expect(source.inspect).to eq('#<Berkshelf::CookbookSource: artifact (= 0.10.0), locked_version: nil, groups: [:default], location: default>')
|
|
342
|
-
end
|
|
343
|
-
|
|
344
|
-
context 'given a CookbookSource with an explicit location' do
|
|
345
|
-
it 'contains the name, constraint, groups, and location' do
|
|
346
|
-
source = Berkshelf::CookbookSource.new(berksfile, 'artifact', constraint: '= 0.10.0', site: 'http://cookbooks.opscode.com/api/v1/cookbooks')
|
|
347
|
-
expect(source.inspect).to eq("#<Berkshelf::CookbookSource: artifact (= 0.10.0), locked_version: nil, groups: [:default], location: site: 'http://cookbooks.opscode.com/api/v1/cookbooks'>")
|
|
348
|
-
end
|
|
349
|
-
end
|
|
350
|
-
|
|
351
|
-
context 'given an explicitly locked version' do
|
|
352
|
-
it 'includes the locked_version' do
|
|
353
|
-
source = Berkshelf::CookbookSource.new(berksfile, 'artifact', constraint: '= 0.10.0', site: 'http://cookbooks.opscode.com/api/v1/cookbooks', locked_version: '1.2.3')
|
|
354
|
-
expect(source.inspect).to eq("#<Berkshelf::CookbookSource: artifact (= 0.10.0), locked_version: 1.2.3, groups: [:default], location: site: 'http://cookbooks.opscode.com/api/v1/cookbooks'>")
|
|
355
|
-
end
|
|
356
|
-
end
|
|
357
|
-
end
|
|
358
|
-
end
|