berkshelf 5.5.0 → 5.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -3
- data/Gemfile +31 -31
- data/Gemfile.lock +3 -3
- data/Guardfile +13 -13
- data/Rakefile +1 -0
- data/Thorfile +16 -16
- data/berkshelf.gemspec +35 -35
- data/features/step_definitions/chef/config_steps.rb +4 -4
- data/features/step_definitions/chef_server_steps.rb +6 -6
- data/features/step_definitions/cli_steps.rb +3 -3
- data/features/step_definitions/config_steps.rb +5 -5
- data/features/step_definitions/filesystem_steps.rb +12 -11
- data/features/support/env.rb +21 -21
- data/lib/berkshelf.rb +66 -66
- data/lib/berkshelf/base_generator.rb +10 -11
- data/lib/berkshelf/berksfile.rb +38 -38
- data/lib/berkshelf/cached_cookbook.rb +7 -7
- data/lib/berkshelf/cli.rb +126 -126
- data/lib/berkshelf/commands/shelf.rb +19 -18
- data/lib/berkshelf/commands/test_command.rb +2 -2
- data/lib/berkshelf/community_rest.rb +38 -38
- data/lib/berkshelf/config.rb +42 -41
- data/lib/berkshelf/cookbook_generator.rb +38 -38
- data/lib/berkshelf/cookbook_store.rb +4 -4
- data/lib/berkshelf/core_ext/file_utils.rb +1 -1
- data/lib/berkshelf/dependency.rb +23 -21
- data/lib/berkshelf/downloader.rb +24 -25
- data/lib/berkshelf/errors.rb +17 -17
- data/lib/berkshelf/file_syncer.rb +9 -8
- data/lib/berkshelf/formatters/human.rb +3 -3
- data/lib/berkshelf/formatters/json.rb +2 -2
- data/lib/berkshelf/init_generator.rb +64 -64
- data/lib/berkshelf/installer.rb +103 -102
- data/lib/berkshelf/location.rb +9 -9
- data/lib/berkshelf/locations/git.rb +16 -16
- data/lib/berkshelf/locations/github.rb +1 -1
- data/lib/berkshelf/locations/path.rb +2 -2
- data/lib/berkshelf/lockfile.rb +309 -315
- data/lib/berkshelf/mixin/git.rb +3 -3
- data/lib/berkshelf/packager.rb +4 -4
- data/lib/berkshelf/resolver.rb +2 -2
- data/lib/berkshelf/resolver/graph.rb +1 -1
- data/lib/berkshelf/shell.rb +1 -1
- data/lib/berkshelf/source.rb +6 -6
- data/lib/berkshelf/source_uri.rb +2 -2
- data/lib/berkshelf/ssl_policies.rb +3 -3
- data/lib/berkshelf/thor.rb +1 -1
- data/lib/berkshelf/uploader.rb +48 -48
- data/lib/berkshelf/validator.rb +2 -2
- data/lib/berkshelf/version.rb +1 -1
- data/lib/berkshelf/visualizer.rb +11 -11
- data/spec/config/knife.rb +2 -2
- data/spec/fixtures/Berksfile +3 -3
- data/spec/fixtures/cookbook-path/jenkins-config/metadata.rb +3 -3
- 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-0.5.0/metadata.rb +3 -3
- data/spec/fixtures/cookbooks/example_cookbook/metadata.rb +3 -3
- data/spec/spec_helper.rb +9 -9
- data/spec/support/chef_api.rb +11 -12
- data/spec/support/chef_server.rb +10 -10
- data/spec/support/git.rb +23 -23
- data/spec/support/kitchen.rb +2 -2
- data/spec/support/matchers/filepath_matchers.rb +2 -2
- data/spec/support/path_helpers.rb +12 -12
- data/spec/support/shared_examples/formatter.rb +1 -1
- data/spec/unit/berkshelf/berksfile_spec.rb +78 -78
- data/spec/unit/berkshelf/cached_cookbook_spec.rb +42 -42
- data/spec/unit/berkshelf/cli_spec.rb +6 -6
- data/spec/unit/berkshelf/community_rest_spec.rb +83 -83
- data/spec/unit/berkshelf/config_spec.rb +13 -13
- data/spec/unit/berkshelf/cookbook_generator_spec.rb +39 -39
- data/spec/unit/berkshelf/cookbook_store_spec.rb +41 -41
- data/spec/unit/berkshelf/core_ext/file_utils_spec.rb +5 -6
- data/spec/unit/berkshelf/core_ext/pathname_spec.rb +1 -1
- data/spec/unit/berkshelf/dependency_spec.rb +43 -43
- data/spec/unit/berkshelf/downloader_spec.rb +20 -20
- data/spec/unit/berkshelf/errors_spec.rb +3 -3
- data/spec/unit/berkshelf/file_syncer_spec.rb +86 -86
- 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/init_generator_spec.rb +92 -92
- 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 -35
- data/spec/unit/berkshelf/locations/git_spec.rb +87 -87
- data/spec/unit/berkshelf/locations/path_spec.rb +40 -40
- data/spec/unit/berkshelf/lockfile_parser_spec.rb +71 -71
- data/spec/unit/berkshelf/lockfile_spec.rb +197 -197
- 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 +1 -1
- data/spec/unit/berkshelf/resolver_spec.rb +17 -17
- data/spec/unit/berkshelf/shell_spec.rb +34 -34
- data/spec/unit/berkshelf/source_spec.rb +12 -11
- data/spec/unit/berkshelf/source_uri_spec.rb +1 -1
- data/spec/unit/berkshelf/ssl_policies_spec.rb +25 -25
- data/spec/unit/berkshelf/uploader_spec.rb +54 -54
- data/spec/unit/berkshelf/validator_spec.rb +16 -16
- data/spec/unit/berkshelf/visualizer_spec.rb +17 -17
- data/spec/unit/berkshelf_spec.rb +18 -18
- metadata +5 -5
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Berkshelf::Lockfile do
|
4
4
|
before do
|
@@ -6,127 +6,127 @@ describe Berkshelf::Lockfile do
|
|
6
6
|
subject.parse
|
7
7
|
end
|
8
8
|
|
9
|
-
context
|
10
|
-
let(:fixture) { fixtures_path.join(
|
9
|
+
context "with an old 2.0 lockfile format" do
|
10
|
+
let(:fixture) { fixtures_path.join("lockfiles/2.0.lock") }
|
11
11
|
|
12
|
-
it
|
12
|
+
it "does not blow up" do
|
13
13
|
expect { subject }.to_not raise_error
|
14
14
|
end
|
15
15
|
|
16
|
-
it
|
16
|
+
it "warns the user" do
|
17
17
|
expect(Berkshelf.formatter).to receive(:warn)
|
18
18
|
subject.parse
|
19
19
|
end
|
20
20
|
|
21
|
-
it
|
22
|
-
expect(subject).to have_dependency(
|
23
|
-
expect(subject).to have_dependency(
|
24
|
-
expect(subject).to have_dependency(
|
25
|
-
expect(subject).to have_dependency(
|
26
|
-
|
27
|
-
expect(subject.find(
|
28
|
-
expect(subject.find(
|
29
|
-
expect(subject.find(
|
30
|
-
expect(subject.find(
|
31
|
-
|
32
|
-
expect(subject.find(
|
33
|
-
expect(subject.find(
|
34
|
-
expect(subject.find(
|
35
|
-
expect(subject.find(
|
21
|
+
it "sets the dependencies" do
|
22
|
+
expect(subject).to have_dependency("apt")
|
23
|
+
expect(subject).to have_dependency("jenkins")
|
24
|
+
expect(subject).to have_dependency("runit")
|
25
|
+
expect(subject).to have_dependency("yum")
|
26
|
+
|
27
|
+
expect(subject.find("apt").version_constraint.to_s).to eq(">= 0.0.0")
|
28
|
+
expect(subject.find("jenkins").version_constraint.to_s).to eq(">= 0.0.0")
|
29
|
+
expect(subject.find("runit").version_constraint.to_s).to eq(">= 0.0.0")
|
30
|
+
expect(subject.find("yum").version_constraint.to_s).to eq(">= 0.0.0")
|
31
|
+
|
32
|
+
expect(subject.find("apt").locked_version.to_s).to eq("2.3.6")
|
33
|
+
expect(subject.find("jenkins").locked_version.to_s).to eq("2.0.3")
|
34
|
+
expect(subject.find("runit").locked_version.to_s).to eq("1.5.8")
|
35
|
+
expect(subject.find("yum").locked_version.to_s).to eq("3.0.6")
|
36
36
|
end
|
37
37
|
|
38
|
-
it
|
38
|
+
it "sets the graph" do
|
39
39
|
graph = subject.graph
|
40
40
|
|
41
|
-
expect(graph).to have_lock(
|
42
|
-
expect(graph).to have_lock(
|
43
|
-
expect(graph).to have_lock(
|
44
|
-
expect(graph).to have_lock(
|
41
|
+
expect(graph).to have_lock("apt")
|
42
|
+
expect(graph).to have_lock("jenkins")
|
43
|
+
expect(graph).to have_lock("runit")
|
44
|
+
expect(graph).to have_lock("yum")
|
45
45
|
|
46
|
-
expect(graph.find(
|
47
|
-
expect(graph.find(
|
48
|
-
expect(graph.find(
|
49
|
-
expect(graph.find(
|
46
|
+
expect(graph.find("apt").version).to eq("2.3.6")
|
47
|
+
expect(graph.find("jenkins").version).to eq("2.0.3")
|
48
|
+
expect(graph.find("runit").version).to eq("1.5.8")
|
49
|
+
expect(graph.find("yum").version).to eq("3.0.6")
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
context
|
54
|
-
let(:fixture) { fixtures_path.join(
|
53
|
+
context "with a blank lockfile" do
|
54
|
+
let(:fixture) { fixtures_path.join("lockfiles/blank.lock") }
|
55
55
|
|
56
|
-
it
|
56
|
+
it "warns the user" do
|
57
57
|
expect(Berkshelf.formatter).to receive(:warn)
|
58
58
|
subject.parse
|
59
59
|
end
|
60
60
|
|
61
|
-
it
|
61
|
+
it "sets an empty list of dependencies" do
|
62
62
|
expect(subject.dependencies).to be_empty
|
63
63
|
end
|
64
64
|
|
65
|
-
it
|
65
|
+
it "sets an empty graph" do
|
66
66
|
expect(subject.graph.locks).to be_empty
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
-
context
|
71
|
-
let(:fixture) { fixtures_path.join(
|
70
|
+
context "with an empty lockfile" do
|
71
|
+
let(:fixture) { fixtures_path.join("lockfiles/empty.lock") }
|
72
72
|
|
73
|
-
it
|
73
|
+
it "does not warn the user" do
|
74
74
|
expect(Berkshelf.formatter).to_not receive(:warn)
|
75
75
|
subject.parse
|
76
76
|
end
|
77
77
|
|
78
|
-
it
|
78
|
+
it "sets an empty list of dependencies" do
|
79
79
|
expect(subject.dependencies).to be_empty
|
80
80
|
end
|
81
81
|
|
82
|
-
it
|
82
|
+
it "sets an empty graph" do
|
83
83
|
expect(subject.graph.locks).to be_empty
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
|
-
context
|
88
|
-
let(:fixture) { fixtures_path.join(
|
87
|
+
context "with real lockfile" do
|
88
|
+
let(:fixture) { fixtures_path.join("lockfiles/default.lock") }
|
89
89
|
|
90
|
-
it
|
91
|
-
expect(subject).to have_dependency(
|
92
|
-
expect(subject).to have_dependency(
|
90
|
+
it "sets the dependencies" do
|
91
|
+
expect(subject).to have_dependency("apt")
|
92
|
+
expect(subject).to have_dependency("jenkins")
|
93
93
|
|
94
|
-
expect(subject.find(
|
95
|
-
expect(subject.find(
|
94
|
+
expect(subject.find("apt").version_constraint.to_s).to eq("~> 2.0")
|
95
|
+
expect(subject.find("jenkins").version_constraint.to_s).to eq("~> 2.0")
|
96
96
|
|
97
|
-
expect(subject.find(
|
98
|
-
expect(subject.find(
|
97
|
+
expect(subject.find("apt").locked_version.to_s).to eq("2.3.6")
|
98
|
+
expect(subject.find("jenkins").locked_version.to_s).to eq("2.0.3")
|
99
99
|
end
|
100
100
|
|
101
|
-
it
|
101
|
+
it "sets the graph" do
|
102
102
|
graph = subject.graph
|
103
103
|
|
104
|
-
expect(graph).to have_lock(
|
105
|
-
expect(graph).to have_lock(
|
106
|
-
expect(graph).to have_lock(
|
107
|
-
expect(graph).to have_lock(
|
108
|
-
expect(graph).to have_lock(
|
109
|
-
expect(graph).to have_lock(
|
110
|
-
|
111
|
-
expect(graph.find(
|
112
|
-
expect(graph.find(
|
113
|
-
expect(graph.find(
|
114
|
-
expect(graph.find(
|
115
|
-
expect(graph.find(
|
116
|
-
expect(graph.find(
|
104
|
+
expect(graph).to have_lock("apt")
|
105
|
+
expect(graph).to have_lock("build-essential")
|
106
|
+
expect(graph).to have_lock("jenkins")
|
107
|
+
expect(graph).to have_lock("runit")
|
108
|
+
expect(graph).to have_lock("yum")
|
109
|
+
expect(graph).to have_lock("yum-epel")
|
110
|
+
|
111
|
+
expect(graph.find("apt").version).to eq("2.3.6")
|
112
|
+
expect(graph.find("build-essential").version).to eq("1.4.2")
|
113
|
+
expect(graph.find("jenkins").version).to eq("2.0.3")
|
114
|
+
expect(graph.find("runit").version).to eq("1.5.8")
|
115
|
+
expect(graph.find("yum").version).to eq("3.0.6")
|
116
|
+
expect(graph.find("yum-epel").version).to eq("0.2.0")
|
117
117
|
end
|
118
118
|
|
119
|
-
it
|
120
|
-
jenkins = subject.graph.find(
|
121
|
-
runit = subject.graph.find(
|
119
|
+
it "sets the graph item dependencies" do
|
120
|
+
jenkins = subject.graph.find("jenkins")
|
121
|
+
runit = subject.graph.find("runit")
|
122
122
|
|
123
|
-
expect(jenkins.dependencies).to include(
|
124
|
-
expect(jenkins.dependencies).to include(
|
125
|
-
expect(jenkins.dependencies).to include(
|
123
|
+
expect(jenkins.dependencies).to include("apt" => "~> 2.0")
|
124
|
+
expect(jenkins.dependencies).to include("runit" => "~> 1.5")
|
125
|
+
expect(jenkins.dependencies).to include("yum" => "~> 3.0")
|
126
126
|
|
127
|
-
expect(runit.dependencies).to include(
|
128
|
-
expect(runit.dependencies).to include(
|
129
|
-
expect(runit.dependencies).to include(
|
127
|
+
expect(runit.dependencies).to include("build-essential" => ">= 0.0.0")
|
128
|
+
expect(runit.dependencies).to include("yum" => "~> 3.0")
|
129
|
+
expect(runit.dependencies).to include("yum-epel" => ">= 0.0.0")
|
130
130
|
end
|
131
131
|
end
|
132
132
|
end
|
@@ -1,85 +1,85 @@
|
|
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
|
10
|
+
double("Berksfile",
|
11
|
+
filepath: lock_path
|
12
12
|
)
|
13
13
|
end
|
14
14
|
|
15
15
|
subject { described_class.from_berksfile(berksfile) }
|
16
16
|
|
17
|
-
it
|
17
|
+
it "uses the basename of the Berksfile" do
|
18
18
|
expect(subject.filepath).to eq("#{lock_path}.lock")
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
describe
|
22
|
+
describe ".initialize" do
|
23
23
|
subject { described_class.new(filepath: filepath) }
|
24
24
|
|
25
|
-
it
|
25
|
+
it "sets the instance variables" do
|
26
26
|
expect(subject.filepath).to eq(filepath)
|
27
27
|
expect(subject.dependencies).to be_a(Array)
|
28
28
|
expect(subject.graph).to be_a(Berkshelf::Lockfile::Graph)
|
29
29
|
end
|
30
30
|
|
31
|
-
it
|
32
|
-
expect(subject).to have_dependency(
|
33
|
-
expect(subject).to have_dependency(
|
31
|
+
it "has the correct dependencies" do
|
32
|
+
expect(subject).to have_dependency("apt")
|
33
|
+
expect(subject).to have_dependency("jenkins")
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
describe
|
38
|
-
let(:parser) { double(
|
37
|
+
describe "#parse" do
|
38
|
+
let(:parser) { double("parser", run: true) }
|
39
39
|
|
40
40
|
before do
|
41
41
|
allow(Berkshelf::Lockfile::LockfileParser).to receive(:new).and_return(parser)
|
42
42
|
end
|
43
43
|
|
44
|
-
it
|
44
|
+
it "creates a new parser object" do
|
45
45
|
expect(Berkshelf::Lockfile::LockfileParser).to receive(:new).with(subject)
|
46
46
|
expect(parser).to receive(:run)
|
47
47
|
subject.parse
|
48
48
|
end
|
49
49
|
|
50
|
-
it
|
50
|
+
it "returns true (always)" do
|
51
51
|
expect(subject.parse).to be(true)
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
describe
|
56
|
-
it
|
55
|
+
describe "#present?" do
|
56
|
+
it "returns true when the file exists" do
|
57
57
|
expect(subject.present?).to be(true)
|
58
58
|
end
|
59
59
|
|
60
|
-
it
|
60
|
+
it "returns false when the file does not exist" do
|
61
61
|
allow(File).to receive(:exists?).and_return(false)
|
62
62
|
expect(subject.present?).to be(false)
|
63
63
|
end
|
64
64
|
|
65
|
-
it
|
66
|
-
allow(File).to receive(:read).and_return(
|
65
|
+
it "returns false when the file is empty" do
|
66
|
+
allow(File).to receive(:read).and_return("")
|
67
67
|
expect(subject.present?).to be(false)
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
-
describe
|
72
|
-
it
|
73
|
-
cookbook = double(
|
74
|
-
apt = double(
|
75
|
-
name:
|
76
|
-
version_constraint: Semverse::Constraint.new(
|
77
|
-
version:
|
78
|
-
location:
|
71
|
+
describe "#trusted?" do
|
72
|
+
it "returns true when the lockfile is trusted" do
|
73
|
+
cookbook = double("apt-1.0.0", dependencies: {})
|
74
|
+
apt = double("apt",
|
75
|
+
name: "apt",
|
76
|
+
version_constraint: Semverse::Constraint.new(">= 0.0.0"),
|
77
|
+
version: "1.0.0",
|
78
|
+
location: "api",
|
79
79
|
dependencies: {},
|
80
|
-
cached_cookbook: cookbook
|
80
|
+
cached_cookbook: cookbook
|
81
81
|
)
|
82
|
-
berksfile = double(
|
82
|
+
berksfile = double("berksfile", dependencies: [apt])
|
83
83
|
subject.instance_variable_set(:@berksfile, berksfile)
|
84
84
|
allow(subject).to receive(:find).with(apt).and_return(apt)
|
85
85
|
allow(subject.graph).to receive(:find).with(apt).and_return(apt)
|
@@ -87,63 +87,63 @@ describe Berkshelf::Lockfile do
|
|
87
87
|
expect(subject.trusted?).to be(true)
|
88
88
|
end
|
89
89
|
|
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
|
90
|
+
it "returns true when the lockfile is trusted with transitive dependencies" do
|
91
|
+
cookbook = double("apt-1.0.0", dependencies: { "bacon" => "1.0.0" })
|
92
|
+
apt = double("apt",
|
93
|
+
name: "apt",
|
94
|
+
version_constraint: Semverse::Constraint.new(">= 0.0.0"),
|
95
|
+
version: "1.0.0",
|
96
|
+
location: "api",
|
97
|
+
dependencies: { "bacon" => "1.0.0" },
|
98
|
+
cached_cookbook: cookbook
|
99
99
|
)
|
100
|
-
bacon = double(name:
|
101
|
-
berksfile = double(
|
100
|
+
bacon = double(name: "bacon", version: "1.0.0", dependencies: {})
|
101
|
+
berksfile = double("berksfile", dependencies: [apt])
|
102
102
|
subject.instance_variable_set(:@berksfile, berksfile)
|
103
103
|
allow(subject).to receive(:find).with(apt).and_return(apt)
|
104
|
-
allow(subject.graph).to receive(:find).with(
|
104
|
+
allow(subject.graph).to receive(:find).with("bacon").and_return(bacon)
|
105
105
|
allow(subject.graph).to receive(:find).with(apt).and_return(apt)
|
106
106
|
|
107
107
|
expect(subject.trusted?).to be(true)
|
108
108
|
end
|
109
109
|
|
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
|
110
|
+
it "returns true when the lockfile is trusted with cyclic transitive dependencies" do
|
111
|
+
cookbook = double("apt-1.0.0", dependencies: { "bacon" => "1.0.0" })
|
112
|
+
apt = double("apt",
|
113
|
+
name: "apt",
|
114
|
+
version_constraint: Semverse::Constraint.new(">= 0.0.0"),
|
115
|
+
version: "1.0.0",
|
116
|
+
location: "api",
|
117
|
+
dependencies: { "bacon" => "1.0.0" },
|
118
|
+
cached_cookbook: cookbook
|
119
119
|
)
|
120
|
-
bacon = double(
|
121
|
-
name:
|
122
|
-
version_constraint: Semverse::Constraint.new(
|
123
|
-
version:
|
124
|
-
location:
|
125
|
-
dependencies: {
|
120
|
+
bacon = double("bacon",
|
121
|
+
name: "bacon",
|
122
|
+
version_constraint: Semverse::Constraint.new(">= 0.0.0"),
|
123
|
+
version: "1.0.0",
|
124
|
+
location: "api",
|
125
|
+
dependencies: { "apt" => "1.0.0" }
|
126
126
|
)
|
127
|
-
berksfile = double(
|
127
|
+
berksfile = double("berksfile", dependencies: [apt])
|
128
128
|
subject.instance_variable_set(:@berksfile, berksfile)
|
129
129
|
allow(subject).to receive(:find).with(apt).and_return(apt)
|
130
|
-
allow(subject.graph).to receive(:find).with(
|
130
|
+
allow(subject.graph).to receive(:find).with("bacon").and_return(bacon)
|
131
131
|
allow(subject.graph).to receive(:find).with(apt).and_return(apt)
|
132
132
|
|
133
133
|
expect(subject.trusted?).to be(true)
|
134
134
|
end
|
135
135
|
|
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
|
136
|
+
it "returns false when the lockfile is not trusted because of transitive dependencies" do
|
137
|
+
cookbook = double("apt-1.0.0", dependencies: { "bacon" => "1.0.0", "flip" => "2.0.0" })
|
138
|
+
apt = double("apt",
|
139
|
+
name: "apt",
|
140
|
+
version_constraint: Semverse::Constraint.new(">= 0.0.0"),
|
141
|
+
version: "1.0.0",
|
142
|
+
location: "api",
|
143
|
+
dependencies: { "bacon" => "1.0.0" },
|
144
|
+
cached_cookbook: cookbook
|
145
145
|
)
|
146
|
-
berksfile = double(
|
146
|
+
berksfile = double("berksfile", dependencies: [apt])
|
147
147
|
subject.instance_variable_set(:@berksfile, berksfile)
|
148
148
|
allow(subject).to receive(:find).with(apt).and_return(apt)
|
149
149
|
allow(subject.graph).to receive(:find).with(apt).and_return(apt)
|
@@ -151,17 +151,17 @@ describe Berkshelf::Lockfile do
|
|
151
151
|
expect(subject.trusted?).to be(false)
|
152
152
|
end
|
153
153
|
|
154
|
-
it
|
155
|
-
apt = double(
|
156
|
-
berksfile = double(
|
154
|
+
it "returns false if the dependency is not in the lockfile" do
|
155
|
+
apt = double("apt", name: "apt", version_constraint: nil)
|
156
|
+
berksfile = double("berksfile", dependencies: [apt])
|
157
157
|
subject.instance_variable_set(:@berksfile, berksfile)
|
158
158
|
|
159
159
|
expect(subject.trusted?).to be(false)
|
160
160
|
end
|
161
161
|
|
162
|
-
it
|
163
|
-
apt = double(
|
164
|
-
berksfile = double(
|
162
|
+
it "returns false if the dependency is not in the graph" do
|
163
|
+
apt = double("apt", name: "apt", version_constraint: nil)
|
164
|
+
berksfile = double("berksfile", dependencies: [apt])
|
165
165
|
subject.instance_variable_set(:@berksfile, berksfile)
|
166
166
|
allow(subject).to receive(:find).with(apt).and_return(true)
|
167
167
|
allow(subject.graph).to receive(:find).with(apt).and_return(nil)
|
@@ -169,17 +169,17 @@ describe Berkshelf::Lockfile do
|
|
169
169
|
expect(subject.trusted?).to be(false)
|
170
170
|
end
|
171
171
|
|
172
|
-
it
|
173
|
-
cookbook = double(
|
174
|
-
apt = double(
|
175
|
-
name:
|
176
|
-
version_constraint: Semverse::Constraint.new(
|
177
|
-
version:
|
178
|
-
location:
|
172
|
+
it "returns false if the constraint is not satisfied" do
|
173
|
+
cookbook = double("apt-1.0.0", dependencies: {})
|
174
|
+
apt = double("apt",
|
175
|
+
name: "apt",
|
176
|
+
version_constraint: Semverse::Constraint.new("< 1.0.0"),
|
177
|
+
version: "1.0.0",
|
178
|
+
location: "api",
|
179
179
|
dependencies: {},
|
180
|
-
cached_cookbook: cookbook
|
180
|
+
cached_cookbook: cookbook
|
181
181
|
)
|
182
|
-
berksfile = double(
|
182
|
+
berksfile = double("berksfile", dependencies: [apt])
|
183
183
|
subject.instance_variable_set(:@berksfile, berksfile)
|
184
184
|
allow(subject).to receive(:find).with(apt).and_return(apt)
|
185
185
|
allow(subject.graph).to receive(:find).with(apt).and_return(apt)
|
@@ -187,20 +187,20 @@ describe Berkshelf::Lockfile do
|
|
187
187
|
expect(subject.trusted?).to be(false)
|
188
188
|
end
|
189
189
|
|
190
|
-
it
|
191
|
-
cookbook = double(
|
192
|
-
apt = double(
|
193
|
-
name:
|
194
|
-
version_constraint: Semverse::Constraint.new(
|
195
|
-
version:
|
196
|
-
location:
|
190
|
+
it "returns false if the locations are different" do
|
191
|
+
cookbook = double("apt-1.0.0", dependencies: {})
|
192
|
+
apt = double("apt",
|
193
|
+
name: "apt",
|
194
|
+
version_constraint: Semverse::Constraint.new("< 1.0.0"),
|
195
|
+
version: "1.0.0",
|
196
|
+
location: "api",
|
197
197
|
dependencies: {},
|
198
|
-
cached_cookbook: cookbook
|
198
|
+
cached_cookbook: cookbook
|
199
199
|
)
|
200
200
|
apt_master = apt.dup
|
201
|
-
allow(apt_master).to receive_messages(location:
|
201
|
+
allow(apt_master).to receive_messages(location: "github")
|
202
202
|
allow(apt_master).to receive_messages(cached_cookbook: cookbook)
|
203
|
-
berksfile = double(
|
203
|
+
berksfile = double("berksfile", dependencies: [apt])
|
204
204
|
subject.instance_variable_set(:@berksfile, berksfile)
|
205
205
|
allow(subject).to receive(:find).with(apt).and_return(apt_master)
|
206
206
|
allow(subject.graph).to receive(:find).with(apt).and_return(apt)
|
@@ -209,169 +209,169 @@ describe Berkshelf::Lockfile do
|
|
209
209
|
end
|
210
210
|
end
|
211
211
|
|
212
|
-
describe
|
212
|
+
describe "#apply" do
|
213
213
|
before do
|
214
|
-
|
215
|
-
|
216
|
-
|
214
|
+
apt = double(name: "apt", locked_version: "1.0.0")
|
215
|
+
jenkins = double(name: "jenkins", locked_version: "1.4.5")
|
216
|
+
allow(subject.graph).to receive(:locks).and_return("apt" => apt, "jenkins" => jenkins)
|
217
217
|
end
|
218
218
|
|
219
|
-
describe
|
220
|
-
let(:connection) { double(
|
219
|
+
describe "when :envfile option is not used" do
|
220
|
+
let(:connection) { double("connection") }
|
221
221
|
|
222
222
|
before do
|
223
223
|
allow(Berkshelf).to receive(:ridley_connection).and_yield(connection)
|
224
224
|
end
|
225
225
|
|
226
|
-
context
|
227
|
-
it
|
226
|
+
context "when the Chef environment does not exist" do
|
227
|
+
it "raises an exception" do
|
228
228
|
allow(connection).to receive(:environment).and_return(double(find: nil))
|
229
|
-
expect
|
230
|
-
subject.apply(
|
231
|
-
|
229
|
+
expect do
|
230
|
+
subject.apply("production")
|
231
|
+
end.to raise_error(Berkshelf::EnvironmentNotFound)
|
232
232
|
end
|
233
233
|
end
|
234
234
|
|
235
|
-
it
|
236
|
-
environment = double(
|
235
|
+
it "locks the environment cookbook versions on chef server" do
|
236
|
+
environment = double("environment", :cookbook_versions= => nil, save: true)
|
237
237
|
allow(connection).to receive(:environment).and_return(double(find: environment))
|
238
238
|
|
239
239
|
expect(environment).to receive(:cookbook_versions=).with(
|
240
|
-
|
241
|
-
|
240
|
+
"apt" => "= 1.0.0",
|
241
|
+
"jenkins" => "= 1.4.5"
|
242
242
|
)
|
243
243
|
|
244
|
-
subject.apply(
|
244
|
+
subject.apply("production")
|
245
245
|
end
|
246
246
|
end
|
247
|
-
|
248
|
-
describe
|
249
|
-
it
|
250
|
-
locks = {
|
251
|
-
|
252
|
-
|
253
|
-
}
|
254
|
-
|
255
|
-
expect(subject).to receive(:update_environment_file).with(
|
256
|
-
|
257
|
-
|
247
|
+
|
248
|
+
describe "when :envfile option is used" do
|
249
|
+
it "locks the environment cookbook version into envfile" do
|
250
|
+
locks = {
|
251
|
+
"apt" => "= 1.0.0",
|
252
|
+
"jenkins" => "= 1.4.5",
|
253
|
+
}
|
254
|
+
|
255
|
+
expect(subject).to receive(:update_environment_file).with("/working/path", locks)
|
256
|
+
|
257
|
+
subject.apply("production", envfile: "/working/path")
|
258
258
|
end
|
259
259
|
end
|
260
260
|
end
|
261
261
|
|
262
|
-
describe
|
263
|
-
it
|
262
|
+
describe "#dependencies" do
|
263
|
+
it "returns an array" do
|
264
264
|
expect(subject.dependencies).to be_a(Array)
|
265
265
|
end
|
266
266
|
end
|
267
267
|
|
268
|
-
describe
|
269
|
-
it
|
270
|
-
expect(subject.find(
|
268
|
+
describe "#find" do
|
269
|
+
it "returns a matching cookbook" do
|
270
|
+
expect(subject.find("apt").name).to eq("apt")
|
271
271
|
end
|
272
272
|
|
273
|
-
it
|
274
|
-
expect(subject.find(
|
273
|
+
it "returns nil for a missing cookbook" do
|
274
|
+
expect(subject.find("foo")).to be_nil
|
275
275
|
end
|
276
276
|
end
|
277
277
|
|
278
|
-
describe
|
279
|
-
it
|
280
|
-
expect(subject).to have_dependency(
|
278
|
+
describe "#has_dependency?" do
|
279
|
+
it "returns true if a matching cookbook is found" do
|
280
|
+
expect(subject).to have_dependency("apt")
|
281
281
|
end
|
282
282
|
|
283
|
-
it
|
284
|
-
expect(subject).to_not have_dependency(
|
283
|
+
it "returns false if no matching cookbook is found" do
|
284
|
+
expect(subject).to_not have_dependency("foo")
|
285
285
|
end
|
286
286
|
end
|
287
287
|
|
288
|
-
describe
|
289
|
-
it
|
290
|
-
subject.add(
|
291
|
-
expect(subject).to have_dependency(
|
288
|
+
describe "#add" do
|
289
|
+
it "adds the dependency to the lockfile" do
|
290
|
+
subject.add("apache2")
|
291
|
+
expect(subject).to have_dependency("apache2")
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
describe "#update_environment_file" do
|
296
|
+
it "raises an exception when environment file does not exist" do
|
297
|
+
allow(File).to receive(:exists?).and_return(false)
|
298
|
+
expect do
|
299
|
+
subject.update_environment_file("/broken/path", nil)
|
300
|
+
end.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
|
292
321
|
end
|
293
322
|
end
|
294
323
|
|
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
|
324
|
+
describe "#update" do
|
325
|
+
it "resets the dependencies" do
|
326
326
|
subject.update([])
|
327
327
|
expect(subject.dependencies).to be_empty
|
328
328
|
end
|
329
329
|
|
330
|
-
it
|
331
|
-
subject.update([
|
332
|
-
expect(subject).to have_dependency(
|
330
|
+
it "appends each of the dependencies" do
|
331
|
+
subject.update(["apache2"])
|
332
|
+
expect(subject).to have_dependency("apache2")
|
333
333
|
end
|
334
334
|
end
|
335
335
|
|
336
|
-
describe
|
337
|
-
it
|
338
|
-
subject.add(
|
339
|
-
subject.unlock(
|
340
|
-
expect(subject).to_not have_dependency(
|
336
|
+
describe "#unlock" do
|
337
|
+
it "removes the dependency from the graph" do
|
338
|
+
subject.add("apache2")
|
339
|
+
subject.unlock("apache2")
|
340
|
+
expect(subject).to_not have_dependency("apache2")
|
341
341
|
end
|
342
342
|
end
|
343
343
|
|
344
|
-
describe
|
345
|
-
let(:berksfile_path) { fixtures_path.join(
|
344
|
+
describe "#reduce!" do
|
345
|
+
let(:berksfile_path) { fixtures_path.join("berksfiles/default").to_s }
|
346
346
|
let(:berksfile) { Berkshelf::Berksfile.from_file(berksfile_path) }
|
347
347
|
|
348
|
-
describe
|
349
|
-
let(:orphans_lock) { fixtures_path.join(
|
348
|
+
describe "with some orphan dependencies" do
|
349
|
+
let(:orphans_lock) { fixtures_path.join("lockfiles/orphans.lock").to_s }
|
350
350
|
subject { Berkshelf::Lockfile.new(filepath: orphans_lock, berksfile: berksfile) }
|
351
351
|
|
352
|
-
it
|
352
|
+
it "removes orphan dependencies" do
|
353
353
|
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(
|
354
|
+
expect(graph).to receive(:delete).with("yum-epel").and_call_original
|
355
|
+
expect(graph).to receive(:delete).with("zum-foo").and_call_original
|
356
|
+
expect(graph).to receive(:delete).with("yum").and_call_original
|
357
357
|
subject.reduce!
|
358
358
|
end
|
359
359
|
end
|
360
360
|
|
361
|
-
describe
|
361
|
+
describe "minimizes updates" do
|
362
362
|
subject { Berkshelf::Lockfile.new(filepath: filepath, berksfile: berksfile) }
|
363
363
|
|
364
364
|
before(:each) do
|
365
|
-
cs = fixtures_path.join(
|
365
|
+
cs = fixtures_path.join("cookbook-store")
|
366
366
|
allow(Berkshelf::CookbookStore.instance).to receive(:storage_path).and_return(cs)
|
367
367
|
end
|
368
368
|
|
369
|
-
it
|
369
|
+
it "uses the cookbook version specified in the lockfile" do
|
370
370
|
subject.reduce!
|
371
|
-
expect(subject.berksfile.dependencies[1].cached_cookbook.version).to eq(
|
371
|
+
expect(subject.berksfile.dependencies[1].cached_cookbook.version).to eq("2.0.3")
|
372
372
|
end
|
373
373
|
|
374
|
-
it
|
374
|
+
it "does not remove locks unnecessarily" do
|
375
375
|
expect(subject).to_not receive(:unlock)
|
376
376
|
subject.reduce!
|
377
377
|
end
|
@@ -380,16 +380,16 @@ describe Berkshelf::Lockfile do
|
|
380
380
|
end
|
381
381
|
|
382
382
|
describe Berkshelf::Lockfile::Graph do
|
383
|
-
let(:filepath) { fixtures_path.join(
|
383
|
+
let(:filepath) { fixtures_path.join("lockfiles/empty.lock").to_s }
|
384
384
|
let(:lockfile) { Berkshelf::Lockfile.new(filepath: filepath) }
|
385
385
|
subject { described_class.new(lockfile) }
|
386
386
|
|
387
|
-
describe
|
388
|
-
it
|
389
|
-
cookbook = double(
|
390
|
-
name:
|
391
|
-
version:
|
392
|
-
cookbook_name:
|
387
|
+
describe "#update" do
|
388
|
+
it "uses cookbook_name as GraphItem name" do
|
389
|
+
cookbook = double("test",
|
390
|
+
name: "test-0.0.1",
|
391
|
+
version: "0.0.1",
|
392
|
+
cookbook_name: "test",
|
393
393
|
dependencies: {}
|
394
394
|
)
|
395
395
|
subject.update([cookbook])
|