Skip to content

Commit

Permalink
add more test cases for thorough testing
Browse files Browse the repository at this point in the history
  • Loading branch information
upcomingnewton committed Aug 19, 2016
1 parent 13c5d65 commit 029139c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
4 changes: 2 additions & 2 deletions plugins/jenkins/app/models/samson/jenkins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ def notify_emails
if ENV["JENKINS_NOTIFY_COMMITTERS"]
emails.concat(deploy.changeset.commits.map(&:author_email))
end
emails = emails.map! { |x| Mail::Address.new(x) }
emails.map! { |x| Mail::Address.new(x) }
if ENV["GOOGLE_DOMAIN"]
emails = emails.select! { |x| ENV["GOOGLE_DOMAIN"].match(x.domain) }
emails.select! { |x| ("@" + x.domain).casecmp(ENV["GOOGLE_DOMAIN"]) == 0 }
end
emails.map(&:address).uniq.join(",")
end
Expand Down
22 changes: 18 additions & 4 deletions plugins/jenkins/test/models/samson/jenkins_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ def stub_add_changeset
commit1.stubs("author_email").returns("[email protected]")
commit2 = stub("commit2")
commit2.stubs("author_email").returns("[email protected]")
changeset.stubs(:commits).returns([commit1, commit2])
commit3 = stub("commit3")
commit3.stubs("author_email").returns("[email protected]")
commit4 = stub("commit4")
commit4.stubs("author_email").returns("[email protected]")
commit5 = stub("commit5")
commit5.stubs("author_email").returns("[email protected]")
changeset.stubs(:commits).returns([commit1, commit2, commit3, commit4, commit5])
deploy.stubs(:changeset).returns(changeset)
end

Expand Down Expand Up @@ -114,15 +120,23 @@ def stub_add_changeset

it "includes committer emails when JENKINS_NOTIFY_COMMITTERS is set" do
with_env 'JENKINS_NOTIFY_COMMITTERS': "1" do
stub_build_with_parameters("emails": '[email protected],[email protected],[email protected]')
stub_build_with_parameters("emails": '[email protected],[email protected],[email protected],[email protected],[email protected],[email protected]')
stub_get_build_id_from_queue(1)
jenkins.build.must_equal 1
end
end

it "filters emails by GOOGLE_DOMAIN" do
with_env 'GOOGLE_DOMAIN': 'example1.com' do
stub_build_with_parameters("emails": "")
with_env 'GOOGLE_DOMAIN': '@example.com' do
stub_build_with_parameters({})
stub_get_build_id_from_queue(1)
jenkins.build.must_equal 1
end
end

it "filters emails by GOOGLE_DOMAIN when JENKINS_NOTIFY_COMMITTERS is set" do
with_env 'GOOGLE_DOMAIN': '@example.com', 'JENKINS_NOTIFY_COMMITTERS': '1' do
stub_build_with_parameters("emails": '[email protected],[email protected],[email protected]')
stub_get_build_id_from_queue(1)
jenkins.build.must_equal 1
end
Expand Down

0 comments on commit 029139c

Please sign in to comment.