sensu-settings 5.1.0 → 5.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b105b89c40f34934a546ccf394ae680e3c576ecb
4
- data.tar.gz: 7761ac36a88894957b99509e3db28285dbe70d27
3
+ metadata.gz: d8924c88d3f2c09c838a8d63483dc5c5b43e4dfb
4
+ data.tar.gz: 6602361eb730baa005e103d0f916dc73c387febc
5
5
  SHA512:
6
- metadata.gz: 11439eb54a3e92cc7cbc6c38afad9daec1027c6df2738e0709e3ef4ad0da9097bfc55bfc47927eebe9d399569f26e2b14231209900c167083aca1abe1333a189
7
- data.tar.gz: 6c2b3dd3773e45e87ad0669cf216a0cd5e5953dd339a71abe11d815e5f770860908ddb09b04f771ac3239db3b9e7f291f1bb0f89cee91848fdf36c3234bb4022
6
+ metadata.gz: 51c1f51bd223da49a9cf4221ae0504758841572628359d491dba61e5a091a77fbe51957f2aca71a4deb4a00c612982c485075a110239e6ecf5d8ebcd41166bc7
7
+ data.tar.gz: 343e7d524dc24d974007ee1bf190048084ab0005ed23ec1574bf801d31dc29f50083b62490f49991c80a0820c1ac54d2d68707278bbebd2ffefc17364032195e
@@ -14,7 +14,7 @@ module Sensu
14
14
  @loader = Loader.new
15
15
  @loader.load_env
16
16
  if options[:config_file]
17
- @loader.load_file(options[:config_file])
17
+ @loader.load_file(options[:config_file], false)
18
18
  end
19
19
  if options[:config_dir]
20
20
  @loader.load_directory(options[:config_dir])
@@ -99,7 +99,9 @@ module Sensu
99
99
  # Load settings from a JSON file.
100
100
  #
101
101
  # @param [String] file path.
102
- def load_file(file)
102
+ # @param must_exist [TrueClass, FalseClass] if the file must
103
+ # exist and is readable.
104
+ def load_file(file, must_exist=true)
103
105
  if File.file?(file) && File.readable?(file)
104
106
  begin
105
107
  warning("loading config file", :file => file)
@@ -122,8 +124,11 @@ module Sensu
122
124
  :error => error.to_s
123
125
  })
124
126
  end
125
- else
127
+ elsif must_exist
126
128
  load_error("config file does not exist or is not readable", :file => file)
129
+ else
130
+ warning("config file does not exist or is not readable", :file => file)
131
+ warning("ignoring config file", :file => file)
127
132
  end
128
133
  end
129
134
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "sensu-settings"
5
- spec.version = "5.1.0"
5
+ spec.version = "5.2.0"
6
6
  spec.authors = ["Sean Porter"]
7
7
  spec.email = ["portertech@gmail.com"]
8
8
  spec.summary = "The Sensu settings library, loader and validator"
data/spec/loader_spec.rb CHANGED
@@ -114,6 +114,14 @@ describe "Sensu::Settings::Loader" do
114
114
  expect(error[:message]).to include("config file does not exist or is not readable")
115
115
  end
116
116
 
117
+ it "can attempt to load settings from a nonexistent file and ignore it" do
118
+ @loader.load_file("/tmp/bananaphone", false)
119
+ expect(@loader.errors.length).to eq(0)
120
+ expect(@loader.warnings.length).to eq(2)
121
+ warning = @loader.warnings.last
122
+ expect(warning[:message]).to include("ignoring config file")
123
+ end
124
+
117
125
  it "can attempt to load settings from a file with invalid JSON" do
118
126
  expect {
119
127
  @loader.load_file(File.join(@assets_dir, "invalid.json"))
@@ -51,9 +51,17 @@ describe "Sensu::Settings" do
51
51
  end
52
52
 
53
53
  it "can catch load errors" do
54
- settings = Sensu::Settings.load(:config_file => "/tmp/bananaphone")
54
+ settings = Sensu::Settings.load(:config_file => File.join(@assets_dir, "invalid.json"))
55
55
  expect(settings.errors.length).to eq(1)
56
56
  error = settings.errors.first
57
- expect(error[:message]).to include("config file does not exist or is not readable")
57
+ expect(error[:message]).to include("config file must be valid json")
58
+ end
59
+
60
+ it "can handle a nonexistent config.json" do
61
+ settings = Sensu::Settings.load(:config_file => "/tmp/bananaphone")
62
+ expect(settings.errors.length).to eq(0)
63
+ expect(settings.warnings.length).to eq(2)
64
+ warning = settings.warnings.last
65
+ expect(warning[:message]).to include("ignoring config file")
58
66
  end
59
67
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-settings
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.0
4
+ version: 5.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Porter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-31 00:00:00.000000000 Z
11
+ date: 2016-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sensu-json