From b9d79fca8f1682e3c10fc634770180890d18e6df Mon Sep 17 00:00:00 2001 From: Adam Haymond Date: Thu, 16 Feb 2017 14:51:07 -0700 Subject: [PATCH 01/17] Added notifier for DataDog service_check --- .../notifier/data_dog_service_check.rb | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 lib/stoplight/notifier/data_dog_service_check.rb diff --git a/lib/stoplight/notifier/data_dog_service_check.rb b/lib/stoplight/notifier/data_dog_service_check.rb new file mode 100644 index 00000000..ce256159 --- /dev/null +++ b/lib/stoplight/notifier/data_dog_service_check.rb @@ -0,0 +1,53 @@ +# coding: utf-8 + +module Stoplight + module Notifier + # @see Base + class DataDogServiceCheck < Base + DEFAULT_OPTIONS = { + timestamp: Time.now, + tags: {} + }.freeze + + # @return [String] + attr_reader :api_key + # @return [Proc] + attr_reader :formatter + # @return[Hash{Symbol => Object}] + attr_reader :options + # @return [Object] + attr_reader :dog + # @return [String] + attr_reader :check + # @return [String] + attr_reader :host_name + + # @param api_key [String] + # @param check [String] + # @param host_name [String] + # @param formatter [Proc, nil] + # @param options [Hash{Symbol => Object}] + # @option options [Time] :timestamp + # @option options [Hash] :tags + def initialize(api_key, check, host_name, formatter = nil, options = nil) + @api_key = api_key + @check = check + @hostname = host_name + @formatter = formatter || Default::FORMATTER + @options = DEFAULT_OPTIONS.merge(options) + @dog = Dogapi::Client.new(api_key) + end + + def notify(light, from_color, to_color, error) + @options = @options.merge(message: formatter.call(light, from_color, to_color, error)) + if light.color == Color::GREEN + status = 0 + elsif light.color == Color::RED + status = 3 + end + options[:timestamp] = options[:timestamp].to_i + dog.service_check(check, host_name, status, options) + end + end + end +end From 2c46822d4131f4dd12fea370ae424400c7c69065 Mon Sep 17 00:00:00 2001 From: Adam Haymond Date: Thu, 16 Feb 2017 15:38:51 -0700 Subject: [PATCH 02/17] added new notifier require statement --- lib/stoplight.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/stoplight.rb b/lib/stoplight.rb index 818f4609..ace8493f 100644 --- a/lib/stoplight.rb +++ b/lib/stoplight.rb @@ -26,6 +26,7 @@ module Stoplight # rubocop:disable Style/Documentation require 'stoplight/notifier/logger' require 'stoplight/notifier/raven' require 'stoplight/notifier/slack' +require 'stoplight/notifier/data_dog_service_check' require 'stoplight/default' From 1ac4906a0bf115a35f5ccd64b303b60d2a54bf58 Mon Sep 17 00:00:00 2001 From: Adam Haymond Date: Fri, 17 Feb 2017 15:54:20 -0700 Subject: [PATCH 03/17] fixed host_name var spelling --- lib/stoplight/notifier/data_dog_service_check.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/stoplight/notifier/data_dog_service_check.rb b/lib/stoplight/notifier/data_dog_service_check.rb index ce256159..998b1b9f 100644 --- a/lib/stoplight/notifier/data_dog_service_check.rb +++ b/lib/stoplight/notifier/data_dog_service_check.rb @@ -32,7 +32,7 @@ class DataDogServiceCheck < Base def initialize(api_key, check, host_name, formatter = nil, options = nil) @api_key = api_key @check = check - @hostname = host_name + @host_name = host_name @formatter = formatter || Default::FORMATTER @options = DEFAULT_OPTIONS.merge(options) @dog = Dogapi::Client.new(api_key) From 56be95967f2e618c9360255b083013f1b0b398a6 Mon Sep 17 00:00:00 2001 From: Adam Haymond Date: Tue, 7 Mar 2017 11:29:24 -0700 Subject: [PATCH 04/17] resolved naming convention for check --- lib/stoplight/notifier/data_dog_service_check.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/stoplight/notifier/data_dog_service_check.rb b/lib/stoplight/notifier/data_dog_service_check.rb index 998b1b9f..a8afed39 100644 --- a/lib/stoplight/notifier/data_dog_service_check.rb +++ b/lib/stoplight/notifier/data_dog_service_check.rb @@ -29,9 +29,9 @@ class DataDogServiceCheck < Base # @param options [Hash{Symbol => Object}] # @option options [Time] :timestamp # @option options [Hash] :tags - def initialize(api_key, check, host_name, formatter = nil, options = nil) + def initialize(api_key, prefix = '', host_name, formatter = nil, options = nil) @api_key = api_key - @check = check + @prefix = prefix @host_name = host_name @formatter = formatter || Default::FORMATTER @options = DEFAULT_OPTIONS.merge(options) @@ -39,13 +39,14 @@ def initialize(api_key, check, host_name, formatter = nil, options = nil) end def notify(light, from_color, to_color, error) - @options = @options.merge(message: formatter.call(light, from_color, to_color, error)) + @options = @options.merge({message: formatter.call(light, from_color, to_color, error)}) if light.color == Color::GREEN status = 0 elsif light.color == Color::RED status = 3 end options[:timestamp] = options[:timestamp].to_i + check = @prefix.empty? ? 'stoplight.' + light.name : prefix + '.' + light.name dog.service_check(check, host_name, status, options) end end From fc5d7a17e1ea079847fb1fa6cb7f56b69eb2e6f8 Mon Sep 17 00:00:00 2001 From: Adam Haymond Date: Tue, 7 Mar 2017 13:13:22 -0700 Subject: [PATCH 05/17] fixed argument list --- lib/stoplight/notifier/data_dog_service_check.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/stoplight/notifier/data_dog_service_check.rb b/lib/stoplight/notifier/data_dog_service_check.rb index a8afed39..9dc9838c 100644 --- a/lib/stoplight/notifier/data_dog_service_check.rb +++ b/lib/stoplight/notifier/data_dog_service_check.rb @@ -29,7 +29,7 @@ class DataDogServiceCheck < Base # @param options [Hash{Symbol => Object}] # @option options [Time] :timestamp # @option options [Hash] :tags - def initialize(api_key, prefix = '', host_name, formatter = nil, options = nil) + def initialize(api_key, host_name, prefix = '', formatter = nil, options = nil) @api_key = api_key @prefix = prefix @host_name = host_name From d35ac5eb53dea7e1b5c03f7f0cfc6390e71b8879 Mon Sep 17 00:00:00 2001 From: Adam Haymond Date: Tue, 7 Mar 2017 13:37:28 -0700 Subject: [PATCH 06/17] fixed var getter/setter --- lib/stoplight/notifier/data_dog_service_check.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/stoplight/notifier/data_dog_service_check.rb b/lib/stoplight/notifier/data_dog_service_check.rb index 9dc9838c..645d4184 100644 --- a/lib/stoplight/notifier/data_dog_service_check.rb +++ b/lib/stoplight/notifier/data_dog_service_check.rb @@ -18,7 +18,7 @@ class DataDogServiceCheck < Base # @return [Object] attr_reader :dog # @return [String] - attr_reader :check + attr_reader :prefix # @return [String] attr_reader :host_name From 9eb8e3cba99d4e2c275c0e2ff0511080327f6660 Mon Sep 17 00:00:00 2001 From: Adam Haymond Date: Tue, 7 Mar 2017 16:34:00 -0700 Subject: [PATCH 07/17] fixed statuses --- lib/stoplight/notifier/data_dog_service_check.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/stoplight/notifier/data_dog_service_check.rb b/lib/stoplight/notifier/data_dog_service_check.rb index 645d4184..fa41a67e 100644 --- a/lib/stoplight/notifier/data_dog_service_check.rb +++ b/lib/stoplight/notifier/data_dog_service_check.rb @@ -42,7 +42,11 @@ def notify(light, from_color, to_color, error) @options = @options.merge({message: formatter.call(light, from_color, to_color, error)}) if light.color == Color::GREEN status = 0 + elsif light.color == Color::YELLOW + status = 1 elsif light.color == Color::RED + status = 2 + else status = 3 end options[:timestamp] = options[:timestamp].to_i From fdfc379809445f9694597f28b0f9fc28a5776820 Mon Sep 17 00:00:00 2001 From: Adam Haymond Date: Wed, 8 Mar 2017 10:23:09 -0700 Subject: [PATCH 08/17] cleaned up syntax --- .../notifier/data_dog_service_check.rb | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/stoplight/notifier/data_dog_service_check.rb b/lib/stoplight/notifier/data_dog_service_check.rb index fa41a67e..d94ac720 100644 --- a/lib/stoplight/notifier/data_dog_service_check.rb +++ b/lib/stoplight/notifier/data_dog_service_check.rb @@ -29,7 +29,7 @@ class DataDogServiceCheck < Base # @param options [Hash{Symbol => Object}] # @option options [Time] :timestamp # @option options [Hash] :tags - def initialize(api_key, host_name, prefix = '', formatter = nil, options = nil) + def initialize(api_key, host_name, prefix, formatter = nil, options = nil) @api_key = api_key @prefix = prefix @host_name = host_name @@ -39,19 +39,21 @@ def initialize(api_key, host_name, prefix = '', formatter = nil, options = nil) end def notify(light, from_color, to_color, error) - @options = @options.merge({message: formatter.call(light, from_color, to_color, error)}) - if light.color == Color::GREEN - status = 0 - elsif light.color == Color::YELLOW - status = 1 - elsif light.color == Color::RED - status = 2 - else - status = 3 - end + message = formatter.call(light, from_color, to_color, error) options[:timestamp] = options[:timestamp].to_i - check = @prefix.empty? ? 'stoplight.' + light.name : prefix + '.' + light.name - dog.service_check(check, host_name, status, options) + opts = options.merge( + message: message) + check = prefix.gsub(/\.$/,'') + '.' + light.name + dog.service_check(check, host_name, get_status(light.color), opts) + end + + def get_status(color) + case light.color + when Color::GREEN then 0 + when Color::YELLOW then 1 + when Color::RED then 2 + else 3 + end end end end From 9703c506a766bd51b68cfab44884f4e0af96d60a Mon Sep 17 00:00:00 2001 From: Adam Haymond Date: Wed, 8 Mar 2017 10:40:25 -0700 Subject: [PATCH 09/17] cleaning up more syntax for rubocop --- .../notifier/data_dog_service_check.rb | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/stoplight/notifier/data_dog_service_check.rb b/lib/stoplight/notifier/data_dog_service_check.rb index d94ac720..52f6858b 100644 --- a/lib/stoplight/notifier/data_dog_service_check.rb +++ b/lib/stoplight/notifier/data_dog_service_check.rb @@ -20,7 +20,7 @@ class DataDogServiceCheck < Base # @return [String] attr_reader :prefix # @return [String] - attr_reader :host_name + attr_reader :host # @param api_key [String] # @param check [String] @@ -29,10 +29,10 @@ class DataDogServiceCheck < Base # @param options [Hash{Symbol => Object}] # @option options [Time] :timestamp # @option options [Hash] :tags - def initialize(api_key, host_name, prefix, formatter = nil, options = nil) + def initialize(api_key, host, prefix, formatter = nil, options = nil) @api_key = api_key @prefix = prefix - @host_name = host_name + @host= host @formatter = formatter || Default::FORMATTER @options = DEFAULT_OPTIONS.merge(options) @dog = Dogapi::Client.new(api_key) @@ -40,15 +40,19 @@ def initialize(api_key, host_name, prefix, formatter = nil, options = nil) def notify(light, from_color, to_color, error) message = formatter.call(light, from_color, to_color, error) - options[:timestamp] = options[:timestamp].to_i opts = options.merge( - message: message) - check = prefix.gsub(/\.$/,'') + '.' + light.name - dog.service_check(check, host_name, get_status(light.color), opts) + message: message, + timestamp: options[:timestamp].to_i + ) + dog.service_check(check(light), host, get_status(light.color), opts) + end + + def check(light) + prefix.gsub(/\.$/, '') + '.' + light.name end def get_status(color) - case light.color + case color when Color::GREEN then 0 when Color::YELLOW then 1 when Color::RED then 2 From 426c23657ed3236dac476f05333a8651364dbe55 Mon Sep 17 00:00:00 2001 From: Adam Haymond Date: Wed, 8 Mar 2017 10:42:15 -0700 Subject: [PATCH 10/17] added space --- lib/stoplight/notifier/data_dog_service_check.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/stoplight/notifier/data_dog_service_check.rb b/lib/stoplight/notifier/data_dog_service_check.rb index 52f6858b..446f58bc 100644 --- a/lib/stoplight/notifier/data_dog_service_check.rb +++ b/lib/stoplight/notifier/data_dog_service_check.rb @@ -32,7 +32,7 @@ class DataDogServiceCheck < Base def initialize(api_key, host, prefix, formatter = nil, options = nil) @api_key = api_key @prefix = prefix - @host= host + @host = host @formatter = formatter || Default::FORMATTER @options = DEFAULT_OPTIONS.merge(options) @dog = Dogapi::Client.new(api_key) From ea597508255ff7c15a9eea0340cc7b66bd7c37d7 Mon Sep 17 00:00:00 2001 From: Adam Haymond Date: Wed, 8 Mar 2017 13:28:27 -0700 Subject: [PATCH 11/17] added test --- .../notifier/data_dog_service_check.rb | 22 +++++++++---------- stoplight.gemspec | 1 + 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/stoplight/notifier/data_dog_service_check.rb b/lib/stoplight/notifier/data_dog_service_check.rb index 446f58bc..5b8a6d54 100644 --- a/lib/stoplight/notifier/data_dog_service_check.rb +++ b/lib/stoplight/notifier/data_dog_service_check.rb @@ -9,33 +9,30 @@ class DataDogServiceCheck < Base tags: {} }.freeze - # @return [String] - attr_reader :api_key # @return [Proc] attr_reader :formatter + # @return [::Dogapi::Client] + attr_reader :dogapi # @return[Hash{Symbol => Object}] attr_reader :options - # @return [Object] - attr_reader :dog # @return [String] attr_reader :prefix # @return [String] attr_reader :host - # @param api_key [String] - # @param check [String] - # @param host_name [String] + # @param dogapi [::Dogapi::Client] + # @param prefix [String] + # @param host [String] # @param formatter [Proc, nil] # @param options [Hash{Symbol => Object}] # @option options [Time] :timestamp # @option options [Hash] :tags - def initialize(api_key, host, prefix, formatter = nil, options = nil) - @api_key = api_key - @prefix = prefix + def initialize(dogapi, host, prefix, formatter = nil, options = {}) + @dogapi = dogapi @host = host + @prefix = prefix @formatter = formatter || Default::FORMATTER @options = DEFAULT_OPTIONS.merge(options) - @dog = Dogapi::Client.new(api_key) end def notify(light, from_color, to_color, error) @@ -44,7 +41,8 @@ def notify(light, from_color, to_color, error) message: message, timestamp: options[:timestamp].to_i ) - dog.service_check(check(light), host, get_status(light.color), opts) + dogapi.service_check(check(light), host, get_status(light.color), opts) + message end def check(light) diff --git a/stoplight.gemspec b/stoplight.gemspec index b9bf14be..59324c40 100644 --- a/stoplight.gemspec +++ b/stoplight.gemspec @@ -38,6 +38,7 @@ Gem::Specification.new do |gem| 'fakeredis' => '0.5', 'hipchat' => '1.5', 'honeybadger' => '2.5', + 'dogapi' => '1.25.0', 'sentry-raven' => '1.2', 'rake' => '11.1', 'redis' => '3.2', From cfbdb544392fc3ca9de68ed861906d1943ba12ec Mon Sep 17 00:00:00 2001 From: Adam Haymond Date: Wed, 8 Mar 2017 13:33:01 -0700 Subject: [PATCH 12/17] Actually added tests --- .../notifier/data_dog_service_check_spec.rb | 128 ++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 spec/stoplight/notifier/data_dog_service_check_spec.rb diff --git a/spec/stoplight/notifier/data_dog_service_check_spec.rb b/spec/stoplight/notifier/data_dog_service_check_spec.rb new file mode 100644 index 00000000..33d34b2c --- /dev/null +++ b/spec/stoplight/notifier/data_dog_service_check_spec.rb @@ -0,0 +1,128 @@ +# coding: utf-8 + +require 'spec_helper' + +# require 'dogapi' +module Dogapi + class Client + def initialize(*) + end + end +end + +RSpec.describe Stoplight::Notifier::DataDogServiceCheck do + $prefix = 'stoplight' + $host = 'myhostname' + it 'is a class' do + expect(described_class).to be_a(Class) + end + + it 'is a subclass of Base' do + expect(described_class).to be < Stoplight::Notifier::Base + end + + describe '#formatter' do + it 'is initially the default' do + expect(described_class.new(nil, $host, $prefix).formatter).to eql( + Stoplight::Default::FORMATTER + ) + end + + it 'reads the formatter' do + formatter = proc {} + expect(described_class.new(nil, $host, $prefix, formatter).formatter).to eql(formatter) + end + end + + describe '#options' do + it 'is intiially the default' do + expect(described_class.new(nil, $host, $prefix).options).to eql( + Stoplight::Notifier::DataDogServiceCheck::DEFAULT_OPTIONS + ) + end + + it 'reads the options' do + options = { key: :value } + expect(described_class.new(nil, $host, $prefix, nil, options).options).to eql( + Stoplight::Notifier::DataDogServiceCheck::DEFAULT_OPTIONS.merge(options) + ) + end + end + + describe '#dogapi' do + it 'reads the Dogapi client' do + dogapi = Dogapi::Client.new('API token') + expect(described_class.new(dogapi, $host, $prefix).dogapi) + .to eql(dogapi) + end + end + + describe '#host' do + it 'reads the host' do + expect(described_class.new(nil, $host, $prefix).host).to eql($host) + end + end + + describe '#prefix' do + it 'reads the prefix' do + expect(described_class.new(nil, $host, $prefix).prefix).to eql($prefix) + end + end + + describe '#check' do + let(:light) { Stoplight::Light.new(name, &code) } + let(:name) { ('a'..'z').to_a.shuffle.join } + let(:code) { -> {} } + let(:notifier) { described_class.new(nil, $host, $prefix) } + + it 'returns the prefix combined with the stoplight name' do + expect(notifier.check(light)).to eql($prefix + '.' + name) + end + end + + describe '#get_status' do + let(:light) { Stoplight::Light.new(name, &code) } + let(:name) { ('a'..'z').to_a.shuffle.join } + let(:code) { -> {} } + let(:notifier) { described_class.new(nil, $host, $prefix) } + + it 'returns 0 for a working stoplight' do + expect(notifier.get_status(light.color)).to eql(0) + end + + context "after the stoplight is red" do + let(:light) { Stoplight::Light.new(name, &code).with_threshold(0) } + let(:code) { -> { 0/0 } } + it 'returns 2 for a broken stoplight' do + expect(notifier.get_status(light.color)).to eql(2) + end + end + end + + describe '#notify' do + let(:light) { Stoplight::Light.new(name, &code) } + let(:name) { ('a'..'z').to_a.shuffle.join } + let(:code) { -> {} } + let(:from_color) { Stoplight::Color::GREEN } + let(:to_color) { Stoplight::Color::RED } + let(:notifier) { described_class.new(dogapi, $host, $prefix) } + let(:dogapi) { double(Dogapi::Client) } + let(:api_key) { ('a'..'z').to_a.shuffle.join } + + before do + allow(dogapi).to receive(:service_check) + end + + it 'returns the message' do + error = nil + expect(notifier.notify(light, from_color, to_color, error)) + .to eql(notifier.formatter.call(light, from_color, to_color, error)) + end + + it 'returns the message with an error' do + error = ZeroDivisionError.new('divide by 0') + expect(notifier.notify(light, from_color, to_color, error)) + .to eql(notifier.formatter.call(light, from_color, to_color, error)) + end + end +end From 77d752f9999a224c93c5bfef6872a16449ea19ba Mon Sep 17 00:00:00 2001 From: Adam Haymond Date: Wed, 8 Mar 2017 14:17:50 -0700 Subject: [PATCH 13/17] rubocop is the bain of all existence --- .../notifier/data_dog_service_check_spec.rb | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/spec/stoplight/notifier/data_dog_service_check_spec.rb b/spec/stoplight/notifier/data_dog_service_check_spec.rb index 33d34b2c..194e38f9 100644 --- a/spec/stoplight/notifier/data_dog_service_check_spec.rb +++ b/spec/stoplight/notifier/data_dog_service_check_spec.rb @@ -11,8 +11,8 @@ def initialize(*) end RSpec.describe Stoplight::Notifier::DataDogServiceCheck do - $prefix = 'stoplight' - $host = 'myhostname' + prefix = 'stoplight' + host = 'myhostname' it 'is a class' do expect(described_class).to be_a(Class) end @@ -23,27 +23,31 @@ def initialize(*) describe '#formatter' do it 'is initially the default' do - expect(described_class.new(nil, $host, $prefix).formatter).to eql( + expect(described_class.new(nil, host, prefix).formatter).to eql( Stoplight::Default::FORMATTER ) end it 'reads the formatter' do formatter = proc {} - expect(described_class.new(nil, $host, $prefix, formatter).formatter).to eql(formatter) + expect(described_class + .new(nil, host, prefix, formatter).formatter) + .to eql(formatter) end end describe '#options' do it 'is intiially the default' do - expect(described_class.new(nil, $host, $prefix).options).to eql( + expect(described_class.new(nil, host, prefix).options).to eql( Stoplight::Notifier::DataDogServiceCheck::DEFAULT_OPTIONS ) end it 'reads the options' do options = { key: :value } - expect(described_class.new(nil, $host, $prefix, nil, options).options).to eql( + expect(described_class + .new(nil, host, prefix, nil, options).options) + .to eql( Stoplight::Notifier::DataDogServiceCheck::DEFAULT_OPTIONS.merge(options) ) end @@ -52,20 +56,20 @@ def initialize(*) describe '#dogapi' do it 'reads the Dogapi client' do dogapi = Dogapi::Client.new('API token') - expect(described_class.new(dogapi, $host, $prefix).dogapi) + expect(described_class.new(dogapi, host, prefix).dogapi) .to eql(dogapi) end end describe '#host' do it 'reads the host' do - expect(described_class.new(nil, $host, $prefix).host).to eql($host) + expect(described_class.new(nil, host, prefix).host).to eql(host) end end describe '#prefix' do it 'reads the prefix' do - expect(described_class.new(nil, $host, $prefix).prefix).to eql($prefix) + expect(described_class.new(nil, host, prefix).prefix).to eql(prefix) end end @@ -73,10 +77,10 @@ def initialize(*) let(:light) { Stoplight::Light.new(name, &code) } let(:name) { ('a'..'z').to_a.shuffle.join } let(:code) { -> {} } - let(:notifier) { described_class.new(nil, $host, $prefix) } + let(:notifier) { described_class.new(nil, host, prefix) } it 'returns the prefix combined with the stoplight name' do - expect(notifier.check(light)).to eql($prefix + '.' + name) + expect(notifier.check(light)).to eql(prefix + '.' + name) end end @@ -84,13 +88,13 @@ def initialize(*) let(:light) { Stoplight::Light.new(name, &code) } let(:name) { ('a'..'z').to_a.shuffle.join } let(:code) { -> {} } - let(:notifier) { described_class.new(nil, $host, $prefix) } + let(:notifier) { described_class.new(nil, host, prefix) } it 'returns 0 for a working stoplight' do expect(notifier.get_status(light.color)).to eql(0) end - context "after the stoplight is red" do + context 'after the stoplight is red' do let(:light) { Stoplight::Light.new(name, &code).with_threshold(0) } let(:code) { -> { 0/0 } } it 'returns 2 for a broken stoplight' do @@ -105,7 +109,7 @@ def initialize(*) let(:code) { -> {} } let(:from_color) { Stoplight::Color::GREEN } let(:to_color) { Stoplight::Color::RED } - let(:notifier) { described_class.new(dogapi, $host, $prefix) } + let(:notifier) { described_class.new(dogapi, host, prefix) } let(:dogapi) { double(Dogapi::Client) } let(:api_key) { ('a'..'z').to_a.shuffle.join } From 3fbbe08942fab605edd22ef53e7f3c81858d6947 Mon Sep 17 00:00:00 2001 From: Adam Haymond Date: Wed, 8 Mar 2017 14:18:41 -0700 Subject: [PATCH 14/17] rubocop I hate you --- spec/stoplight/notifier/data_dog_service_check_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/stoplight/notifier/data_dog_service_check_spec.rb b/spec/stoplight/notifier/data_dog_service_check_spec.rb index 194e38f9..b13a6925 100644 --- a/spec/stoplight/notifier/data_dog_service_check_spec.rb +++ b/spec/stoplight/notifier/data_dog_service_check_spec.rb @@ -96,7 +96,7 @@ def initialize(*) context 'after the stoplight is red' do let(:light) { Stoplight::Light.new(name, &code).with_threshold(0) } - let(:code) { -> { 0/0 } } + let(:code) { -> { 0 / 0 } } it 'returns 2 for a broken stoplight' do expect(notifier.get_status(light.color)).to eql(2) end From 003826a714abfe5dfd48021544adf3e0efa894b7 Mon Sep 17 00:00:00 2001 From: Adam Haymond Date: Wed, 8 Mar 2017 14:24:00 -0700 Subject: [PATCH 15/17] rubocop will die a slow painful death --- spec/stoplight/notifier/data_dog_service_check_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/stoplight/notifier/data_dog_service_check_spec.rb b/spec/stoplight/notifier/data_dog_service_check_spec.rb index b13a6925..4941ce7e 100644 --- a/spec/stoplight/notifier/data_dog_service_check_spec.rb +++ b/spec/stoplight/notifier/data_dog_service_check_spec.rb @@ -48,8 +48,8 @@ def initialize(*) expect(described_class .new(nil, host, prefix, nil, options).options) .to eql( - Stoplight::Notifier::DataDogServiceCheck::DEFAULT_OPTIONS.merge(options) - ) + Stoplight::Notifier::DataDogServiceCheck::DEFAULT_OPTIONS.merge(options) + ) end end From e1603aac04720d74164dcd8e0ffb86724ab2f5f7 Mon Sep 17 00:00:00 2001 From: Adam Haymond Date: Wed, 8 Mar 2017 14:26:21 -0700 Subject: [PATCH 16/17] line length fix... --- spec/stoplight/notifier/data_dog_service_check_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/stoplight/notifier/data_dog_service_check_spec.rb b/spec/stoplight/notifier/data_dog_service_check_spec.rb index 4941ce7e..5223034f 100644 --- a/spec/stoplight/notifier/data_dog_service_check_spec.rb +++ b/spec/stoplight/notifier/data_dog_service_check_spec.rb @@ -48,7 +48,8 @@ def initialize(*) expect(described_class .new(nil, host, prefix, nil, options).options) .to eql( - Stoplight::Notifier::DataDogServiceCheck::DEFAULT_OPTIONS.merge(options) + Stoplight::Notifier::DataDogServiceCheck::DEFAULT_OPTIONS + .merge(options) ) end end From 192b24dc765d8712adfab7b2a6bcc48ef97f98fa Mon Sep 17 00:00:00 2001 From: Adam Haymond Date: Wed, 8 Mar 2017 14:54:07 -0700 Subject: [PATCH 17/17] full test coverage --- lib/stoplight/notifier/data_dog_service_check.rb | 3 +-- spec/stoplight/notifier/data_dog_service_check_spec.rb | 10 ++++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/stoplight/notifier/data_dog_service_check.rb b/lib/stoplight/notifier/data_dog_service_check.rb index 5b8a6d54..b7bef896 100644 --- a/lib/stoplight/notifier/data_dog_service_check.rb +++ b/lib/stoplight/notifier/data_dog_service_check.rb @@ -52,9 +52,8 @@ def check(light) def get_status(color) case color when Color::GREEN then 0 - when Color::YELLOW then 1 when Color::RED then 2 - else 3 + else 1 end end end diff --git a/spec/stoplight/notifier/data_dog_service_check_spec.rb b/spec/stoplight/notifier/data_dog_service_check_spec.rb index 5223034f..d3e0979f 100644 --- a/spec/stoplight/notifier/data_dog_service_check_spec.rb +++ b/spec/stoplight/notifier/data_dog_service_check_spec.rb @@ -95,10 +95,16 @@ def initialize(*) expect(notifier.get_status(light.color)).to eql(0) end - context 'after the stoplight is red' do + context 'when the stoplight is yellow' do + it 'returns 1' do + expect(notifier.get_status('yellow')).to eql(1) + end + end + + context 'when the stoplight is red' do let(:light) { Stoplight::Light.new(name, &code).with_threshold(0) } let(:code) { -> { 0 / 0 } } - it 'returns 2 for a broken stoplight' do + it 'returns 2' do expect(notifier.get_status(light.color)).to eql(2) end end