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,85 +1,83 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Berkshelf::Lockfile do
|
4
|
-
let(:filepath) { fixtures_path.join(
|
4
|
+
let(:filepath) { fixtures_path.join("lockfiles/default.lock").to_s }
|
5
5
|
subject { Berkshelf::Lockfile.new(filepath: filepath) }
|
6
6
|
|
7
|
-
describe
|
8
|
-
let(:lock_path) { File.absolute_path(
|
7
|
+
describe ".from_berksfile" do
|
8
|
+
let(:lock_path) { File.absolute_path("/path/to/Bacon") }
|
9
9
|
let(:berksfile) do
|
10
|
-
double(
|
11
|
-
filepath: lock_path
|
12
|
-
)
|
10
|
+
double("Berksfile",
|
11
|
+
filepath: lock_path)
|
13
12
|
end
|
14
13
|
|
15
14
|
subject { described_class.from_berksfile(berksfile) }
|
16
15
|
|
17
|
-
it
|
16
|
+
it "uses the basename of the Berksfile" do
|
18
17
|
expect(subject.filepath).to eq("#{lock_path}.lock")
|
19
18
|
end
|
20
19
|
end
|
21
20
|
|
22
|
-
describe
|
21
|
+
describe ".initialize" do
|
23
22
|
subject { described_class.new(filepath: filepath) }
|
24
23
|
|
25
|
-
it
|
24
|
+
it "sets the instance variables" do
|
26
25
|
expect(subject.filepath).to eq(filepath)
|
27
26
|
expect(subject.dependencies).to be_a(Array)
|
28
27
|
expect(subject.graph).to be_a(Berkshelf::Lockfile::Graph)
|
29
28
|
end
|
30
29
|
|
31
|
-
it
|
32
|
-
expect(subject).to have_dependency(
|
33
|
-
expect(subject).to have_dependency(
|
30
|
+
it "has the correct dependencies" do
|
31
|
+
expect(subject).to have_dependency("apt")
|
32
|
+
expect(subject).to have_dependency("jenkins")
|
34
33
|
end
|
35
34
|
end
|
36
35
|
|
37
|
-
describe
|
38
|
-
let(:parser) { double(
|
36
|
+
describe "#parse" do
|
37
|
+
let(:parser) { double("parser", run: true) }
|
39
38
|
|
40
39
|
before do
|
41
40
|
allow(Berkshelf::Lockfile::LockfileParser).to receive(:new).and_return(parser)
|
42
41
|
end
|
43
42
|
|
44
|
-
it
|
43
|
+
it "creates a new parser object" do
|
45
44
|
expect(Berkshelf::Lockfile::LockfileParser).to receive(:new).with(subject)
|
46
45
|
expect(parser).to receive(:run)
|
47
46
|
subject.parse
|
48
47
|
end
|
49
48
|
|
50
|
-
it
|
49
|
+
it "returns true (always)" do
|
51
50
|
expect(subject.parse).to be(true)
|
52
51
|
end
|
53
52
|
end
|
54
53
|
|
55
|
-
describe
|
56
|
-
it
|
54
|
+
describe "#present?" do
|
55
|
+
it "returns true when the file exists" do
|
57
56
|
expect(subject.present?).to be(true)
|
58
57
|
end
|
59
58
|
|
60
|
-
it
|
61
|
-
allow(File).to receive(:
|
59
|
+
it "returns false when the file does not exist" do
|
60
|
+
allow(File).to receive(:exist?).and_return(false)
|
62
61
|
expect(subject.present?).to be(false)
|
63
62
|
end
|
64
63
|
|
65
|
-
it
|
66
|
-
allow(File).to receive(:read).and_return(
|
64
|
+
it "returns false when the file is empty" do
|
65
|
+
allow(File).to receive(:read).and_return("")
|
67
66
|
expect(subject.present?).to be(false)
|
68
67
|
end
|
69
68
|
end
|
70
69
|
|
71
|
-
describe
|
72
|
-
it
|
73
|
-
cookbook = double(
|
74
|
-
apt = double(
|
75
|
-
name:
|
76
|
-
version_constraint: Semverse::Constraint.new(
|
77
|
-
version:
|
78
|
-
location:
|
70
|
+
describe "#trusted?" do
|
71
|
+
it "returns true when the lockfile is trusted" do
|
72
|
+
cookbook = double("apt-1.0.0", dependencies: {})
|
73
|
+
apt = double("apt",
|
74
|
+
name: "apt",
|
75
|
+
version_constraint: Semverse::Constraint.new(">= 0.0.0"),
|
76
|
+
version: "1.0.0",
|
77
|
+
location: "api",
|
79
78
|
dependencies: {},
|
80
|
-
cached_cookbook: cookbook
|
81
|
-
)
|
82
|
-
berksfile = double('berksfile', dependencies: [apt])
|
79
|
+
cached_cookbook: cookbook)
|
80
|
+
berksfile = double("berksfile", dependencies: [apt])
|
83
81
|
subject.instance_variable_set(:@berksfile, berksfile)
|
84
82
|
allow(subject).to receive(:find).with(apt).and_return(apt)
|
85
83
|
allow(subject.graph).to receive(:find).with(apt).and_return(apt)
|
@@ -87,63 +85,59 @@ describe Berkshelf::Lockfile do
|
|
87
85
|
expect(subject.trusted?).to be(true)
|
88
86
|
end
|
89
87
|
|
90
|
-
it
|
91
|
-
cookbook = double(
|
92
|
-
apt = double(
|
93
|
-
name:
|
94
|
-
version_constraint: Semverse::Constraint.new(
|
95
|
-
version:
|
96
|
-
location:
|
97
|
-
dependencies: {
|
98
|
-
cached_cookbook: cookbook
|
99
|
-
)
|
100
|
-
|
101
|
-
berksfile = double('berksfile', dependencies: [apt])
|
88
|
+
it "returns true when the lockfile is trusted with transitive dependencies" do
|
89
|
+
cookbook = double("apt-1.0.0", dependencies: { "bacon" => "1.0.0" })
|
90
|
+
apt = double("apt",
|
91
|
+
name: "apt",
|
92
|
+
version_constraint: Semverse::Constraint.new(">= 0.0.0"),
|
93
|
+
version: "1.0.0",
|
94
|
+
location: "api",
|
95
|
+
dependencies: { "bacon" => "1.0.0" },
|
96
|
+
cached_cookbook: cookbook)
|
97
|
+
bacon = double(name: "bacon", version: "1.0.0", dependencies: {})
|
98
|
+
berksfile = double("berksfile", dependencies: [apt])
|
102
99
|
subject.instance_variable_set(:@berksfile, berksfile)
|
103
100
|
allow(subject).to receive(:find).with(apt).and_return(apt)
|
104
|
-
allow(subject.graph).to receive(:find).with(
|
101
|
+
allow(subject.graph).to receive(:find).with("bacon").and_return(bacon)
|
105
102
|
allow(subject.graph).to receive(:find).with(apt).and_return(apt)
|
106
103
|
|
107
104
|
expect(subject.trusted?).to be(true)
|
108
105
|
end
|
109
106
|
|
110
|
-
it
|
111
|
-
cookbook = double(
|
112
|
-
apt = double(
|
113
|
-
name:
|
114
|
-
version_constraint: Semverse::Constraint.new(
|
115
|
-
version:
|
116
|
-
location:
|
117
|
-
dependencies: {
|
118
|
-
cached_cookbook: cookbook
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
)
|
127
|
-
berksfile = double('berksfile', dependencies: [apt])
|
107
|
+
it "returns true when the lockfile is trusted with cyclic transitive dependencies" do
|
108
|
+
cookbook = double("apt-1.0.0", dependencies: { "bacon" => "1.0.0" })
|
109
|
+
apt = double("apt",
|
110
|
+
name: "apt",
|
111
|
+
version_constraint: Semverse::Constraint.new(">= 0.0.0"),
|
112
|
+
version: "1.0.0",
|
113
|
+
location: "api",
|
114
|
+
dependencies: { "bacon" => "1.0.0" },
|
115
|
+
cached_cookbook: cookbook)
|
116
|
+
bacon = double("bacon",
|
117
|
+
name: "bacon",
|
118
|
+
version_constraint: Semverse::Constraint.new(">= 0.0.0"),
|
119
|
+
version: "1.0.0",
|
120
|
+
location: "api",
|
121
|
+
dependencies: { "apt" => "1.0.0" })
|
122
|
+
berksfile = double("berksfile", dependencies: [apt])
|
128
123
|
subject.instance_variable_set(:@berksfile, berksfile)
|
129
124
|
allow(subject).to receive(:find).with(apt).and_return(apt)
|
130
|
-
allow(subject.graph).to receive(:find).with(
|
125
|
+
allow(subject.graph).to receive(:find).with("bacon").and_return(bacon)
|
131
126
|
allow(subject.graph).to receive(:find).with(apt).and_return(apt)
|
132
127
|
|
133
128
|
expect(subject.trusted?).to be(true)
|
134
129
|
end
|
135
130
|
|
136
|
-
it
|
137
|
-
cookbook = double(
|
138
|
-
apt = double(
|
139
|
-
name:
|
140
|
-
version_constraint: Semverse::Constraint.new(
|
141
|
-
version:
|
142
|
-
location:
|
143
|
-
dependencies: {
|
144
|
-
cached_cookbook: cookbook
|
145
|
-
)
|
146
|
-
berksfile = double('berksfile', dependencies: [apt])
|
131
|
+
it "returns false when the lockfile is not trusted because of transitive dependencies" do
|
132
|
+
cookbook = double("apt-1.0.0", dependencies: { "bacon" => "1.0.0", "flip" => "2.0.0" })
|
133
|
+
apt = double("apt",
|
134
|
+
name: "apt",
|
135
|
+
version_constraint: Semverse::Constraint.new(">= 0.0.0"),
|
136
|
+
version: "1.0.0",
|
137
|
+
location: "api",
|
138
|
+
dependencies: { "bacon" => "1.0.0" },
|
139
|
+
cached_cookbook: cookbook)
|
140
|
+
berksfile = double("berksfile", dependencies: [apt])
|
147
141
|
subject.instance_variable_set(:@berksfile, berksfile)
|
148
142
|
allow(subject).to receive(:find).with(apt).and_return(apt)
|
149
143
|
allow(subject.graph).to receive(:find).with(apt).and_return(apt)
|
@@ -151,17 +145,17 @@ describe Berkshelf::Lockfile do
|
|
151
145
|
expect(subject.trusted?).to be(false)
|
152
146
|
end
|
153
147
|
|
154
|
-
it
|
155
|
-
apt = double(
|
156
|
-
berksfile = double(
|
148
|
+
it "returns false if the dependency is not in the lockfile" do
|
149
|
+
apt = double("apt", name: "apt", version_constraint: nil)
|
150
|
+
berksfile = double("berksfile", dependencies: [apt])
|
157
151
|
subject.instance_variable_set(:@berksfile, berksfile)
|
158
152
|
|
159
153
|
expect(subject.trusted?).to be(false)
|
160
154
|
end
|
161
155
|
|
162
|
-
it
|
163
|
-
apt = double(
|
164
|
-
berksfile = double(
|
156
|
+
it "returns false if the dependency is not in the graph" do
|
157
|
+
apt = double("apt", name: "apt", version_constraint: nil)
|
158
|
+
berksfile = double("berksfile", dependencies: [apt])
|
165
159
|
subject.instance_variable_set(:@berksfile, berksfile)
|
166
160
|
allow(subject).to receive(:find).with(apt).and_return(true)
|
167
161
|
allow(subject.graph).to receive(:find).with(apt).and_return(nil)
|
@@ -169,17 +163,16 @@ describe Berkshelf::Lockfile do
|
|
169
163
|
expect(subject.trusted?).to be(false)
|
170
164
|
end
|
171
165
|
|
172
|
-
it
|
173
|
-
cookbook = double(
|
174
|
-
apt = double(
|
175
|
-
name:
|
176
|
-
version_constraint: Semverse::Constraint.new(
|
177
|
-
version:
|
178
|
-
location:
|
166
|
+
it "returns false if the constraint is not satisfied" do
|
167
|
+
cookbook = double("apt-1.0.0", dependencies: {})
|
168
|
+
apt = double("apt",
|
169
|
+
name: "apt",
|
170
|
+
version_constraint: Semverse::Constraint.new("< 1.0.0"),
|
171
|
+
version: "1.0.0",
|
172
|
+
location: "api",
|
179
173
|
dependencies: {},
|
180
|
-
cached_cookbook: cookbook
|
181
|
-
)
|
182
|
-
berksfile = double('berksfile', dependencies: [apt])
|
174
|
+
cached_cookbook: cookbook)
|
175
|
+
berksfile = double("berksfile", dependencies: [apt])
|
183
176
|
subject.instance_variable_set(:@berksfile, berksfile)
|
184
177
|
allow(subject).to receive(:find).with(apt).and_return(apt)
|
185
178
|
allow(subject.graph).to receive(:find).with(apt).and_return(apt)
|
@@ -187,20 +180,19 @@ describe Berkshelf::Lockfile do
|
|
187
180
|
expect(subject.trusted?).to be(false)
|
188
181
|
end
|
189
182
|
|
190
|
-
it
|
191
|
-
cookbook = double(
|
192
|
-
apt = double(
|
193
|
-
name:
|
194
|
-
version_constraint: Semverse::Constraint.new(
|
195
|
-
version:
|
196
|
-
location:
|
183
|
+
it "returns false if the locations are different" do
|
184
|
+
cookbook = double("apt-1.0.0", dependencies: {})
|
185
|
+
apt = double("apt",
|
186
|
+
name: "apt",
|
187
|
+
version_constraint: Semverse::Constraint.new("< 1.0.0"),
|
188
|
+
version: "1.0.0",
|
189
|
+
location: "api",
|
197
190
|
dependencies: {},
|
198
|
-
cached_cookbook: cookbook
|
199
|
-
)
|
191
|
+
cached_cookbook: cookbook)
|
200
192
|
apt_master = apt.dup
|
201
|
-
allow(apt_master).to receive_messages(location:
|
193
|
+
allow(apt_master).to receive_messages(location: "github")
|
202
194
|
allow(apt_master).to receive_messages(cached_cookbook: cookbook)
|
203
|
-
berksfile = double(
|
195
|
+
berksfile = double("berksfile", dependencies: [apt])
|
204
196
|
subject.instance_variable_set(:@berksfile, berksfile)
|
205
197
|
allow(subject).to receive(:find).with(apt).and_return(apt_master)
|
206
198
|
allow(subject.graph).to receive(:find).with(apt).and_return(apt)
|
@@ -209,169 +201,172 @@ describe Berkshelf::Lockfile do
|
|
209
201
|
end
|
210
202
|
end
|
211
203
|
|
212
|
-
describe
|
204
|
+
describe "#apply" do
|
213
205
|
before do
|
214
|
-
|
215
|
-
|
216
|
-
|
206
|
+
apt = double(name: "apt", locked_version: "1.0.0")
|
207
|
+
jenkins = double(name: "jenkins", locked_version: "1.4.5")
|
208
|
+
allow(subject.graph).to receive(:locks).and_return("apt" => apt, "jenkins" => jenkins)
|
217
209
|
end
|
218
210
|
|
219
|
-
describe
|
220
|
-
let(:connection) { double(
|
211
|
+
describe "when :envfile option is not used" do
|
212
|
+
let(:connection) { double("connection") }
|
221
213
|
|
222
214
|
before do
|
223
215
|
allow(Berkshelf).to receive(:ridley_connection).and_yield(connection)
|
224
216
|
end
|
225
217
|
|
226
|
-
context
|
227
|
-
it
|
228
|
-
allow(connection).to receive(:
|
229
|
-
expect
|
230
|
-
subject.apply(
|
231
|
-
|
218
|
+
context "when the Chef environment does not exist" do
|
219
|
+
it "raises an exception" do
|
220
|
+
allow(connection).to receive(:get).and_raise(Berkshelf::APIClient::ServiceNotFound)
|
221
|
+
expect do
|
222
|
+
subject.apply("production")
|
223
|
+
end.to raise_error(Berkshelf::EnvironmentNotFound)
|
232
224
|
end
|
233
225
|
end
|
234
226
|
|
235
|
-
it
|
236
|
-
environment =
|
237
|
-
|
227
|
+
it "locks the environment cookbook versions on chef server" do
|
228
|
+
environment = instance_double(Chef::Environment)
|
229
|
+
env_hash = double(Hash)
|
230
|
+
expect(connection).to receive(:get).with("environments/production").and_return(env_hash)
|
231
|
+
expect(Chef::Environment).to receive(:from_hash).with(env_hash).and_return(environment)
|
238
232
|
|
239
|
-
expect(environment).to receive(:cookbook_versions
|
240
|
-
|
241
|
-
|
233
|
+
expect(environment).to receive(:cookbook_versions).with(
|
234
|
+
{"apt" => "= 1.0.0",
|
235
|
+
"jenkins" => "= 1.4.5"}
|
242
236
|
)
|
243
237
|
|
244
|
-
|
238
|
+
expect(environment).to receive(:save)
|
239
|
+
subject.apply("production")
|
245
240
|
end
|
246
241
|
end
|
247
|
-
|
248
|
-
describe
|
249
|
-
it
|
250
|
-
locks = {
|
251
|
-
|
252
|
-
|
253
|
-
}
|
254
|
-
|
255
|
-
expect(subject).to receive(:update_environment_file).with(
|
256
|
-
|
257
|
-
|
242
|
+
|
243
|
+
describe "when :envfile option is used" do
|
244
|
+
it "locks the environment cookbook version into envfile" do
|
245
|
+
locks = {
|
246
|
+
"apt" => "= 1.0.0",
|
247
|
+
"jenkins" => "= 1.4.5",
|
248
|
+
}
|
249
|
+
|
250
|
+
expect(subject).to receive(:update_environment_file).with("/working/path", locks)
|
251
|
+
|
252
|
+
subject.apply("production", envfile: "/working/path")
|
258
253
|
end
|
259
254
|
end
|
260
255
|
end
|
261
256
|
|
262
|
-
describe
|
263
|
-
it
|
257
|
+
describe "#dependencies" do
|
258
|
+
it "returns an array" do
|
264
259
|
expect(subject.dependencies).to be_a(Array)
|
265
260
|
end
|
266
261
|
end
|
267
262
|
|
268
|
-
describe
|
269
|
-
it
|
270
|
-
expect(subject.find(
|
263
|
+
describe "#find" do
|
264
|
+
it "returns a matching cookbook" do
|
265
|
+
expect(subject.find("apt").name).to eq("apt")
|
271
266
|
end
|
272
267
|
|
273
|
-
it
|
274
|
-
expect(subject.find(
|
268
|
+
it "returns nil for a missing cookbook" do
|
269
|
+
expect(subject.find("foo")).to be_nil
|
275
270
|
end
|
276
271
|
end
|
277
272
|
|
278
|
-
describe
|
279
|
-
it
|
280
|
-
expect(subject).to have_dependency(
|
273
|
+
describe "#has_dependency?" do
|
274
|
+
it "returns true if a matching cookbook is found" do
|
275
|
+
expect(subject).to have_dependency("apt")
|
281
276
|
end
|
282
277
|
|
283
|
-
it
|
284
|
-
expect(subject).to_not have_dependency(
|
278
|
+
it "returns false if no matching cookbook is found" do
|
279
|
+
expect(subject).to_not have_dependency("foo")
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
describe "#add" do
|
284
|
+
it "adds the dependency to the lockfile" do
|
285
|
+
subject.add("apache2")
|
286
|
+
expect(subject).to have_dependency("apache2")
|
285
287
|
end
|
286
288
|
end
|
287
289
|
|
288
|
-
describe
|
289
|
-
it
|
290
|
-
|
291
|
-
expect
|
290
|
+
describe "#update_environment_file" do
|
291
|
+
it "raises an exception when environment file does not exist" do
|
292
|
+
allow(File).to receive(:exist?).and_return(false)
|
293
|
+
expect do
|
294
|
+
subject.update_environment_file("/broken/path", nil)
|
295
|
+
end.to raise_error(Berkshelf::EnvironmentFileNotFound)
|
296
|
+
end
|
297
|
+
|
298
|
+
it "updates the environment file with cookbook versions" do
|
299
|
+
file = instance_spy("File")
|
300
|
+
locks = {
|
301
|
+
"apt" => "1.0.0",
|
302
|
+
"jenkins" => "1.4.5",
|
303
|
+
}
|
304
|
+
|
305
|
+
allow(File).to receive(:exist?).and_return(true)
|
306
|
+
allow(File).to receive(:read).and_return("{}")
|
307
|
+
allow(File).to receive(:open).and_yield(file)
|
308
|
+
|
309
|
+
subject.update_environment_file("/working/path.json", locks)
|
310
|
+
|
311
|
+
expect(file).to have_received(:puts) do |arg|
|
312
|
+
expect(JSON.parse(arg)).to eq({
|
313
|
+
"cookbook_versions" => locks,
|
314
|
+
})
|
315
|
+
end
|
292
316
|
end
|
293
317
|
end
|
294
318
|
|
295
|
-
describe
|
296
|
-
it
|
297
|
-
allow(File).to receive(:exists?).and_return(false)
|
298
|
-
expect {
|
299
|
-
subject.update_environment_file('/broken/path', nil)
|
300
|
-
}.to raise_error(Berkshelf::EnvironmentFileNotFound)
|
301
|
-
end
|
302
|
-
|
303
|
-
it 'updates the environment file with cookbook versions' do
|
304
|
-
file = instance_spy('File')
|
305
|
-
locks = {
|
306
|
-
'apt' => '1.0.0',
|
307
|
-
'jenkins' => '1.4.5'
|
308
|
-
}
|
309
|
-
|
310
|
-
allow(File).to receive(:exists?).and_return(true)
|
311
|
-
allow(File).to receive(:read).and_return("{}")
|
312
|
-
allow(File).to receive(:open).and_yield(file)
|
313
|
-
|
314
|
-
subject.update_environment_file('/working/path.json', locks)
|
315
|
-
|
316
|
-
expect(file).to have_received(:puts) do |arg|
|
317
|
-
expect(JSON.parse(arg)).to eq({
|
318
|
-
'cookbook_versions' => locks
|
319
|
-
})
|
320
|
-
end
|
321
|
-
end
|
322
|
-
end
|
323
|
-
|
324
|
-
describe '#update' do
|
325
|
-
it 'resets the dependencies' do
|
319
|
+
describe "#update" do
|
320
|
+
it "resets the dependencies" do
|
326
321
|
subject.update([])
|
327
322
|
expect(subject.dependencies).to be_empty
|
328
323
|
end
|
329
324
|
|
330
|
-
it
|
331
|
-
subject.update([
|
332
|
-
expect(subject).to have_dependency(
|
325
|
+
it "appends each of the dependencies" do
|
326
|
+
subject.update(["apache2"])
|
327
|
+
expect(subject).to have_dependency("apache2")
|
333
328
|
end
|
334
329
|
end
|
335
330
|
|
336
|
-
describe
|
337
|
-
it
|
338
|
-
subject.add(
|
339
|
-
subject.unlock(
|
340
|
-
expect(subject).to_not have_dependency(
|
331
|
+
describe "#unlock" do
|
332
|
+
it "removes the dependency from the graph" do
|
333
|
+
subject.add("apache2")
|
334
|
+
subject.unlock("apache2")
|
335
|
+
expect(subject).to_not have_dependency("apache2")
|
341
336
|
end
|
342
337
|
end
|
343
338
|
|
344
|
-
describe
|
345
|
-
let(:berksfile_path) { fixtures_path.join(
|
339
|
+
describe "#reduce!" do
|
340
|
+
let(:berksfile_path) { fixtures_path.join("berksfiles/default").to_s }
|
346
341
|
let(:berksfile) { Berkshelf::Berksfile.from_file(berksfile_path) }
|
347
342
|
|
348
|
-
describe
|
349
|
-
let(:orphans_lock) { fixtures_path.join(
|
343
|
+
describe "with some orphan dependencies" do
|
344
|
+
let(:orphans_lock) { fixtures_path.join("lockfiles/orphans.lock").to_s }
|
350
345
|
subject { Berkshelf::Lockfile.new(filepath: orphans_lock, berksfile: berksfile) }
|
351
346
|
|
352
|
-
it
|
347
|
+
it "removes orphan dependencies" do
|
353
348
|
graph = subject.graph.instance_variable_get(:@graph)
|
354
|
-
expect(graph).to receive(:delete).with(
|
355
|
-
expect(graph).to receive(:delete).with(
|
356
|
-
expect(graph).to receive(:delete).with(
|
349
|
+
expect(graph).to receive(:delete).with("yum-epel").and_call_original
|
350
|
+
expect(graph).to receive(:delete).with("zum-foo").and_call_original
|
351
|
+
expect(graph).to receive(:delete).with("yum").and_call_original
|
357
352
|
subject.reduce!
|
358
353
|
end
|
359
354
|
end
|
360
355
|
|
361
|
-
describe
|
356
|
+
describe "minimizes updates" do
|
362
357
|
subject { Berkshelf::Lockfile.new(filepath: filepath, berksfile: berksfile) }
|
363
358
|
|
364
359
|
before(:each) do
|
365
|
-
cs = fixtures_path.join(
|
360
|
+
cs = fixtures_path.join("cookbook-store")
|
366
361
|
allow(Berkshelf::CookbookStore.instance).to receive(:storage_path).and_return(cs)
|
367
362
|
end
|
368
363
|
|
369
|
-
it
|
364
|
+
it "uses the cookbook version specified in the lockfile" do
|
370
365
|
subject.reduce!
|
371
|
-
expect(subject.berksfile.dependencies[1].cached_cookbook.version).to eq(
|
366
|
+
expect(subject.berksfile.dependencies[1].cached_cookbook.version).to eq("2.0.3")
|
372
367
|
end
|
373
368
|
|
374
|
-
it
|
369
|
+
it "does not remove locks unnecessarily" do
|
375
370
|
expect(subject).to_not receive(:unlock)
|
376
371
|
subject.reduce!
|
377
372
|
end
|
@@ -380,18 +375,17 @@ describe Berkshelf::Lockfile do
|
|
380
375
|
end
|
381
376
|
|
382
377
|
describe Berkshelf::Lockfile::Graph do
|
383
|
-
let(:filepath) { fixtures_path.join(
|
378
|
+
let(:filepath) { fixtures_path.join("lockfiles/empty.lock").to_s }
|
384
379
|
let(:lockfile) { Berkshelf::Lockfile.new(filepath: filepath) }
|
385
380
|
subject { described_class.new(lockfile) }
|
386
381
|
|
387
|
-
describe
|
388
|
-
it
|
389
|
-
cookbook = double(
|
390
|
-
name:
|
391
|
-
version:
|
392
|
-
cookbook_name:
|
393
|
-
dependencies: {}
|
394
|
-
)
|
382
|
+
describe "#update" do
|
383
|
+
it "uses cookbook_name as GraphItem name" do
|
384
|
+
cookbook = double("test",
|
385
|
+
name: "test-0.0.1",
|
386
|
+
version: "0.0.1",
|
387
|
+
cookbook_name: "test",
|
388
|
+
dependencies: {})
|
395
389
|
subject.update([cookbook])
|
396
390
|
|
397
391
|
expect(subject.locks.keys).to include(cookbook.cookbook_name)
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Berkshelf::Logger do
|
4
|
-
%w
|
4
|
+
%w{info warn error fatal debug deprecate exception}.each do |meth|
|
5
5
|
describe "##{meth}" do
|
6
|
-
it
|
6
|
+
it "responds" do
|
7
7
|
expect(subject).to respond_to(meth.to_sym)
|
8
8
|
end
|
9
9
|
end
|
@@ -1,18 +1,18 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Berkshelf::Mixin::Logging do
|
4
4
|
subject do
|
5
5
|
Class.new { include Berkshelf::Mixin::Logging }.new
|
6
6
|
end
|
7
7
|
|
8
|
-
describe
|
9
|
-
it
|
8
|
+
describe "#logger" do
|
9
|
+
it "returns the Berkshelf::Logger" do
|
10
10
|
expect(subject.logger).to be_a(Berkshelf::Logger)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
describe
|
15
|
-
it
|
14
|
+
describe "#log" do
|
15
|
+
it "returns the Berkshelf::Logger" do
|
16
16
|
expect(subject.log).to be_a(Berkshelf::Logger)
|
17
17
|
end
|
18
18
|
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Berkshelf::Packager do
|
4
4
|
let(:target) { tmp_path.join("cookbooks.tar.gz").to_s }
|
5
5
|
subject { described_class.new(target) }
|
6
6
|
|
7
|
-
it
|
7
|
+
it "has the correct out_file" do
|
8
8
|
expect(subject.out_file).to eq(target)
|
9
9
|
end
|
10
10
|
|