cookbook-omnifetch 0.8.0 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/cookbook-omnifetch.rb +13 -13
- data/lib/cookbook-omnifetch/artifactory.rb +12 -7
- data/lib/cookbook-omnifetch/artifactserver.rb +3 -3
- data/lib/cookbook-omnifetch/base.rb +1 -1
- data/lib/cookbook-omnifetch/chef_server.rb +2 -2
- data/lib/cookbook-omnifetch/chef_server_artifact.rb +2 -2
- data/lib/cookbook-omnifetch/git.rb +4 -4
- data/lib/cookbook-omnifetch/integration.rb +1 -1
- data/lib/cookbook-omnifetch/metadata_based_installer.rb +14 -13
- data/lib/cookbook-omnifetch/path.rb +1 -1
- data/lib/cookbook-omnifetch/threaded_job_queue.rb +1 -1
- data/lib/cookbook-omnifetch/version.rb +1 -1
- metadata +15 -85
- data/.gitignore +0 -23
- data/.rspec +0 -1
- data/.travis.yml +0 -11
- data/Gemfile +0 -8
- data/README.md +0 -90
- data/Rakefile +0 -19
- data/cookbook-omnifetch.gemspec +0 -39
- data/spec/fixtures/cookbooks/example_cookbook-0.5.0/README.md +0 -12
- data/spec/fixtures/cookbooks/example_cookbook-0.5.0/metadata.rb +0 -3
- data/spec/fixtures/cookbooks/example_cookbook-0.5.0/recipes/default.rb +0 -8
- data/spec/fixtures/cookbooks/example_cookbook/.gitignore +0 -2
- data/spec/fixtures/cookbooks/example_cookbook/.kitchen.yml +0 -26
- data/spec/fixtures/cookbooks/example_cookbook/Berksfile +0 -1
- data/spec/fixtures/cookbooks/example_cookbook/Berksfile.lock +0 -3
- data/spec/fixtures/cookbooks/example_cookbook/README.md +0 -12
- data/spec/fixtures/cookbooks/example_cookbook/metadata.rb +0 -3
- data/spec/fixtures/cookbooks/example_cookbook/recipes/default.rb +0 -8
- data/spec/spec_helper.rb +0 -43
- data/spec/unit/artifactory_spec.rb +0 -64
- data/spec/unit/artifactserver_spec.rb +0 -116
- data/spec/unit/base_spec.rb +0 -87
- data/spec/unit/chef_server_artifact_spec.rb +0 -110
- data/spec/unit/chef_server_spec.rb +0 -108
- data/spec/unit/exceptions_spec.rb +0 -87
- data/spec/unit/git_spec.rb +0 -290
- data/spec/unit/metadata_based_installer_spec.rb +0 -137
- data/spec/unit/path_spec.rb +0 -119
@@ -1,110 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "cookbook-omnifetch/chef_server.rb"
|
3
|
-
|
4
|
-
RSpec.describe CookbookOmnifetch::ChefServerArtifactLocation do
|
5
|
-
|
6
|
-
let(:http_client) { double("Http Client") }
|
7
|
-
|
8
|
-
let(:test_root) { "/some/fake/path" }
|
9
|
-
|
10
|
-
let(:storage_path) { File.join(test_root, "storage") }
|
11
|
-
|
12
|
-
let(:dependency) { double("Dependency", name: cookbook_name) }
|
13
|
-
|
14
|
-
let(:cookbook_name) { "example" }
|
15
|
-
|
16
|
-
let(:cookbook_identifier) { "467dc855408ce8b74f991c5dc2fd72a6aa369b60" }
|
17
|
-
|
18
|
-
let(:url) { "https://chef.example.com/organizations/example" }
|
19
|
-
|
20
|
-
let(:options) { { chef_server_artifact: url, identifier: cookbook_identifier, http_client: http_client } }
|
21
|
-
|
22
|
-
let(:expected_cache_key) { "example-467dc855408ce8b74f991c5dc2fd72a6aa369b60" }
|
23
|
-
|
24
|
-
let(:expected_install_path) { File.join(storage_path, expected_cache_key) }
|
25
|
-
|
26
|
-
subject(:chef_server_artifact_location) { described_class.new(dependency, options) }
|
27
|
-
|
28
|
-
before do
|
29
|
-
allow(CookbookOmnifetch).to receive(:storage_path).and_return(Pathname.new(storage_path))
|
30
|
-
end
|
31
|
-
|
32
|
-
it "has a URI" do
|
33
|
-
expect(chef_server_artifact_location.uri).to eq(url)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "has an HTTP client" do
|
37
|
-
expect(chef_server_artifact_location.http_client).to eq(http_client)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "has a metadata_based_installer" do
|
41
|
-
installer = chef_server_artifact_location.installer
|
42
|
-
expect(installer).to be_a(CookbookOmnifetch::MetadataBasedInstaller)
|
43
|
-
expect(installer.http_client).to eq(http_client)
|
44
|
-
expect(installer.url_path).to eq("/cookbook_artifacts/example/467dc855408ce8b74f991c5dc2fd72a6aa369b60")
|
45
|
-
expect(installer.install_path.to_s).to eq(expected_install_path)
|
46
|
-
end
|
47
|
-
|
48
|
-
it "has a cache key containing the site URI and version" do
|
49
|
-
expect(chef_server_artifact_location.cache_key).to eq(expected_cache_key)
|
50
|
-
end
|
51
|
-
|
52
|
-
it "has an identifier" do
|
53
|
-
expect(chef_server_artifact_location.cookbook_identifier).to eq(cookbook_identifier)
|
54
|
-
end
|
55
|
-
|
56
|
-
it "provides lock data as a Hash" do
|
57
|
-
expected_data = {
|
58
|
-
"chef_server_artifact" => url,
|
59
|
-
"identifier" => cookbook_identifier,
|
60
|
-
}
|
61
|
-
expect(chef_server_artifact_location.lock_data).to eq(expected_data)
|
62
|
-
end
|
63
|
-
|
64
|
-
it "returns a cached cookbook object" do
|
65
|
-
expect(MockCachedCookbook).to receive(:from_path).with(Pathname.new(expected_install_path))
|
66
|
-
chef_server_artifact_location.cached_cookbook
|
67
|
-
end
|
68
|
-
|
69
|
-
context "when using the default chef server HTTP client" do
|
70
|
-
|
71
|
-
let(:options) { { chef_server_artifact: url, identifier: cookbook_identifier } }
|
72
|
-
|
73
|
-
let(:default_http_client) { double("Http Client") }
|
74
|
-
|
75
|
-
before do
|
76
|
-
CookbookOmnifetch.integration.default_chef_server_http_client = default_http_client
|
77
|
-
end
|
78
|
-
|
79
|
-
after do
|
80
|
-
CookbookOmnifetch.integration.default_chef_server_http_client = nil
|
81
|
-
end
|
82
|
-
|
83
|
-
it "uses the default http client for requests" do
|
84
|
-
expect(chef_server_artifact_location.http_client).to eq(default_http_client)
|
85
|
-
end
|
86
|
-
|
87
|
-
context "and an http client is explicitly passed" do
|
88
|
-
|
89
|
-
let(:options) { { chef_server: url, identifier: cookbook_identifier, http_client: http_client } }
|
90
|
-
|
91
|
-
it "uses the explicitly passed client instead of the default" do
|
92
|
-
expect(chef_server_artifact_location.http_client).to eq(http_client)
|
93
|
-
end
|
94
|
-
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
describe "when installing" do
|
99
|
-
|
100
|
-
let(:installer) { instance_double("CookbookOmnifetch::MetadataBasedInstaller") }
|
101
|
-
|
102
|
-
it "delegates to the MetadataBasedInstaller" do
|
103
|
-
allow(chef_server_artifact_location).to receive(:installer).and_return(installer)
|
104
|
-
expect(installer).to receive(:install)
|
105
|
-
chef_server_artifact_location.install
|
106
|
-
end
|
107
|
-
|
108
|
-
end
|
109
|
-
|
110
|
-
end
|
@@ -1,108 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "cookbook-omnifetch/chef_server.rb"
|
3
|
-
|
4
|
-
RSpec.describe CookbookOmnifetch::ChefServerLocation do
|
5
|
-
|
6
|
-
let(:http_client) { double("Http Client") }
|
7
|
-
|
8
|
-
let(:test_root) { "/some/fake/path" }
|
9
|
-
|
10
|
-
let(:storage_path) { File.join(test_root, "storage") }
|
11
|
-
|
12
|
-
let(:dependency) { double("Dependency", name: cookbook_name) }
|
13
|
-
|
14
|
-
let(:cookbook_name) { "example" }
|
15
|
-
|
16
|
-
let(:cookbook_version) { "0.5.0" }
|
17
|
-
|
18
|
-
let(:url) { "https://chef.example.com/organizations/example" }
|
19
|
-
|
20
|
-
let(:options) { { chef_server: url, version: cookbook_version, http_client: http_client } }
|
21
|
-
|
22
|
-
let(:expected_install_path) { File.join(storage_path, "example-0.5.0") }
|
23
|
-
|
24
|
-
subject(:chef_server_location) { described_class.new(dependency, options) }
|
25
|
-
|
26
|
-
before do
|
27
|
-
allow(CookbookOmnifetch).to receive(:storage_path).and_return(Pathname.new(storage_path))
|
28
|
-
end
|
29
|
-
|
30
|
-
it "has a URI" do
|
31
|
-
expect(chef_server_location.uri).to eq(url)
|
32
|
-
end
|
33
|
-
|
34
|
-
it "has an HTTP client" do
|
35
|
-
expect(chef_server_location.http_client).to eq(http_client)
|
36
|
-
end
|
37
|
-
|
38
|
-
it "has a metadata_based_installer" do
|
39
|
-
installer = chef_server_location.installer
|
40
|
-
expect(installer).to be_a(CookbookOmnifetch::MetadataBasedInstaller)
|
41
|
-
expect(installer.http_client).to eq(http_client)
|
42
|
-
expect(installer.url_path).to eq("/cookbooks/example/0.5.0")
|
43
|
-
expect(installer.install_path.to_s).to eq(expected_install_path)
|
44
|
-
end
|
45
|
-
|
46
|
-
it "has a cache key containing the site URI and version" do
|
47
|
-
expect(chef_server_location.cache_key).to eq("example-0.5.0")
|
48
|
-
end
|
49
|
-
|
50
|
-
it "has an exact version" do
|
51
|
-
expect(chef_server_location.cookbook_version).to eq("0.5.0")
|
52
|
-
end
|
53
|
-
|
54
|
-
it "provides lock data as a Hash" do
|
55
|
-
expected_data = {
|
56
|
-
"chef_server" => url,
|
57
|
-
"version" => "0.5.0",
|
58
|
-
}
|
59
|
-
expect(chef_server_location.lock_data).to eq(expected_data)
|
60
|
-
end
|
61
|
-
|
62
|
-
it "returns a cached cookbook object" do
|
63
|
-
expect(MockCachedCookbook).to receive(:from_path).with(Pathname.new(expected_install_path))
|
64
|
-
chef_server_location.cached_cookbook
|
65
|
-
end
|
66
|
-
|
67
|
-
context "when using the default chef server HTTP client" do
|
68
|
-
|
69
|
-
let(:options) { { chef_server_artifact: url, version: cookbook_version } }
|
70
|
-
|
71
|
-
let(:default_http_client) { double("Http Client") }
|
72
|
-
|
73
|
-
before do
|
74
|
-
CookbookOmnifetch.integration.default_chef_server_http_client = default_http_client
|
75
|
-
end
|
76
|
-
|
77
|
-
after do
|
78
|
-
CookbookOmnifetch.integration.default_chef_server_http_client = nil
|
79
|
-
end
|
80
|
-
|
81
|
-
it "uses the default http client for requests" do
|
82
|
-
expect(chef_server_location.http_client).to eq(default_http_client)
|
83
|
-
end
|
84
|
-
|
85
|
-
context "and an http client is explicitly passed" do
|
86
|
-
|
87
|
-
let(:options) { { chef_server: url, version: cookbook_version, http_client: http_client } }
|
88
|
-
|
89
|
-
it "uses the explicitly passed client instead of the default" do
|
90
|
-
expect(chef_server_location.http_client).to eq(http_client)
|
91
|
-
end
|
92
|
-
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
describe "when installing" do
|
97
|
-
|
98
|
-
let(:installer) { instance_double("CookbookOmnifetch::MetadataBasedInstaller") }
|
99
|
-
|
100
|
-
it "delegates to the MetadataBasedInstaller" do
|
101
|
-
allow(chef_server_location).to receive(:installer).and_return(installer)
|
102
|
-
expect(installer).to receive(:install)
|
103
|
-
chef_server_location.install
|
104
|
-
end
|
105
|
-
|
106
|
-
end
|
107
|
-
|
108
|
-
end
|
@@ -1,87 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "cookbook-omnifetch/exceptions"
|
3
|
-
|
4
|
-
module CookbookOmnifetch
|
5
|
-
describe "Exceptions" do
|
6
|
-
|
7
|
-
describe NotACookbook do
|
8
|
-
|
9
|
-
subject(:exception) do
|
10
|
-
described_class.new("/path/to/cookbook")
|
11
|
-
end
|
12
|
-
|
13
|
-
let(:message) do
|
14
|
-
"The resource at '/path/to/cookbook' does not appear to be a valid cookbook. Does it have a metadata.rb?"
|
15
|
-
end
|
16
|
-
|
17
|
-
it "creates an informative error in #message" do
|
18
|
-
expect(exception.message).to eq(message)
|
19
|
-
end
|
20
|
-
|
21
|
-
it "creates an informative error in #to_s" do
|
22
|
-
expect(exception.to_s).to eq(message)
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
describe CookbookValidationFailure do
|
28
|
-
|
29
|
-
let(:dependency) { instance_double("ChefDK::Policyfile::CookbookLocationSpecification", to_s: "apt ~> 1.2.3") }
|
30
|
-
|
31
|
-
# The exception class itself doesn't use this
|
32
|
-
let(:cached_cookbook) { Object.new }
|
33
|
-
|
34
|
-
subject(:exception) do
|
35
|
-
described_class.new(dependency, cached_cookbook)
|
36
|
-
end
|
37
|
-
|
38
|
-
let(:message) do
|
39
|
-
"The cookbook downloaded for apt ~> 1.2.3 did not satisfy the constraint."
|
40
|
-
end
|
41
|
-
|
42
|
-
it "creates an informative error in #message" do
|
43
|
-
expect(exception.message).to eq(message)
|
44
|
-
end
|
45
|
-
|
46
|
-
it "creates an informative error in #to_s" do
|
47
|
-
expect(exception.to_s).to eq(message)
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
describe MismatchedCookbookName do
|
53
|
-
|
54
|
-
let(:dependency) { instance_double("ChefDK::Policyfile::CookbookLocationSpecification", name: "apt") }
|
55
|
-
|
56
|
-
let(:cached_cookbook) { instance_double("Chef::Cookbook", cookbook_name: "apt") }
|
57
|
-
|
58
|
-
subject(:exception) do
|
59
|
-
described_class.new(dependency, cached_cookbook)
|
60
|
-
end
|
61
|
-
|
62
|
-
let(:message) do
|
63
|
-
<<-EOM
|
64
|
-
In your Berksfile, you have:
|
65
|
-
|
66
|
-
cookbook 'apt'
|
67
|
-
|
68
|
-
But that cookbook is actually named 'apt'
|
69
|
-
|
70
|
-
This can cause potentially unwanted side-effects in the future.
|
71
|
-
|
72
|
-
NOTE: If you do not explicitly set the 'name' attribute in the metadata, the name of the directory will be used instead. This is often a cause of confusion for dependency solving.
|
73
|
-
EOM
|
74
|
-
end
|
75
|
-
|
76
|
-
it "creates an informative error in #message" do
|
77
|
-
expect(exception.message).to eq(message)
|
78
|
-
end
|
79
|
-
|
80
|
-
it "creates an informative error in #to_s" do
|
81
|
-
expect(exception.to_s).to eq(message)
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
end
|
87
|
-
end
|
data/spec/unit/git_spec.rb
DELETED
@@ -1,290 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "cookbook-omnifetch/git"
|
3
|
-
|
4
|
-
module CookbookOmnifetch
|
5
|
-
describe GitLocation do
|
6
|
-
let(:dependency) { double(name: "bacon") }
|
7
|
-
|
8
|
-
subject do
|
9
|
-
described_class.new(dependency, git: "https://repo.com", branch: "ham",
|
10
|
-
tag: "v1.2.3", ref: "abc123", revision: "defjkl123456", rel: "hi")
|
11
|
-
end
|
12
|
-
|
13
|
-
describe ".initialize" do
|
14
|
-
it "sets the uri" do
|
15
|
-
instance = described_class.new(dependency, git: "https://repo.com")
|
16
|
-
expect(instance.uri).to eq("https://repo.com")
|
17
|
-
end
|
18
|
-
|
19
|
-
it "sets the branch" do
|
20
|
-
instance = described_class.new(dependency,
|
21
|
-
git: "https://repo.com", branch: "magic_new_feature")
|
22
|
-
expect(instance.branch).to eq("magic_new_feature")
|
23
|
-
end
|
24
|
-
|
25
|
-
it "sets the tag" do
|
26
|
-
instance = described_class.new(dependency,
|
27
|
-
git: "https://repo.com", tag: "v1.2.3")
|
28
|
-
expect(instance.tag).to eq("v1.2.3")
|
29
|
-
end
|
30
|
-
|
31
|
-
it "adds the ref" do
|
32
|
-
instance = described_class.new(dependency,
|
33
|
-
git: "https://repo.com", ref: "abc123")
|
34
|
-
expect(instance.ref).to eq("abc123")
|
35
|
-
end
|
36
|
-
|
37
|
-
it "sets the revision" do
|
38
|
-
instance = described_class.new(dependency,
|
39
|
-
git: "https://repo.com", revision: "abcde12345")
|
40
|
-
expect(instance.revision).to eq("abcde12345")
|
41
|
-
end
|
42
|
-
|
43
|
-
it "sets the rel" do
|
44
|
-
instance = described_class.new(dependency,
|
45
|
-
git: "https://repo.com", rel: "internal/path")
|
46
|
-
expect(instance.rel).to eq("internal/path")
|
47
|
-
end
|
48
|
-
|
49
|
-
context "rev_parse" do
|
50
|
-
def rev_parse(instance)
|
51
|
-
instance.instance_variable_get(:@rev_parse)
|
52
|
-
end
|
53
|
-
|
54
|
-
it "uses the :ref option with priority" do
|
55
|
-
instance = described_class.new(dependency,
|
56
|
-
git: "https://repo.com", ref: "abc123", branch: "magic_new_feature")
|
57
|
-
expect(rev_parse(instance)).to eq("abc123")
|
58
|
-
end
|
59
|
-
|
60
|
-
it "uses the :branch option with priority" do
|
61
|
-
instance = described_class.new(dependency,
|
62
|
-
git: "https://repo.com", branch: "magic_new_feature", tag: "v1.2.3")
|
63
|
-
expect(rev_parse(instance)).to eq("magic_new_feature")
|
64
|
-
end
|
65
|
-
|
66
|
-
it "uses the :tag option" do
|
67
|
-
instance = described_class.new(dependency,
|
68
|
-
git: "https://repo.com", tag: "v1.2.3")
|
69
|
-
expect(rev_parse(instance)).to eq("v1.2.3")
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'uses "master" when none is given' do
|
73
|
-
instance = described_class.new(dependency, git: "https://repo.com")
|
74
|
-
expect(rev_parse(instance)).to eq("master")
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
describe "#cache_key" do
|
80
|
-
|
81
|
-
it "concatenates the name and revision" do
|
82
|
-
subject.stub(:revision).and_return("abcdef123456")
|
83
|
-
expect(subject.cache_key).to eq("bacon-abcdef123456")
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
describe "#installed?" do
|
88
|
-
it "returns false when there is no revision" do
|
89
|
-
subject.stub(:revision).and_return(nil)
|
90
|
-
expect(subject.installed?).to be false
|
91
|
-
end
|
92
|
-
|
93
|
-
it "returns false when the install_path does not exist" do
|
94
|
-
subject.stub(:revision).and_return("abcd1234")
|
95
|
-
subject.stub(:install_path).and_return(double(exist?: false))
|
96
|
-
expect(subject.installed?).to be false
|
97
|
-
end
|
98
|
-
|
99
|
-
it "returns true when the location is installed" do
|
100
|
-
subject.stub(:revision).and_return("abcd1234")
|
101
|
-
subject.stub(:install_path).and_return(double(exist?: true))
|
102
|
-
expect(subject.installed?).to be true
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
describe "#install" do
|
107
|
-
before do
|
108
|
-
File.stub(:chmod)
|
109
|
-
FileUtils.stub(:cp_r)
|
110
|
-
subject.stub(:validate_cached!)
|
111
|
-
subject.stub(:git)
|
112
|
-
end
|
113
|
-
|
114
|
-
context "when the repository is cached" do
|
115
|
-
it "pulls a new version" do
|
116
|
-
Dir.stub(:chdir) { |args, &b| b.call } # Force eval the chdir block
|
117
|
-
|
118
|
-
subject.stub(:cached?).and_return(true)
|
119
|
-
expect(subject).to receive(:git).with(
|
120
|
-
'fetch --force --tags https://repo.com "refs/heads/*:refs/heads/*"'
|
121
|
-
)
|
122
|
-
subject.install
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
context "when the revision is not cached" do
|
127
|
-
it "clones the repository" do
|
128
|
-
Dir.stub(:chdir) { |args, &b| b.call } # Force eval the chdir block
|
129
|
-
|
130
|
-
cache_path = subject.send(:cache_path)
|
131
|
-
subject.stub(:cached?).and_return(false)
|
132
|
-
expect(subject).to receive(:git).with(
|
133
|
-
%{clone https://repo.com "#{cache_path}" --bare --no-hardlinks}
|
134
|
-
)
|
135
|
-
subject.install
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
describe "#cached_cookbook" do
|
141
|
-
it "returns nil if the cookbook is not installed" do
|
142
|
-
subject.stub(:installed?).and_return(false)
|
143
|
-
expect(subject.cached_cookbook).to be_nil
|
144
|
-
end
|
145
|
-
|
146
|
-
it "returns the cookbook at the install_path" do
|
147
|
-
subject.stub(:installed?).and_return(true)
|
148
|
-
MockCachedCookbook.stub(:from_path)
|
149
|
-
|
150
|
-
expect(MockCachedCookbook).to receive(:from_path).once
|
151
|
-
subject.cached_cookbook
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
describe "#==" do
|
156
|
-
let(:other) { subject.dup }
|
157
|
-
|
158
|
-
it "returns true when everything matches" do
|
159
|
-
expect(subject).to eq(other)
|
160
|
-
end
|
161
|
-
|
162
|
-
it "returns false when the other location is not an GitLocation" do
|
163
|
-
other.stub(:is_a?).and_return(false)
|
164
|
-
expect(subject).to_not eq(other)
|
165
|
-
end
|
166
|
-
|
167
|
-
it "returns false when the uri is different" do
|
168
|
-
other.stub(:uri).and_return("different")
|
169
|
-
expect(subject).to_not eq(other)
|
170
|
-
end
|
171
|
-
|
172
|
-
it "returns false when the branch is different" do
|
173
|
-
other.stub(:branch).and_return("different")
|
174
|
-
expect(subject).to_not eq(other)
|
175
|
-
end
|
176
|
-
|
177
|
-
it "returns false when the tag is different" do
|
178
|
-
other.stub(:tag).and_return("different")
|
179
|
-
expect(subject).to_not eq(other)
|
180
|
-
end
|
181
|
-
|
182
|
-
it "returns false when the ref is different" do
|
183
|
-
other.stub(:ref).and_return("different")
|
184
|
-
expect(subject).to_not eq(other)
|
185
|
-
end
|
186
|
-
|
187
|
-
it "returns false when the rel is different" do
|
188
|
-
other.stub(:rel).and_return("different")
|
189
|
-
expect(subject).to_not eq(other)
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
describe "#to_s" do
|
194
|
-
it "prefers the tag" do
|
195
|
-
expect(subject.to_s).to eq("https://repo.com (at v1.2.3/hi)")
|
196
|
-
end
|
197
|
-
|
198
|
-
it "prefers the branch" do
|
199
|
-
subject.stub(:tag).and_return(nil)
|
200
|
-
expect(subject.to_s).to eq("https://repo.com (at ham/hi)")
|
201
|
-
end
|
202
|
-
|
203
|
-
it "falls back to the ref" do
|
204
|
-
subject.stub(:tag).and_return(nil)
|
205
|
-
subject.stub(:branch).and_return(nil)
|
206
|
-
expect(subject.to_s).to eq("https://repo.com (at abc123/hi)")
|
207
|
-
end
|
208
|
-
|
209
|
-
it "does not use the rel if missing" do
|
210
|
-
subject.stub(:rel).and_return(nil)
|
211
|
-
expect(subject.to_s).to eq("https://repo.com (at v1.2.3)")
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
describe "#to_lock" do
|
216
|
-
it "includes all the information" do
|
217
|
-
expect(subject.to_lock).to eq <<-EOH.gsub(/^ {8}/, "")
|
218
|
-
git: https://repo.com
|
219
|
-
revision: defjkl123456
|
220
|
-
ref: abc123
|
221
|
-
branch: ham
|
222
|
-
tag: v1.2.3
|
223
|
-
rel: hi
|
224
|
-
EOH
|
225
|
-
end
|
226
|
-
|
227
|
-
it "does not include the branch if missing" do
|
228
|
-
subject.stub(:branch).and_return(nil)
|
229
|
-
expect(subject.to_lock).to_not include("branch")
|
230
|
-
end
|
231
|
-
|
232
|
-
it "does not include the tag if missing" do
|
233
|
-
subject.stub(:tag).and_return(nil)
|
234
|
-
expect(subject.to_lock).to_not include("tag")
|
235
|
-
end
|
236
|
-
|
237
|
-
it "does not include the rel if missing" do
|
238
|
-
subject.stub(:rel).and_return(nil)
|
239
|
-
expect(subject.to_lock).to_not include("rel")
|
240
|
-
end
|
241
|
-
end
|
242
|
-
|
243
|
-
describe "#lock_data" do
|
244
|
-
let(:full_lock_data) do
|
245
|
-
{
|
246
|
-
"git" => "https://repo.com",
|
247
|
-
"revision" => "defjkl123456",
|
248
|
-
"ref" => "abc123",
|
249
|
-
"branch" => "ham",
|
250
|
-
"tag" => "v1.2.3",
|
251
|
-
"rel" => "hi",
|
252
|
-
}
|
253
|
-
end
|
254
|
-
|
255
|
-
it "includes all the information" do
|
256
|
-
expect(subject.lock_data).to eq(full_lock_data)
|
257
|
-
end
|
258
|
-
|
259
|
-
it "does not include the branch if missing" do
|
260
|
-
subject.stub(:branch).and_return(nil)
|
261
|
-
expect(subject.lock_data).to_not have_key("branch")
|
262
|
-
end
|
263
|
-
|
264
|
-
it "does not include the tag if missing" do
|
265
|
-
subject.stub(:tag).and_return(nil)
|
266
|
-
expect(subject.lock_data).to_not have_key("tag")
|
267
|
-
end
|
268
|
-
|
269
|
-
it "does not include the rel if missing" do
|
270
|
-
subject.stub(:rel).and_return(nil)
|
271
|
-
expect(subject.lock_data).to_not have_key("rel")
|
272
|
-
end
|
273
|
-
end
|
274
|
-
|
275
|
-
describe "#git" do
|
276
|
-
before { described_class.send(:public, :git) }
|
277
|
-
|
278
|
-
it "raises an error if Git is not installed" do
|
279
|
-
CookbookOmnifetch.stub(:which).and_return(false)
|
280
|
-
expect { subject.git("foo") }.to raise_error(GitNotInstalled)
|
281
|
-
end
|
282
|
-
|
283
|
-
it "raises an error if the command fails" do
|
284
|
-
shell_out = double("shell_out", success?: false, stderr: nil)
|
285
|
-
MockShellOut.stub(:shell_out).and_return(shell_out)
|
286
|
-
expect { subject.git("foo") }.to raise_error(GitCommandError)
|
287
|
-
end
|
288
|
-
end
|
289
|
-
end
|
290
|
-
end
|