summaryrefslogtreecommitdiff
path: root/spec/unit/config_fetcher_spec.rb
diff options
context:
space:
mode:
authordanielsdeleo <dan@chef.io>2016-01-26 13:32:29 -0800
committerdanielsdeleo <dan@chef.io>2016-01-27 12:38:54 -0800
commit05d98b354ab995fefd9ef6bc6d3e19bb5f960ad5 (patch)
treebf75f47b1b87ddbfddcb9100a803716eca1b65fe /spec/unit/config_fetcher_spec.rb
parent6defab990c91e07361cc27a41d506338ca915527 (diff)
downloadchef-05d98b354ab995fefd9ef6bc6d3e19bb5f960ad5.tar.gz
Force config file setting to absolute path in chef-client
Diffstat (limited to 'spec/unit/config_fetcher_spec.rb')
-rw-r--r--spec/unit/config_fetcher_spec.rb75
1 files changed, 53 insertions, 22 deletions
diff --git a/spec/unit/config_fetcher_spec.rb b/spec/unit/config_fetcher_spec.rb
index 794940c39a..82eca1cf1a 100644
--- a/spec/unit/config_fetcher_spec.rb
+++ b/spec/unit/config_fetcher_spec.rb
@@ -22,6 +22,21 @@ describe Chef::ConfigFetcher do
expect(fetcher.read_config).to eq(config_content)
end
+ it "gives the expanded path to the config file" do
+ expect(fetcher.expanded_path).to eq(config_location)
+ end
+
+ context "with a relative path" do
+
+ let(:config_location) { "client.rb" }
+
+ it "gives the expanded path to the config file" do
+ expected = File.join(Dir.pwd, config_location)
+ expect(fetcher.expanded_path).to eq(expected)
+ end
+
+ end
+
context "and consuming JSON" do
let(:config_location) { "/etc/chef/first-boot.json" }
@@ -53,45 +68,61 @@ describe Chef::ConfigFetcher do
end
- context "when loading a file over HTTP" do
+ context "with an HTTP URL config location" do
let(:config_location) { "https://example.com/client.rb" }
let(:config_content) { "# The client.rb content" }
- before do
- expect(Chef::HTTP::Simple).to receive(:new).
- with(config_location).
- and_return(http)
+ it "returns the config location unchanged for #expanded_path" do
+ expect(fetcher.expanded_path).to eq(config_location)
end
- it "reads the file over HTTP" do
- expect(http).to receive(:get).
- with("").and_return(config_content)
- expect(fetcher.read_config).to eq(config_content)
- end
+ describe "reading the file" do
- context "and consuming JSON" do
- let(:config_location) { "https://example.com/foo.json" }
+ before do
+ expect(Chef::HTTP::Simple).to receive(:new).
+ with(config_location).
+ and_return(http)
+ end
- it "fetches the file and parses it" do
- expect(http).to receive(:get).
- with("").and_return(valid_json)
- expect(fetcher.fetch_json).to eq({"a" => "b"})
+ it "reads the file over HTTP" do
+ expect(http).to receive(:get).
+ with("").and_return(config_content)
+ expect(fetcher.read_config).to eq(config_content)
end
- context "and the JSON is invalid" do
- it "reports the JSON error" do
+ context "and consuming JSON" do
+ let(:config_location) { "https://example.com/foo.json" }
+
+ it "fetches the file and parses it" do
expect(http).to receive(:get).
- with("").and_return(invalid_json)
+ with("").and_return(valid_json)
+ expect(fetcher.fetch_json).to eq({"a" => "b"})
+ end
- expect(Chef::Application).to receive(:fatal!).
- with(invalid_json_error_regex, 2)
- fetcher.fetch_json
+ context "and the JSON is invalid" do
+ it "reports the JSON error" do
+ expect(http).to receive(:get).
+ with("").and_return(invalid_json)
+
+ expect(Chef::Application).to receive(:fatal!).
+ with(invalid_json_error_regex, 2)
+ fetcher.fetch_json
+ end
end
end
end
end
+ context "with a nil config file argument" do
+
+ let(:config_location) { nil }
+
+ it "returns the config location unchanged for #expanded_path" do
+ expect(fetcher.expanded_path).to eq(nil)
+ end
+ end
+
end