diff --git a/scripts/cctray.check b/scripts/cctray.check
index 410c9d7..d1508a1 100755
--- a/scripts/cctray.check
+++ b/scripts/cctray.check
@@ -42,13 +42,28 @@ class CCTray
end
def latest_status
- name = [@pipeline, @stage, @job].compact.join(" :: ")
+ projects = exact_match
+ projects = partial_match if projects.empty?
- projects = @feed.xpath('//Project').select do |proj|
- proj.attr('name').downcase.include?(name.downcase)
+ CCTrayMultiProjectStatus.new(projects)
+ end
+
+ def partial_match
+ name = name = [@pipeline, @stage, @job].compact.join(" :: ").downcase
+
+ @feed.xpath('//Project').select do |proj|
+ proj.attr('name').downcase.include?(name)
end
+ end
- CCTrayMultiProjectStatus.new(projects)
+ def exact_match
+ @feed.xpath('//Project').select do |proj|
+ proj_pipeline, proj_stage, proj_job, _ = proj.attr('name').split(' :: ')
+ [ [ @pipeline, @stage, @job ], [ proj_pipeline, proj_stage, proj_job ]].transpose.all? do |attribute_to_compare, proj_attribute|
+ attribute_to_compare.nil? ||
+ (!proj_attribute.nil? && attribute_to_compare.downcase == proj_attribute.downcase)
+ end
+ end
end
end
diff --git a/scripts/specs/cctray_spec.rb b/scripts/specs/cctray_spec.rb
index d39eff2..41def88 100644
--- a/scripts/specs/cctray_spec.rb
+++ b/scripts/specs/cctray_spec.rb
@@ -12,6 +12,16 @@
+
+
+
+
+
+
+
+
+
+
XML
@@ -30,18 +40,50 @@
it_returns_ok %w(http://cd-server.example.com/cctray.xml goodPipe)
it_returns_fail %w(http://cd-server.example.com/cctray.xml aBadPipeline)
it_returns_changing %w(http://cd-server.example.com/cctray.xml goodPipe)
+
+ context 'when it matches some pipeline names fully' do
+ it_returns_ok %w(http://cd-server.example.com/cctray.xml Pipeline)
+ end
+
+ context 'when it does not match any pipeline name fully' do
+ it_returns_fail %w(http://cd-server.example.com/cctray.xml Pipeline_)
+ end
end
context 'when using stage specific api' do
it_returns_ok %w(http://cd-server.example.com/cctray.xml goodPipe successfulStage)
it_returns_fail %w(http://cd-server.example.com/cctray.xml aBadPipeline aBrokenStage)
it_returns_changing %w(http://cd-server.example.com/cctray.xml goodPipe busyStage)
+
+ context 'when it matches some pipeline and job name fully' do
+ context "when check does not indicate changing" do
+ let(:opts) { %w(http://cd-server.example.com/cctray.xml Pipeline OtherStage) }
+
+ it "does not return changing result" do
+ subject.latest_status.as_json[:changing].should == false
+ end
+ end
+ end
+
+ it_returns_changing %w(http://cd-server.example.com/cctray.xml Pipeline OtherStag)
end
context 'when using job specific api' do
it_returns_ok %w(http://cd-server.example.com/cctray.xml goodPipe successfulStage reliablyExcellentJob)
it_returns_fail %w(http://cd-server.example.com/cctray.xml aBadPipeline aBrokenStage anEvilJob)
it_returns_changing %w(http://cd-server.example.com/cctray.xml goodPipe busyStage workingJob)
+
+ context 'when it matches some pipeline and job name fully' do
+ context "when check does not indicate changing" do
+ let(:opts) { %w(http://cd-server.example.com/cctray.xml Pipeline SomeStage job) }
+
+ it "does not return changing result" do
+ subject.latest_status.as_json[:changing].should == false
+ end
+ end
+ end
+
+ it_returns_changing %w(http://cd-server.example.com/cctray.xml Pipeline SomeStage jobWorking)
end
context 'when using basic auth' do
diff --git a/scripts/specs/site_spec.rb b/scripts/specs/site_spec.rb
index a7d9c5b..59df234 100644
--- a/scripts/specs/site_spec.rb
+++ b/scripts/specs/site_spec.rb
@@ -2,8 +2,8 @@
require "spec_helper"
describe_check :Site do
- it_returns_ok %w(http://www.google.com)
+ it_returns_ok %w(http://www.bing.com/)
# Google's non-www version redirects to www
- it_returns_fail %w(http://google.com)
+ it_returns_fail %w(http://bing.com)
end