berkshelf 5.2.0 → 8.0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile +19 -47
- data/Rakefile +14 -4
- data/berkshelf.gemspec +61 -40
- data/bin/berks +2 -2
- data/lib/berkshelf/api-client.rb +1 -0
- data/lib/berkshelf/api_client/chef_server_connection.rb +29 -0
- data/lib/berkshelf/api_client/connection.rb +57 -0
- data/lib/berkshelf/api_client/errors.rb +10 -0
- data/lib/berkshelf/api_client/remote_cookbook.rb +56 -0
- data/lib/berkshelf/api_client/version.rb +5 -0
- data/lib/berkshelf/api_client.rb +24 -0
- data/lib/berkshelf/berksfile.rb +149 -122
- data/lib/berkshelf/cached_cookbook.rb +127 -24
- data/lib/berkshelf/chef_config_compat.rb +51 -0
- data/lib/berkshelf/chef_repo_universe.rb +47 -0
- data/lib/berkshelf/cli.rb +143 -174
- data/lib/berkshelf/commands/shelf.rb +20 -19
- data/lib/berkshelf/community_rest.rb +59 -94
- data/lib/berkshelf/config.rb +97 -127
- data/lib/berkshelf/cookbook_store.rb +7 -6
- data/lib/berkshelf/core_ext/file.rb +1 -1
- data/lib/berkshelf/core_ext/file_utils.rb +4 -4
- data/lib/berkshelf/core_ext.rb +1 -1
- data/lib/berkshelf/dependency.rb +25 -32
- data/lib/berkshelf/downloader.rb +66 -39
- data/lib/berkshelf/errors.rb +23 -17
- data/lib/berkshelf/file_syncer.rb +24 -47
- data/lib/berkshelf/formatters/human.rb +7 -5
- data/lib/berkshelf/formatters/json.rb +6 -6
- data/lib/berkshelf/installer.rb +120 -111
- data/lib/berkshelf/location.rb +14 -14
- data/lib/berkshelf/locations/base.rb +1 -1
- data/lib/berkshelf/locations/git.rb +16 -24
- data/lib/berkshelf/locations/github.rb +2 -2
- data/lib/berkshelf/locations/path.rb +2 -2
- data/lib/berkshelf/lockfile.rb +326 -328
- data/lib/berkshelf/logger.rb +64 -1
- data/lib/berkshelf/mixin/git.rb +6 -5
- data/lib/berkshelf/packager.rb +44 -10
- data/lib/berkshelf/resolver/graph.rb +1 -1
- data/lib/berkshelf/resolver.rb +4 -4
- data/lib/berkshelf/ridley_compat.rb +109 -0
- data/lib/berkshelf/shell.rb +2 -1
- data/lib/berkshelf/shell_out.rb +18 -0
- data/lib/berkshelf/source.rb +77 -33
- data/lib/berkshelf/source_uri.rb +4 -4
- data/lib/berkshelf/ssl_policies.rb +38 -0
- data/lib/berkshelf/thor.rb +1 -1
- data/lib/berkshelf/thor_ext/hash_with_indifferent_access.rb +1 -1
- data/lib/berkshelf/thor_ext.rb +1 -1
- data/lib/berkshelf/uploader.rb +106 -70
- data/lib/berkshelf/validator.rb +13 -5
- data/lib/berkshelf/version.rb +1 -1
- data/lib/berkshelf/visualizer.rb +16 -11
- data/lib/berkshelf.rb +106 -81
- data/spec/config/knife.rb +4 -4
- data/spec/data/trusted_certs/example.crt +22 -0
- data/spec/fixtures/Berksfile +3 -3
- data/spec/fixtures/complex-cookbook-path/cookbooks/app/metadata.rb +2 -0
- data/spec/fixtures/complex-cookbook-path/cookbooks/jenkins/metadata.rb +2 -0
- data/spec/fixtures/complex-cookbook-path/cookbooks/jenkins-config/metadata.rb +4 -0
- data/spec/fixtures/cookbook-path/jenkins-config/metadata.rb +3 -3
- data/spec/fixtures/cookbook-path-uploader/apt-2.3.6/metadata.rb +2 -0
- data/spec/fixtures/cookbook-path-uploader/build-essential-1.4.2/metadata.rb +2 -0
- data/spec/fixtures/cookbook-path-uploader/jenkins-2.0.3/metadata.rb +5 -0
- data/spec/fixtures/cookbook-path-uploader/jenkins-config-0.1.0/metadata.rb +4 -0
- data/spec/fixtures/cookbook-path-uploader/runit-1.5.8/metadata.rb +5 -0
- data/spec/fixtures/cookbook-path-uploader/yum-3.0.6/metadata.rb +2 -0
- data/spec/fixtures/cookbook-path-uploader/yum-epel-0.2.0/metadata.rb +3 -0
- data/spec/fixtures/cookbook-store/jenkins-2.0.3/metadata.rb +5 -5
- data/spec/fixtures/cookbook-store/jenkins-2.0.4/metadata.rb +4 -4
- data/spec/fixtures/cookbooks/example_cookbook/metadata.rb +3 -3
- data/spec/fixtures/cookbooks/example_cookbook-0.5.0/metadata.rb +3 -3
- data/spec/spec_helper.rb +56 -64
- data/spec/support/chef_api.rb +15 -16
- data/spec/support/chef_server.rb +71 -69
- data/spec/support/git.rb +59 -58
- data/spec/support/kitchen.rb +0 -14
- data/spec/support/matchers/file_system_matchers.rb +4 -5
- data/spec/support/matchers/filepath_matchers.rb +2 -2
- data/spec/support/path_helpers.rb +17 -17
- data/spec/support/shared_examples/formatter.rb +1 -1
- data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/attributes/default.rb +0 -0
- data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/files/default/file.h +0 -0
- data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/metadata.rb +2 -0
- data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/recipes/default.rb +0 -0
- data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/templates/default/template.erb +0 -0
- data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/attributes/default.rb +0 -0
- data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/files/default/file.h +0 -0
- data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/metadata.rb +2 -0
- data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/recipes/default.rb +0 -0
- data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/templates/default/template.erb +0 -0
- data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/attributes/default.rb +0 -0
- data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/files/default/file.h +0 -0
- data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/metadata.rb +2 -0
- data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/recipes/default.rb +0 -0
- data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/templates/default/template.erb +0 -0
- data/spec/unit/berkshelf/berksfile_spec.rb +84 -105
- data/spec/unit/berkshelf/berkshelf/api_client/chef_server_connection_spec.rb +65 -0
- data/spec/unit/berkshelf/berkshelf/api_client/connection_spec.rb +157 -0
- data/spec/unit/berkshelf/berkshelf/api_client/remote_cookbook_spec.rb +23 -0
- data/spec/unit/berkshelf/berkshelf/api_client_spec.rb +9 -0
- data/spec/unit/berkshelf/cached_cookbook_spec.rb +45 -47
- data/spec/unit/berkshelf/chef_repo_universe_spec.rb +37 -0
- data/spec/unit/berkshelf/cli_spec.rb +7 -8
- data/spec/unit/berkshelf/community_rest_spec.rb +82 -90
- data/spec/unit/berkshelf/config_spec.rb +51 -22
- data/spec/unit/berkshelf/cookbook_store_spec.rb +41 -41
- data/spec/unit/berkshelf/core_ext/file_utils_spec.rb +7 -8
- data/spec/unit/berkshelf/core_ext/pathname_spec.rb +1 -1
- data/spec/unit/berkshelf/dependency_spec.rb +48 -48
- data/spec/unit/berkshelf/downloader_spec.rb +191 -34
- data/spec/unit/berkshelf/errors_spec.rb +3 -3
- data/spec/unit/berkshelf/file_syncer_spec.rb +87 -87
- data/spec/unit/berkshelf/formatters/base_spec.rb +23 -23
- data/spec/unit/berkshelf/formatters/human_spec.rb +2 -2
- data/spec/unit/berkshelf/formatters/json_spec.rb +2 -2
- data/spec/unit/berkshelf/formatters/null_spec.rb +3 -3
- data/spec/unit/berkshelf/installer_spec.rb +8 -8
- data/spec/unit/berkshelf/location_spec.rb +11 -11
- data/spec/unit/berkshelf/locations/base_spec.rb +35 -36
- data/spec/unit/berkshelf/locations/git_spec.rb +90 -93
- data/spec/unit/berkshelf/locations/path_spec.rb +40 -41
- data/spec/unit/berkshelf/lockfile_parser_spec.rb +71 -71
- data/spec/unit/berkshelf/lockfile_spec.rb +205 -211
- data/spec/unit/berkshelf/logger_spec.rb +3 -3
- data/spec/unit/berkshelf/mixin/logging_spec.rb +5 -5
- data/spec/unit/berkshelf/packager_spec.rb +2 -2
- data/spec/unit/berkshelf/resolver/graph_spec.rb +10 -8
- data/spec/unit/berkshelf/resolver_spec.rb +17 -17
- data/spec/unit/berkshelf/ridley_compat_spec.rb +16 -0
- data/spec/unit/berkshelf/shell_spec.rb +34 -34
- data/spec/unit/berkshelf/source_spec.rb +186 -20
- data/spec/unit/berkshelf/source_uri_spec.rb +1 -1
- data/spec/unit/berkshelf/ssl_policies_spec.rb +86 -0
- data/spec/unit/berkshelf/uploader_spec.rb +146 -64
- data/spec/unit/berkshelf/validator_spec.rb +23 -16
- data/spec/unit/berkshelf/visualizer_spec.rb +24 -15
- data/spec/unit/berkshelf_spec.rb +18 -18
- metadata +138 -289
- data/.gitignore +0 -29
- data/.travis.yml +0 -64
- data/CHANGELOG.legacy.md +0 -307
- data/CHANGELOG.md +0 -1358
- data/CONTRIBUTING.md +0 -64
- data/Gemfile.lock +0 -399
- data/Guardfile +0 -23
- data/PLUGINS.md +0 -25
- data/README.md +0 -70
- data/Thorfile +0 -61
- data/appveyor.yml +0 -31
- data/docs/berkshelf_for_newcomers.md +0 -65
- data/features/berksfile.feature +0 -46
- data/features/commands/apply.feature +0 -41
- data/features/commands/contingent.feature +0 -48
- data/features/commands/cookbook.feature +0 -35
- data/features/commands/info.feature +0 -99
- data/features/commands/init.feature +0 -27
- data/features/commands/install.feature +0 -636
- data/features/commands/list.feature +0 -78
- data/features/commands/outdated.feature +0 -130
- data/features/commands/package.feature +0 -17
- data/features/commands/search.feature +0 -17
- data/features/commands/shelf/list.feature +0 -32
- data/features/commands/shelf/show.feature +0 -143
- data/features/commands/shelf/uninstall.feature +0 -96
- data/features/commands/show.feature +0 -83
- data/features/commands/update.feature +0 -142
- data/features/commands/upload.feature +0 -426
- data/features/commands/vendor.feature +0 -111
- data/features/commands/verify.feature +0 -29
- data/features/commands/viz.feature +0 -66
- data/features/community_site.feature +0 -37
- data/features/config.feature +0 -111
- data/features/help.feature +0 -11
- data/features/json_formatter.feature +0 -161
- data/features/lifecycle.feature +0 -378
- data/features/lockfile.feature +0 -378
- data/features/step_definitions/berksfile_steps.rb +0 -39
- data/features/step_definitions/chef/config_steps.rb +0 -12
- data/features/step_definitions/chef_server_steps.rb +0 -60
- data/features/step_definitions/cli_steps.rb +0 -18
- data/features/step_definitions/config_steps.rb +0 -46
- data/features/step_definitions/environment_steps.rb +0 -7
- data/features/step_definitions/filesystem_steps.rb +0 -269
- data/features/step_definitions/gem_steps.rb +0 -13
- data/features/step_definitions/json_steps.rb +0 -23
- data/features/step_definitions/utility_steps.rb +0 -11
- data/features/support/aruba.rb +0 -12
- data/features/support/env.rb +0 -82
- data/generator_files/Berksfile.erb +0 -11
- data/generator_files/CHANGELOG.md.erb +0 -3
- data/generator_files/Gemfile.erb +0 -8
- data/generator_files/README.md.erb +0 -42
- data/generator_files/Thorfile.erb +0 -11
- data/generator_files/Vagrantfile.erb +0 -117
- data/generator_files/chefignore +0 -94
- data/generator_files/default_recipe.erb +0 -6
- data/generator_files/default_test.rb.erb +0 -11
- data/generator_files/gitignore.erb +0 -23
- data/generator_files/helpers.rb.erb +0 -7
- data/generator_files/licenses/apachev2.erb +0 -13
- data/generator_files/licenses/gplv2.erb +0 -15
- data/generator_files/licenses/gplv3.erb +0 -14
- data/generator_files/licenses/mit.erb +0 -20
- data/generator_files/licenses/reserved.erb +0 -3
- data/generator_files/metadata.rb.erb +0 -11
- data/lib/berkshelf/base_generator.rb +0 -43
- data/lib/berkshelf/commands/test_command.rb +0 -13
- data/lib/berkshelf/cookbook_generator.rb +0 -133
- data/lib/berkshelf/init_generator.rb +0 -195
- data/spec/fixtures/cookbooks/example_cookbook/.gitignore +0 -2
- data/spec/fixtures/cookbooks/example_cookbook/.kitchen.yml +0 -26
- data/spec/unit/berkshelf/cookbook_generator_spec.rb +0 -110
- data/spec/unit/berkshelf/init_generator_spec.rb +0 -263
@@ -1,100 +1,100 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
module Berkshelf
|
4
4
|
describe GitLocation do
|
5
|
-
let(:dependency) { double(name:
|
5
|
+
let(:dependency) { double(name: "bacon") }
|
6
6
|
|
7
7
|
subject do
|
8
|
-
described_class.new(dependency, git:
|
9
|
-
|
8
|
+
described_class.new(dependency, git: "https://repo.com", branch: "ham",
|
9
|
+
tag: "v1.2.3", ref: "abc123", revision: "defjkl123456", rel: "hi")
|
10
10
|
end
|
11
11
|
|
12
|
-
describe
|
13
|
-
it
|
14
|
-
instance = described_class.new(dependency, git:
|
15
|
-
expect(instance.uri).to eq(
|
12
|
+
describe ".initialize" do
|
13
|
+
it "sets the uri" do
|
14
|
+
instance = described_class.new(dependency, git: "https://repo.com")
|
15
|
+
expect(instance.uri).to eq("https://repo.com")
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
18
|
+
it "sets the branch" do
|
19
19
|
instance = described_class.new(dependency,
|
20
|
-
git:
|
21
|
-
expect(instance.branch).to eq(
|
20
|
+
git: "https://repo.com", branch: "magic_new_feature")
|
21
|
+
expect(instance.branch).to eq("magic_new_feature")
|
22
22
|
end
|
23
23
|
|
24
|
-
it
|
24
|
+
it "sets the tag" do
|
25
25
|
instance = described_class.new(dependency,
|
26
|
-
git:
|
27
|
-
expect(instance.tag).to eq(
|
26
|
+
git: "https://repo.com", tag: "v1.2.3")
|
27
|
+
expect(instance.tag).to eq("v1.2.3")
|
28
28
|
end
|
29
29
|
|
30
|
-
it
|
30
|
+
it "adds the ref" do
|
31
31
|
instance = described_class.new(dependency,
|
32
|
-
git:
|
33
|
-
expect(instance.ref).to eq(
|
32
|
+
git: "https://repo.com", ref: "abc123")
|
33
|
+
expect(instance.ref).to eq("abc123")
|
34
34
|
end
|
35
35
|
|
36
|
-
it
|
36
|
+
it "sets the revision" do
|
37
37
|
instance = described_class.new(dependency,
|
38
|
-
git:
|
39
|
-
expect(instance.revision).to eq(
|
38
|
+
git: "https://repo.com", revision: "abcde12345")
|
39
|
+
expect(instance.revision).to eq("abcde12345")
|
40
40
|
end
|
41
41
|
|
42
|
-
it
|
42
|
+
it "sets the rel" do
|
43
43
|
instance = described_class.new(dependency,
|
44
|
-
git:
|
45
|
-
expect(instance.rel).to eq(
|
44
|
+
git: "https://repo.com", rel: "internal/path")
|
45
|
+
expect(instance.rel).to eq("internal/path")
|
46
46
|
end
|
47
47
|
|
48
|
-
context
|
48
|
+
context "rev_parse" do
|
49
49
|
def rev_parse(instance)
|
50
50
|
instance.instance_variable_get(:@rev_parse)
|
51
51
|
end
|
52
52
|
|
53
|
-
it
|
53
|
+
it "uses the :ref option with priority" do
|
54
54
|
instance = described_class.new(dependency,
|
55
|
-
git:
|
56
|
-
expect(rev_parse(instance)).to eq(
|
55
|
+
git: "https://repo.com", ref: "abc123", branch: "magic_new_feature")
|
56
|
+
expect(rev_parse(instance)).to eq("abc123")
|
57
57
|
end
|
58
58
|
|
59
|
-
it
|
59
|
+
it "uses the :branch option with priority" do
|
60
60
|
instance = described_class.new(dependency,
|
61
|
-
git:
|
62
|
-
expect(rev_parse(instance)).to eq(
|
61
|
+
git: "https://repo.com", branch: "magic_new_feature", tag: "v1.2.3")
|
62
|
+
expect(rev_parse(instance)).to eq("magic_new_feature")
|
63
63
|
end
|
64
64
|
|
65
|
-
it
|
65
|
+
it "uses the :tag option" do
|
66
66
|
instance = described_class.new(dependency,
|
67
|
-
git:
|
68
|
-
expect(rev_parse(instance)).to eq(
|
67
|
+
git: "https://repo.com", tag: "v1.2.3")
|
68
|
+
expect(rev_parse(instance)).to eq("v1.2.3")
|
69
69
|
end
|
70
70
|
|
71
71
|
it 'uses "master" when none is given' do
|
72
|
-
instance = described_class.new(dependency, git:
|
73
|
-
expect(rev_parse(instance)).to eq(
|
72
|
+
instance = described_class.new(dependency, git: "https://repo.com")
|
73
|
+
expect(rev_parse(instance)).to eq("master")
|
74
74
|
end
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
-
describe
|
79
|
-
it
|
78
|
+
describe "#installed?" do
|
79
|
+
it "returns false when there is no revision" do
|
80
80
|
allow(subject).to receive(:revision).and_return(nil)
|
81
81
|
expect(subject.installed?).to be(false)
|
82
82
|
end
|
83
83
|
|
84
|
-
it
|
85
|
-
allow(subject).to receive(:revision).and_return(
|
84
|
+
it "returns false when the install_path does not exist" do
|
85
|
+
allow(subject).to receive(:revision).and_return("abcd1234")
|
86
86
|
allow(subject).to receive(:install_path).and_return(double(exist?: false))
|
87
87
|
expect(subject.installed?).to be(false)
|
88
88
|
end
|
89
89
|
|
90
|
-
it
|
91
|
-
allow(subject).to receive(:revision).and_return(
|
90
|
+
it "returns true when the location is installed" do
|
91
|
+
allow(subject).to receive(:revision).and_return("abcd1234")
|
92
92
|
allow(subject).to receive(:install_path).and_return(double(exist?: true))
|
93
93
|
expect(subject.installed?).to be(true)
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
|
-
describe
|
97
|
+
describe "#install" do
|
98
98
|
before do
|
99
99
|
allow(File).to receive(:chmod)
|
100
100
|
allow(FileUtils).to receive(:cp_r)
|
@@ -102,39 +102,36 @@ module Berkshelf
|
|
102
102
|
allow(subject).to receive(:git)
|
103
103
|
end
|
104
104
|
|
105
|
-
context
|
106
|
-
it
|
107
|
-
|
108
|
-
|
105
|
+
context "when the repository is cached" do
|
106
|
+
it "pulls a new version" do
|
107
|
+
cache_path = subject.send(:cache_path)
|
109
108
|
allow(subject).to receive(:cached?).and_return(true)
|
110
109
|
expect(subject).to receive(:git).with(
|
111
|
-
'fetch --force --tags https://repo.com "refs/heads/*:refs/heads/*"'
|
110
|
+
'fetch --force --tags https://repo.com "refs/heads/*:refs/heads/*"', cwd: cache_path.to_s
|
112
111
|
)
|
113
112
|
subject.install
|
114
113
|
end
|
115
114
|
end
|
116
115
|
|
117
|
-
context
|
118
|
-
it
|
119
|
-
allow(Dir).to receive(:chdir) { |args, &b| b.call } # Force eval the chdir block
|
120
|
-
|
116
|
+
context "when the revision is not cached" do
|
117
|
+
it "clones the repository" do
|
121
118
|
cache_path = subject.send(:cache_path)
|
122
119
|
allow(subject).to receive(:cached?).and_return(false)
|
123
120
|
expect(subject).to receive(:git).with(
|
124
|
-
|
121
|
+
%{clone https://repo.com "#{cache_path}" --bare --no-hardlinks}
|
125
122
|
)
|
126
123
|
subject.install
|
127
124
|
end
|
128
125
|
end
|
129
126
|
end
|
130
127
|
|
131
|
-
describe
|
132
|
-
it
|
128
|
+
describe "#cached_cookbook" do
|
129
|
+
it "returns nil if the cookbook is not installed" do
|
133
130
|
allow(subject).to receive(:installed?).and_return(false)
|
134
131
|
expect(subject.cached_cookbook).to be_nil
|
135
132
|
end
|
136
133
|
|
137
|
-
it
|
134
|
+
it "returns the cookbook at the install_path" do
|
138
135
|
allow(subject).to receive(:installed?).and_return(true)
|
139
136
|
allow(CachedCookbook).to receive(:from_path)
|
140
137
|
|
@@ -143,69 +140,69 @@ module Berkshelf
|
|
143
140
|
end
|
144
141
|
end
|
145
142
|
|
146
|
-
describe
|
143
|
+
describe "#==" do
|
147
144
|
let(:other) { subject.dup }
|
148
145
|
|
149
|
-
it
|
146
|
+
it "returns true when everything matches" do
|
150
147
|
expect(subject).to eq(other)
|
151
148
|
end
|
152
149
|
|
153
|
-
it
|
150
|
+
it "returns false when the other location is not an GitLocation" do
|
154
151
|
allow(other).to receive(:is_a?).and_return(false)
|
155
152
|
expect(subject).to_not eq(other)
|
156
153
|
end
|
157
154
|
|
158
|
-
it
|
159
|
-
allow(other).to receive(:uri).and_return(
|
155
|
+
it "returns false when the uri is different" do
|
156
|
+
allow(other).to receive(:uri).and_return("different")
|
160
157
|
expect(subject).to_not eq(other)
|
161
158
|
end
|
162
159
|
|
163
|
-
it
|
164
|
-
allow(other).to receive(:branch).and_return(
|
160
|
+
it "returns false when the branch is different" do
|
161
|
+
allow(other).to receive(:branch).and_return("different")
|
165
162
|
expect(subject).to_not eq(other)
|
166
163
|
end
|
167
164
|
|
168
|
-
it
|
169
|
-
allow(other).to receive(:tag).and_return(
|
165
|
+
it "returns false when the tag is different" do
|
166
|
+
allow(other).to receive(:tag).and_return("different")
|
170
167
|
expect(subject).to_not eq(other)
|
171
168
|
end
|
172
169
|
|
173
|
-
it
|
174
|
-
allow(other).to receive(:ref).and_return(
|
170
|
+
it "returns false when the ref is different" do
|
171
|
+
allow(other).to receive(:ref).and_return("different")
|
175
172
|
expect(subject).to_not eq(other)
|
176
173
|
end
|
177
174
|
|
178
|
-
it
|
179
|
-
allow(other).to receive(:rel).and_return(
|
175
|
+
it "returns false when the rel is different" do
|
176
|
+
allow(other).to receive(:rel).and_return("different")
|
180
177
|
expect(subject).to_not eq(other)
|
181
178
|
end
|
182
179
|
end
|
183
180
|
|
184
|
-
describe
|
185
|
-
it
|
186
|
-
expect(subject.to_s).to eq(
|
181
|
+
describe "#to_s" do
|
182
|
+
it "prefers the tag" do
|
183
|
+
expect(subject.to_s).to eq("https://repo.com (at v1.2.3/hi)")
|
187
184
|
end
|
188
185
|
|
189
|
-
it
|
186
|
+
it "prefers the branch" do
|
190
187
|
allow(subject).to receive(:tag).and_return(nil)
|
191
|
-
expect(subject.to_s).to eq(
|
188
|
+
expect(subject.to_s).to eq("https://repo.com (at ham/hi)")
|
192
189
|
end
|
193
190
|
|
194
|
-
it
|
191
|
+
it "falls back to the ref" do
|
195
192
|
allow(subject).to receive(:tag).and_return(nil)
|
196
193
|
allow(subject).to receive(:branch).and_return(nil)
|
197
|
-
expect(subject.to_s).to eq(
|
194
|
+
expect(subject.to_s).to eq("https://repo.com (at abc123/hi)")
|
198
195
|
end
|
199
196
|
|
200
|
-
it
|
197
|
+
it "does not use the rel if missing" do
|
201
198
|
allow(subject).to receive(:rel).and_return(nil)
|
202
|
-
expect(subject.to_s).to eq(
|
199
|
+
expect(subject.to_s).to eq("https://repo.com (at v1.2.3)")
|
203
200
|
end
|
204
201
|
end
|
205
202
|
|
206
|
-
describe
|
207
|
-
it
|
208
|
-
expect(subject.to_lock).to eq <<-EOH.gsub(/^ {8}/,
|
203
|
+
describe "#to_lock" do
|
204
|
+
it "includes all the information" do
|
205
|
+
expect(subject.to_lock).to eq <<-EOH.gsub(/^ {8}/, "")
|
209
206
|
git: https://repo.com
|
210
207
|
revision: defjkl123456
|
211
208
|
ref: abc123
|
@@ -215,34 +212,34 @@ module Berkshelf
|
|
215
212
|
EOH
|
216
213
|
end
|
217
214
|
|
218
|
-
it
|
215
|
+
it "does not include the branch if missing" do
|
219
216
|
allow(subject).to receive(:branch).and_return(nil)
|
220
|
-
expect(subject.to_lock).to_not include(
|
217
|
+
expect(subject.to_lock).to_not include("branch")
|
221
218
|
end
|
222
219
|
|
223
|
-
it
|
220
|
+
it "does not include the tag if missing" do
|
224
221
|
allow(subject).to receive(:tag).and_return(nil)
|
225
|
-
expect(subject.to_lock).to_not include(
|
222
|
+
expect(subject.to_lock).to_not include("tag")
|
226
223
|
end
|
227
224
|
|
228
|
-
it
|
225
|
+
it "does not include the rel if missing" do
|
229
226
|
allow(subject).to receive(:rel).and_return(nil)
|
230
|
-
expect(subject.to_lock).to_not include(
|
227
|
+
expect(subject.to_lock).to_not include("rel")
|
231
228
|
end
|
232
229
|
end
|
233
230
|
|
234
|
-
describe
|
231
|
+
describe "#git" do
|
235
232
|
before { described_class.send(:public, :git) }
|
236
233
|
|
237
|
-
it
|
234
|
+
it "raises an error if Git is not installed" do
|
238
235
|
allow(Berkshelf).to receive(:which).and_return(false)
|
239
|
-
expect { subject.git(
|
236
|
+
expect { subject.git("foo") }.to raise_error(GitNotInstalled)
|
240
237
|
end
|
241
238
|
|
242
|
-
it
|
243
|
-
shell_out = double(
|
244
|
-
allow(
|
245
|
-
expect { subject.git(
|
239
|
+
it "raises an error if the command fails" do
|
240
|
+
shell_out = double("shell_out", error?: true, stderr: nil)
|
241
|
+
allow(subject).to receive(:shell_out).and_return(shell_out)
|
242
|
+
expect { subject.git("foo") }.to raise_error(GitCommandError)
|
246
243
|
end
|
247
244
|
end
|
248
245
|
end
|
@@ -1,104 +1,103 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
module Berkshelf
|
4
4
|
describe PathLocation do
|
5
|
-
let(:berksfile) { double(
|
6
|
-
let(:constraint) { double(
|
5
|
+
let(:berksfile) { double("berksfile", filepath: __FILE__) }
|
6
|
+
let(:constraint) { double("constraint", satisfies?: true) }
|
7
7
|
let(:dependency) do
|
8
|
-
double(
|
9
|
-
name:
|
8
|
+
double("dependency",
|
9
|
+
name: "nginx",
|
10
10
|
version_constraint: constraint,
|
11
|
-
berksfile: berksfile
|
12
|
-
)
|
11
|
+
berksfile: berksfile)
|
13
12
|
end
|
14
|
-
let(:path) { fixtures_path.join(
|
15
|
-
let(:relative_path) { Pathname.new(
|
13
|
+
let(:path) { fixtures_path.join("cookbooks", "example_cookbook") }
|
14
|
+
let(:relative_path) { Pathname.new("../../../fixtures/cookbooks/example_cookbook") }
|
16
15
|
|
17
16
|
subject { described_class.new(dependency, path: path) }
|
18
17
|
|
19
|
-
describe
|
20
|
-
it
|
18
|
+
describe "#installed?" do
|
19
|
+
it "returns false" do
|
21
20
|
expect(subject.installed?).to be(false)
|
22
21
|
end
|
23
22
|
end
|
24
23
|
|
25
|
-
describe
|
26
|
-
it
|
24
|
+
describe "#install" do
|
25
|
+
it "validates the cached cookbook" do
|
27
26
|
expect(subject).to receive(:validate_cached!).with(path)
|
28
27
|
subject.install
|
29
28
|
end
|
30
29
|
end
|
31
30
|
|
32
|
-
describe
|
33
|
-
it
|
31
|
+
describe "#cached_cookbook" do
|
32
|
+
it "loads the cached cookbook at the path" do
|
34
33
|
expect(CachedCookbook).to receive(:from_path).with(path)
|
35
34
|
subject.cached_cookbook
|
36
35
|
end
|
37
36
|
end
|
38
37
|
|
39
|
-
describe
|
40
|
-
it
|
38
|
+
describe "#relative_path" do
|
39
|
+
it "returns the path to the Berksfile" do
|
41
40
|
expect(subject.relative_path).to eq(relative_path)
|
42
41
|
end
|
43
42
|
end
|
44
43
|
|
45
|
-
describe
|
46
|
-
it
|
44
|
+
describe "#expanded_path" do
|
45
|
+
it "returns the expanded path, relative to the Berksfile" do
|
47
46
|
absolute_path = Pathname.new(File.expand_path(relative_path, File.dirname(berksfile.filepath)))
|
48
47
|
expect(subject.expanded_path).to eq(absolute_path)
|
49
48
|
end
|
50
49
|
end
|
51
50
|
|
52
|
-
describe
|
53
|
-
it
|
54
|
-
this = PathLocation.new(dependency, path:
|
55
|
-
that =
|
51
|
+
describe "#==" do
|
52
|
+
it "is false when compared with a non-PathLocation" do
|
53
|
+
this = PathLocation.new(dependency, path: ".")
|
54
|
+
that = "A string"
|
56
55
|
expect(this).to_not eq(that)
|
57
56
|
end
|
58
57
|
|
59
|
-
it
|
60
|
-
this = PathLocation.new(dependency, path:
|
61
|
-
that = PathLocation.new(dependency, path:
|
58
|
+
it "is false when the metadata? is not the same" do
|
59
|
+
this = PathLocation.new(dependency, path: ".")
|
60
|
+
that = PathLocation.new(dependency, path: ".", metadata: true)
|
62
61
|
expect(this).to_not eq(that)
|
63
62
|
end
|
64
63
|
|
65
|
-
it
|
66
|
-
this = PathLocation.new(dependency, path:
|
67
|
-
that = PathLocation.new(dependency, path:
|
64
|
+
it "is false when the expanded paths are different" do
|
65
|
+
this = PathLocation.new(dependency, path: ".")
|
66
|
+
that = PathLocation.new(dependency, path: "..")
|
68
67
|
expect(this).to_not eq(that)
|
69
68
|
end
|
70
69
|
|
71
|
-
it
|
72
|
-
this = PathLocation.new(dependency, path:
|
73
|
-
that = PathLocation.new(dependency, path:
|
70
|
+
it "is true when they are the same" do
|
71
|
+
this = PathLocation.new(dependency, path: ".", metadata: true)
|
72
|
+
that = PathLocation.new(dependency, path: ".", metadata: true)
|
74
73
|
expect(this).to eq(that)
|
75
74
|
end
|
76
75
|
end
|
77
76
|
|
78
|
-
describe
|
79
|
-
it
|
80
|
-
expect(subject.to_lock).to eq <<-EOH.gsub(/^ {10}/,
|
77
|
+
describe "#to_lock" do
|
78
|
+
it "includes the path relative to the Berksfile" do
|
79
|
+
expect(subject.to_lock).to eq <<-EOH.gsub(/^ {10}/, "")
|
81
80
|
path: #{relative_path}
|
82
81
|
EOH
|
83
82
|
end
|
84
83
|
|
85
|
-
it
|
84
|
+
it "includes the metadata attribute" do
|
86
85
|
allow(subject).to receive(:metadata?).and_return(true)
|
87
|
-
expect(subject.to_lock).to eq <<-EOH.gsub(/^ {10}/,
|
86
|
+
expect(subject.to_lock).to eq <<-EOH.gsub(/^ {10}/, "")
|
88
87
|
path: #{relative_path}
|
89
88
|
metadata: true
|
90
89
|
EOH
|
91
90
|
end
|
92
91
|
end
|
93
92
|
|
94
|
-
describe
|
95
|
-
it
|
93
|
+
describe "#to_s" do
|
94
|
+
it "uses the relative path" do
|
96
95
|
expect(subject.to_s).to eq("source at #{relative_path}")
|
97
96
|
end
|
98
97
|
end
|
99
98
|
|
100
|
-
describe
|
101
|
-
it
|
99
|
+
describe "#inspect" do
|
100
|
+
it "includes the right information" do
|
102
101
|
allow(subject).to receive(:metadata?).and_return(true)
|
103
102
|
expect(subject.inspect).to eq("#<Berkshelf::PathLocation metadata: true, path: #{relative_path}>")
|
104
103
|
end
|