cookbook-omnifetch 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 64e4ca89bc3c10a6c4bf4e224bb39f5657d1cd12
4
- data.tar.gz: c16cfaa9e0b3c9eb655faa3d12a293b6ec166931
3
+ metadata.gz: 43c39456987fef3b32d9b037565804e5293bd8ed
4
+ data.tar.gz: 776b3865d04123606bdafb1f4f7c7412b993724b
5
5
  SHA512:
6
- metadata.gz: 8e3354f49b0ed00fd5ab23f6de8dd8994419bb8e15c1d32b5dc85f960c46c1d20af45b8f2ca4cbb0e96a812a57e9a8bc04bba1907a319c13e9a6a323eda673be
7
- data.tar.gz: f7841d6c9081275526ba60ece1fd3f349b24d812d9c2bba66110a3c1da6800d0e35e2da1a304f7601e4fda6849e9f78f49c8a127f3c3fcaf4f33dc1f919db3dd
6
+ metadata.gz: 1dea15259b08c5de8a97f111c103f9f8a54d6ad6499806c4659b9870f6b73fb587a57b1297d1fb52faa146904b643e698f18572c393f7fd2c334b3f71484d9b2
7
+ data.tar.gz: 1005b451253f385241b319c7601f7bb2594502c712d7583f0c92761836acdda45dde4a027aafd303d6a730fa344ece4fb8276bcad1fbec58d6b2d07bda6d5e14
@@ -124,6 +124,10 @@ module CookbookOmnifetch
124
124
  integration.chef_server_download_concurrency
125
125
  end
126
126
 
127
+ def self.default_chef_server_http_client
128
+ integration.default_chef_server_http_client
129
+ end
130
+
127
131
  # Returns true or false if the given path contains a Chef Cookbook
128
132
  #
129
133
  # @param [#to_s] path
@@ -10,7 +10,7 @@ module CookbookOmnifetch
10
10
  def initialize(dependency, options = {})
11
11
  super
12
12
  @cookbook_version = options[:version]
13
- @http_client = options[:http_client]
13
+ @http_client = options[:http_client] || default_chef_server_http_client
14
14
  @uri ||= options[:chef_server]
15
15
  end
16
16
 
@@ -57,5 +57,16 @@ module CookbookOmnifetch
57
57
  "#{dependency.name}-#{cookbook_version}"
58
58
  end
59
59
 
60
+ # @see BaseLocation#cached_cookbook
61
+ def cached_cookbook
62
+ @cached_cookbook ||= CookbookOmnifetch.cached_cookbook_class.from_path(install_path)
63
+ end
64
+
65
+ private
66
+
67
+ def default_chef_server_http_client
68
+ CookbookOmnifetch.default_chef_server_http_client
69
+ end
70
+
60
71
  end
61
72
  end
@@ -17,7 +17,7 @@ module CookbookOmnifetch
17
17
  def initialize(dependency, options = {})
18
18
  super
19
19
  @cookbook_identifier = options[:identifier]
20
- @http_client = options[:http_client]
20
+ @http_client = options[:http_client] || default_chef_server_http_client
21
21
  @uri ||= options[:chef_server_artifact]
22
22
  end
23
23
 
@@ -61,12 +61,23 @@ module CookbookOmnifetch
61
61
  end
62
62
 
63
63
  def lock_data
64
- { "chef_server" => uri, "server_identifier" => cookbook_identifier }
64
+ { "chef_server_artifact" => uri, "identifier" => cookbook_identifier }
65
65
  end
66
66
 
67
67
  def cache_key
68
68
  "#{dependency.name}-#{cookbook_identifier}"
69
69
  end
70
70
 
71
+ # @see BaseLocation#cached_cookbook
72
+ def cached_cookbook
73
+ @cached_cookbook ||= CookbookOmnifetch.cached_cookbook_class.from_path(install_path)
74
+ end
75
+
76
+ private
77
+
78
+ def default_chef_server_http_client
79
+ CookbookOmnifetch.default_chef_server_http_client
80
+ end
81
+
71
82
  end
72
83
  end
@@ -39,6 +39,11 @@ module CookbookOmnifetch
39
39
  # commentary in cookbook_omnifetch.rb
40
40
  configurable :chef_server_download_concurrency
41
41
 
42
+ # HTTP client object that will be used for source option `http_client` by
43
+ # `ChefServerLocation` and `ChefServerArtifactLocation` if not explicitly
44
+ # passed
45
+ configurable :default_chef_server_http_client
46
+
42
47
  def initialize
43
48
  self.class.configurables.each do |configurable|
44
49
  instance_variable_set("@#{configurable}".to_sym, NullValue.new)
@@ -1,3 +1,3 @@
1
1
  module CookbookOmnifetch
2
- VERSION = "0.7.0"
2
+ VERSION = "0.8.0"
3
3
  end
@@ -21,6 +21,8 @@ RSpec.describe CookbookOmnifetch::ChefServerArtifactLocation do
21
21
 
22
22
  let(:expected_cache_key) { "example-467dc855408ce8b74f991c5dc2fd72a6aa369b60" }
23
23
 
24
+ let(:expected_install_path) { File.join(storage_path, expected_cache_key) }
25
+
24
26
  subject(:chef_server_artifact_location) { described_class.new(dependency, options) }
25
27
 
26
28
  before do
@@ -40,7 +42,7 @@ RSpec.describe CookbookOmnifetch::ChefServerArtifactLocation do
40
42
  expect(installer).to be_a(CookbookOmnifetch::MetadataBasedInstaller)
41
43
  expect(installer.http_client).to eq(http_client)
42
44
  expect(installer.url_path).to eq("/cookbook_artifacts/example/467dc855408ce8b74f991c5dc2fd72a6aa369b60")
43
- expect(installer.install_path.to_s).to eq(File.join(storage_path, expected_cache_key))
45
+ expect(installer.install_path.to_s).to eq(expected_install_path)
44
46
  end
45
47
 
46
48
  it "has a cache key containing the site URI and version" do
@@ -53,12 +55,46 @@ RSpec.describe CookbookOmnifetch::ChefServerArtifactLocation do
53
55
 
54
56
  it "provides lock data as a Hash" do
55
57
  expected_data = {
56
- "chef_server" => url,
57
- "server_identifier" => cookbook_identifier,
58
+ "chef_server_artifact" => url,
59
+ "identifier" => cookbook_identifier,
58
60
  }
59
61
  expect(chef_server_artifact_location.lock_data).to eq(expected_data)
60
62
  end
61
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
+
62
98
  describe "when installing" do
63
99
 
64
100
  let(:installer) { instance_double("CookbookOmnifetch::MetadataBasedInstaller") }
@@ -19,6 +19,8 @@ RSpec.describe CookbookOmnifetch::ChefServerLocation do
19
19
 
20
20
  let(:options) { { chef_server: url, version: cookbook_version, http_client: http_client } }
21
21
 
22
+ let(:expected_install_path) { File.join(storage_path, "example-0.5.0") }
23
+
22
24
  subject(:chef_server_location) { described_class.new(dependency, options) }
23
25
 
24
26
  before do
@@ -38,7 +40,7 @@ RSpec.describe CookbookOmnifetch::ChefServerLocation do
38
40
  expect(installer).to be_a(CookbookOmnifetch::MetadataBasedInstaller)
39
41
  expect(installer.http_client).to eq(http_client)
40
42
  expect(installer.url_path).to eq("/cookbooks/example/0.5.0")
41
- expect(installer.install_path.to_s).to eq(File.join(storage_path, "example-0.5.0"))
43
+ expect(installer.install_path.to_s).to eq(expected_install_path)
42
44
  end
43
45
 
44
46
  it "has a cache key containing the site URI and version" do
@@ -57,6 +59,40 @@ RSpec.describe CookbookOmnifetch::ChefServerLocation do
57
59
  expect(chef_server_location.lock_data).to eq(expected_data)
58
60
  end
59
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
+
60
96
  describe "when installing" do
61
97
 
62
98
  let(:installer) { instance_double("CookbookOmnifetch::MetadataBasedInstaller") }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cookbook-omnifetch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamie Winsor
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2017-11-03 00:00:00.000000000 Z
16
+ date: 2017-11-06 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: mixlib-archive