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,48 +1,48 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Berkshelf::CachedCookbook do
|
4
4
|
describe "ClassMethods" do
|
5
|
-
describe
|
6
|
-
let(:path) { fixtures_path.join(
|
5
|
+
describe "::from_store_path" do
|
6
|
+
let(:path) { fixtures_path.join("cookbooks", "example_cookbook-0.5.0") }
|
7
7
|
let(:cached) { described_class.from_path(path) }
|
8
8
|
|
9
|
-
it
|
9
|
+
it "returns a CachedCookbook" do
|
10
10
|
expect(cached).to be_a(described_class)
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
14
|
-
expect(cached.version).to eq(
|
13
|
+
it "sets a version number" do
|
14
|
+
expect(cached.version).to eq("0.5.0")
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
18
|
-
expect(cached.metadata.name).to eq(
|
17
|
+
it "sets the metadata.name value to the cookbook_name" do
|
18
|
+
expect(cached.metadata.name).to eq("example_cookbook")
|
19
19
|
end
|
20
20
|
|
21
|
-
context
|
22
|
-
it
|
21
|
+
context "given a path that does not contain a cookbook" do
|
22
|
+
it "returns nil" do
|
23
23
|
expect(described_class.from_store_path(tmp_path)).to be_nil
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
context
|
28
|
-
it
|
29
|
-
path = fixtures_path.join(
|
27
|
+
context "given a path that does not match the CachedCookbook dirname format" do
|
28
|
+
it "returns nil" do
|
29
|
+
path = fixtures_path.join("cookbooks", "example_cookbook")
|
30
30
|
expect(described_class.from_store_path(path)).to be_nil
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
context
|
34
|
+
context "given an already cached cookbook" do
|
35
35
|
let!(:cached) { described_class.from_store_path(path) }
|
36
36
|
|
37
|
-
it
|
37
|
+
it "returns the cached cookbook instance" do
|
38
38
|
expect(described_class.from_store_path(path)).to eq(cached)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
describe
|
44
|
-
it
|
45
|
-
path = fixtures_path.join(
|
43
|
+
describe "::checksum" do
|
44
|
+
it "returns a checksum of the given filepath" do
|
45
|
+
path = fixtures_path.join("cookbooks", "example_cookbook-0.5.0", "README.md")
|
46
46
|
expected_md5 = if IO.binread(path).include?("\r\n")
|
47
47
|
# On windows, with git configured for auto crlf
|
48
48
|
"2414583f86c9eb68bdbb0be391939341"
|
@@ -52,48 +52,48 @@ describe Berkshelf::CachedCookbook do
|
|
52
52
|
expect(described_class.checksum(path)).to eq(expected_md5)
|
53
53
|
end
|
54
54
|
|
55
|
-
context
|
56
|
-
it
|
57
|
-
expect
|
58
|
-
described_class.checksum(fixtures_path.join(
|
59
|
-
|
55
|
+
context "given path does not exist" do
|
56
|
+
it "raises an Errno::ENOENT error" do
|
57
|
+
expect do
|
58
|
+
described_class.checksum(fixtures_path.join("notexisting.file"))
|
59
|
+
end.to raise_error(Errno::ENOENT)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
let(:dependencies) { {
|
66
|
-
let(:recommendations) { {
|
65
|
+
let(:dependencies) { { "mysql" => "= 1.2.0", "ntp" => ">= 0.0.0" } }
|
66
|
+
let(:recommendations) { { "database" => ">= 0.0.0" } }
|
67
67
|
let(:path) do
|
68
68
|
generate_cookbook(Berkshelf.cookbook_store.storage_path,
|
69
|
-
|
69
|
+
"sparkle", "0.1.0", dependencies: dependencies, recommendations: recommendations)
|
70
70
|
end
|
71
71
|
|
72
72
|
subject { Berkshelf::CachedCookbook.from_store_path(path) }
|
73
73
|
|
74
|
-
describe
|
75
|
-
it
|
74
|
+
describe "#dependencies" do
|
75
|
+
it "contains depends from the cookbook metadata" do
|
76
76
|
expect(subject.dependencies).to include(dependencies)
|
77
77
|
end
|
78
78
|
|
79
|
-
it
|
79
|
+
it "contains recommendations from the cookbook metadata" do
|
80
80
|
expect(subject.dependencies).to include(recommendations)
|
81
81
|
end
|
82
82
|
|
83
|
-
it
|
83
|
+
it "returns a hash" do
|
84
84
|
expect(subject.dependencies).to be_a(Hash)
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
-
describe
|
89
|
-
shared_examples
|
88
|
+
describe "#pretty_hash" do
|
89
|
+
shared_examples "a pretty_hash cookbook attribute" do |attribute, key|
|
90
90
|
it "is not present when the `#{attribute}` attribute is nil" do
|
91
91
|
allow(subject).to receive(attribute.to_sym).and_return(nil)
|
92
92
|
expect(subject.pretty_hash).to_not have_key((key || attribute).to_sym)
|
93
93
|
end
|
94
94
|
|
95
95
|
it "is not present when the `#{attribute}` attribute is an empty string" do
|
96
|
-
allow(subject).to receive(attribute.to_sym).and_return(
|
96
|
+
allow(subject).to receive(attribute.to_sym).and_return("")
|
97
97
|
expect(subject.pretty_hash).to_not have_key((key || attribute).to_sym)
|
98
98
|
end
|
99
99
|
|
@@ -108,18 +108,18 @@ describe Berkshelf::CachedCookbook do
|
|
108
108
|
end
|
109
109
|
|
110
110
|
it "is present when the `#{attribute}` attribute has a Hash value" do
|
111
|
-
allow(subject).to receive(attribute.to_sym).and_return(foo:
|
111
|
+
allow(subject).to receive(attribute.to_sym).and_return(foo: "bar")
|
112
112
|
expect(subject.pretty_hash).to have_key((key || attribute).to_sym)
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
116
|
-
it_behaves_like
|
117
|
-
it_behaves_like
|
118
|
-
it_behaves_like
|
119
|
-
it_behaves_like
|
120
|
-
it_behaves_like
|
121
|
-
it_behaves_like
|
122
|
-
it_behaves_like
|
123
|
-
it_behaves_like
|
116
|
+
it_behaves_like "a pretty_hash cookbook attribute", "cookbook_name", "name"
|
117
|
+
it_behaves_like "a pretty_hash cookbook attribute", "version"
|
118
|
+
it_behaves_like "a pretty_hash cookbook attribute", "description"
|
119
|
+
it_behaves_like "a pretty_hash cookbook attribute", "maintainer", "author"
|
120
|
+
it_behaves_like "a pretty_hash cookbook attribute", "maintainer_email", "email"
|
121
|
+
it_behaves_like "a pretty_hash cookbook attribute", "license"
|
122
|
+
it_behaves_like "a pretty_hash cookbook attribute", "platforms"
|
123
|
+
it_behaves_like "a pretty_hash cookbook attribute", "dependencies"
|
124
124
|
end
|
125
125
|
end
|
@@ -1,24 +1,24 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
module Berkshelf
|
4
4
|
describe Cli do
|
5
5
|
let(:subject) { described_class.new }
|
6
|
-
let(:berksfile) { double(
|
7
|
-
let(:cookbooks) { [
|
6
|
+
let(:berksfile) { double("Berksfile") }
|
7
|
+
let(:cookbooks) { ["mysql"] }
|
8
8
|
|
9
9
|
before do
|
10
10
|
allow(Berksfile).to receive(:from_options).and_return(berksfile)
|
11
11
|
end
|
12
12
|
|
13
|
-
describe
|
14
|
-
it
|
13
|
+
describe "#upload" do
|
14
|
+
it "calls to upload with params if passed in cli" do
|
15
15
|
expect(berksfile).to receive(:upload).with(cookbooks,
|
16
16
|
include(skip_syntax_check: true, freeze: false)
|
17
17
|
)
|
18
18
|
|
19
19
|
subject.options[:skip_syntax_check] = true
|
20
20
|
subject.options[:no_freeze] = true
|
21
|
-
subject.upload(
|
21
|
+
subject.upload("mysql")
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -1,21 +1,21 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Berkshelf::CommunityREST do
|
4
4
|
describe "ClassMethods" do
|
5
5
|
describe "::unpack" do
|
6
|
-
let(:target) {
|
7
|
-
let(:destination) {
|
8
|
-
let(:file) { double(
|
9
|
-
let(:gzip_reader) { double(
|
10
|
-
let(:archive) { double(
|
6
|
+
let(:target) { "/foo/bar" }
|
7
|
+
let(:destination) { "/destination/bar" }
|
8
|
+
let(:file) { double("file") }
|
9
|
+
let(:gzip_reader) { double("gzip_reader") }
|
10
|
+
let(:archive) { double("mixlib_archive") }
|
11
11
|
|
12
12
|
before do
|
13
|
-
allow(File).to receive(:open).with(target,
|
13
|
+
allow(File).to receive(:open).with(target, "rb").and_return(file)
|
14
14
|
allow(archive).to receive(:extract).with(destination)
|
15
15
|
allow(Mixlib::Archive).to receive(:new).with(target).and_return(archive)
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
18
|
+
it "unpacks the tar" do
|
19
19
|
expect(::IO).to receive(:binread).with(target, 2).and_return([0x1F, 0x8B].pack("C*"))
|
20
20
|
expect(Mixlib::Archive).to receive(:new).with(target).and_return(archive)
|
21
21
|
expect(archive).to receive(:extract).with(destination)
|
@@ -25,38 +25,38 @@ describe Berkshelf::CommunityREST do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
describe "::uri_escape_version" do
|
28
|
-
it
|
28
|
+
it "returns a string" do
|
29
29
|
expect(Berkshelf::CommunityREST.uri_escape_version(nil)).to be_a(String)
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'converts a version to it\'s underscored version' do
|
33
|
-
expect(Berkshelf::CommunityREST.uri_escape_version(
|
33
|
+
expect(Berkshelf::CommunityREST.uri_escape_version("1.1.2")).to eq("1_1_2")
|
34
34
|
end
|
35
35
|
|
36
|
-
it
|
37
|
-
expect(Berkshelf::CommunityREST.uri_escape_version(
|
36
|
+
it "works when the version has more than three points" do
|
37
|
+
expect(Berkshelf::CommunityREST.uri_escape_version("1.1.1.2")).to eq("1_1_1_2")
|
38
38
|
end
|
39
39
|
|
40
|
-
it
|
41
|
-
expect(Berkshelf::CommunityREST.uri_escape_version(
|
40
|
+
it "works when the version has less than three points" do
|
41
|
+
expect(Berkshelf::CommunityREST.uri_escape_version("1.2")).to eq("1_2")
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
describe "::version_from_uri" do
|
46
|
-
it
|
46
|
+
it "returns a string" do
|
47
47
|
expect(Berkshelf::CommunityREST.version_from_uri(nil)).to be_a(String)
|
48
48
|
end
|
49
49
|
|
50
|
-
it
|
51
|
-
expect(Berkshelf::CommunityREST.version_from_uri(
|
50
|
+
it "extracts the version from the URL" do
|
51
|
+
expect(Berkshelf::CommunityREST.version_from_uri("/api/v1/cookbooks/nginx/versions/1_1_2")).to eq("1.1.2")
|
52
52
|
end
|
53
53
|
|
54
|
-
it
|
55
|
-
expect(Berkshelf::CommunityREST.version_from_uri(
|
54
|
+
it "works when the version has more than three points" do
|
55
|
+
expect(Berkshelf::CommunityREST.version_from_uri("/api/v1/cookbooks/nginx/versions/1_1_1_2")).to eq("1.1.1.2")
|
56
56
|
end
|
57
57
|
|
58
|
-
it
|
59
|
-
expect(Berkshelf::CommunityREST.version_from_uri(
|
58
|
+
it "works when the version has less than three points" do
|
59
|
+
expect(Berkshelf::CommunityREST.version_from_uri("/api/v1/cookbooks/nginx/versions/1_2")).to eq("1.2")
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
@@ -64,161 +64,161 @@ describe Berkshelf::CommunityREST do
|
|
64
64
|
let(:api_uri) { Berkshelf::CommunityREST::V1_API }
|
65
65
|
subject { Berkshelf::CommunityREST.new(api_uri) }
|
66
66
|
|
67
|
-
describe
|
68
|
-
context
|
69
|
-
it
|
67
|
+
describe "#initialize" do
|
68
|
+
context "Faraday handlers" do
|
69
|
+
it "includes follow_redirects to prevent 301 from community, stopping some cookbooks installing" do
|
70
70
|
expect(subject.builder.handlers).to include(Ridley::Middleware::FollowRedirects)
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
describe
|
76
|
-
let(:archive) { double(
|
75
|
+
describe "#download" do
|
76
|
+
let(:archive) { double("archive", path: "/foo/bar", unlink: true) }
|
77
77
|
|
78
78
|
before do
|
79
79
|
allow(subject).to receive(:stream).with(any_args()).and_return(archive)
|
80
80
|
allow(Berkshelf::CommunityREST).to receive(:unpack)
|
81
|
-
.and_return(
|
81
|
+
.and_return("/some/path")
|
82
82
|
end
|
83
83
|
|
84
|
-
it
|
84
|
+
it "unpacks the archive" do
|
85
85
|
stub_request(:get, "#{api_uri}/cookbooks/bacon/versions/1_0_0").to_return(
|
86
86
|
status: 200,
|
87
87
|
body: '{ "cookbook": "/path/to/cookbook", "version": "1.0.0" }',
|
88
|
-
headers: {
|
88
|
+
headers: { "Content-Type" => "application/json" }
|
89
89
|
)
|
90
90
|
|
91
91
|
expect(Berkshelf::CommunityREST).to receive(:unpack)
|
92
|
-
.with(
|
93
|
-
.and_return(
|
92
|
+
.with("/foo/bar", String)
|
93
|
+
.and_return("/foo/nginx")
|
94
94
|
.once
|
95
95
|
expect(archive).to receive(:unlink).once
|
96
96
|
|
97
|
-
subject.download(
|
97
|
+
subject.download("bacon", "1.0.0")
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
101
|
-
describe
|
102
|
-
it
|
101
|
+
describe "#find" do
|
102
|
+
it "returns the cookbook and version information" do
|
103
103
|
stub_request(:get, "#{api_uri}/cookbooks/bacon/versions/1_0_0").to_return(
|
104
104
|
status: 200,
|
105
105
|
body: '{ "cookbook": "/path/to/cookbook", "version": "1.0.0" }',
|
106
|
-
headers: {
|
106
|
+
headers: { "Content-Type" => "application/json" }
|
107
107
|
)
|
108
108
|
|
109
|
-
result = subject.find(
|
109
|
+
result = subject.find("bacon", "1.0.0")
|
110
110
|
|
111
|
-
expect(result.cookbook).to eq(
|
112
|
-
expect(result.version).to eq(
|
111
|
+
expect(result.cookbook).to eq("/path/to/cookbook")
|
112
|
+
expect(result.version).to eq("1.0.0")
|
113
113
|
end
|
114
114
|
|
115
|
-
it
|
115
|
+
it "raises a CookbookNotFound error on a 404 response for a non-existent cookbook" do
|
116
116
|
stub_request(:get, "#{api_uri}/cookbooks/not_real/versions/1_0_0").to_return(
|
117
117
|
status: 404,
|
118
|
-
body: nil
|
118
|
+
body: nil
|
119
119
|
)
|
120
120
|
|
121
|
-
expect
|
122
|
-
subject.find(
|
123
|
-
|
121
|
+
expect do
|
122
|
+
subject.find("not_real", "1.0.0")
|
123
|
+
end.to raise_error(Berkshelf::CookbookNotFound)
|
124
124
|
end
|
125
125
|
|
126
|
-
it
|
126
|
+
it "raises a CommunitySiteError error on any non 200 or 404 response" do
|
127
127
|
stub_request(:get, "#{api_uri}/cookbooks/not_real/versions/1_0_0").to_return(
|
128
128
|
status: 500,
|
129
|
-
body: nil
|
129
|
+
body: nil
|
130
130
|
)
|
131
131
|
|
132
|
-
expect
|
133
|
-
subject.find(
|
134
|
-
|
132
|
+
expect do
|
133
|
+
subject.find("not_real", "1.0.0")
|
134
|
+
end.to raise_error(Berkshelf::CommunitySiteError)
|
135
135
|
end
|
136
136
|
end
|
137
137
|
|
138
|
-
describe
|
139
|
-
it
|
138
|
+
describe "#latest_version" do
|
139
|
+
it "returns the version number of the latest version of the cookbook" do
|
140
140
|
stub_request(:get, "#{api_uri}/cookbooks/bacon").to_return(
|
141
141
|
status: 200,
|
142
142
|
body: '{ "latest_version": "1.0.0" }',
|
143
|
-
headers: {
|
143
|
+
headers: { "Content-Type" => "application/json" }
|
144
144
|
)
|
145
145
|
|
146
|
-
latest = subject.latest_version(
|
147
|
-
expect(latest).to eq(
|
146
|
+
latest = subject.latest_version("bacon")
|
147
|
+
expect(latest).to eq("1.0.0")
|
148
148
|
end
|
149
149
|
|
150
|
-
it
|
150
|
+
it "raises a CookbookNotFound error on a 404 response" do
|
151
151
|
stub_request(:get, "#{api_uri}/cookbooks/not_real").to_return(
|
152
152
|
status: 404,
|
153
|
-
body: nil
|
153
|
+
body: nil
|
154
154
|
)
|
155
155
|
|
156
|
-
expect
|
157
|
-
subject.latest_version(
|
158
|
-
|
156
|
+
expect do
|
157
|
+
subject.latest_version("not_real")
|
158
|
+
end.to raise_error(Berkshelf::CookbookNotFound)
|
159
159
|
end
|
160
160
|
|
161
|
-
it
|
161
|
+
it "raises a CommunitySiteError error on any non 200 or 404 response" do
|
162
162
|
stub_request(:get, "#{api_uri}/cookbooks/not_real").to_return(
|
163
163
|
status: 500,
|
164
|
-
body: nil
|
164
|
+
body: nil
|
165
165
|
)
|
166
166
|
|
167
|
-
expect
|
168
|
-
subject.latest_version(
|
169
|
-
|
167
|
+
expect do
|
168
|
+
subject.latest_version("not_real")
|
169
|
+
end.to raise_error(Berkshelf::CommunitySiteError)
|
170
170
|
end
|
171
171
|
end
|
172
172
|
|
173
|
-
describe
|
174
|
-
it
|
173
|
+
describe "#versions" do
|
174
|
+
it "returns an array containing an item for each version" do
|
175
175
|
stub_request(:get, "#{api_uri}/cookbooks/bacon").to_return(
|
176
176
|
status: 200,
|
177
177
|
body: '{ "versions": ["/bacon/versions/1_0_0", "/bacon/versions/2_0_0"] }',
|
178
|
-
headers: {
|
178
|
+
headers: { "Content-Type" => "application/json" }
|
179
179
|
)
|
180
180
|
|
181
|
-
versions = subject.versions(
|
181
|
+
versions = subject.versions("bacon")
|
182
182
|
expect(versions.size).to eq(2)
|
183
183
|
end
|
184
184
|
|
185
|
-
it
|
185
|
+
it "raises a CookbookNotFound error on a 404 response" do
|
186
186
|
stub_request(:get, "#{api_uri}/cookbooks/not_real").to_return(
|
187
187
|
status: 404,
|
188
|
-
body: nil
|
188
|
+
body: nil
|
189
189
|
)
|
190
190
|
|
191
|
-
expect
|
192
|
-
subject.versions(
|
193
|
-
|
191
|
+
expect do
|
192
|
+
subject.versions("not_real")
|
193
|
+
end.to raise_error(Berkshelf::CookbookNotFound)
|
194
194
|
end
|
195
195
|
|
196
|
-
it
|
196
|
+
it "raises a CommunitySiteError error on any non 200 or 404 response" do
|
197
197
|
stub_request(:get, "#{api_uri}/cookbooks/not_real").to_return(
|
198
198
|
status: 500,
|
199
|
-
body: nil
|
199
|
+
body: nil
|
200
200
|
)
|
201
201
|
|
202
|
-
expect
|
203
|
-
subject.versions(
|
204
|
-
|
202
|
+
expect do
|
203
|
+
subject.versions("not_real")
|
204
|
+
end.to raise_error(Berkshelf::CommunitySiteError)
|
205
205
|
end
|
206
206
|
end
|
207
207
|
|
208
|
-
describe
|
209
|
-
it
|
208
|
+
describe "#satisfy" do
|
209
|
+
it "returns the version number of the best solution" do
|
210
210
|
stub_request(:get, "#{api_uri}/cookbooks/bacon").to_return(
|
211
211
|
status: 200,
|
212
212
|
body: '{ "versions": ["/bacon/versions/1_0_0", "/bacon/versions/2_0_0"] }',
|
213
|
-
headers: {
|
213
|
+
headers: { "Content-Type" => "application/json" }
|
214
214
|
)
|
215
215
|
|
216
|
-
result = subject.satisfy(
|
217
|
-
expect(result).to eq(
|
216
|
+
result = subject.satisfy("bacon", "= 1.0.0")
|
217
|
+
expect(result).to eq("1.0.0")
|
218
218
|
end
|
219
219
|
end
|
220
220
|
|
221
|
-
describe
|
221
|
+
describe "#stream" do
|
222
222
|
skip
|
223
223
|
end
|
224
224
|
end
|