From ade4a1a1e2fdfac7180cadebd574ffe5bdedd062 Mon Sep 17 00:00:00 2001 From: Maxim Epishchev Date: Tue, 19 Apr 2016 16:58:43 +0300 Subject: Available "pullRequestAuthor" env variable (featured from #83) Env variable "pullRequestAuthor" contain two parts of author: full name of user and short username in format, like: "Some Doo <@somedoo>". Add test for PR build filter: now we can filter also by author: "a:maxvodo" by example. --- src/test/java/BitbucketBuildFilterTest.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/test') diff --git a/src/test/java/BitbucketBuildFilterTest.java b/src/test/java/BitbucketBuildFilterTest.java index 3b35dbc..3a94c82 100644 --- a/src/test/java/BitbucketBuildFilterTest.java +++ b/src/test/java/BitbucketBuildFilterTest.java @@ -140,6 +140,26 @@ public class BitbucketBuildFilterTest { } } + @Test + @WithoutJenkins + public void authorFilter() { + BitbucketCause cause = EasyMock.createMock(BitbucketCause.class); + EasyMock.expect(cause.getTargetBranch()).andReturn("master").anyTimes(); + EasyMock.expect(cause.getSourceBranch()).andReturn("feature-master").anyTimes(); + EasyMock.expect(cause.getPullRequestAuthor()).andReturn("test").anyTimes(); + EasyMock.replay(cause); + + for(String f : new String[] {"a:test", "a:r:^test", "d: s: a:", "a:", "a:foo a:test"}) { + BitbucketBuildFilter filter = BitbucketBuildFilter.InstanceByString(f); + assertTrue(filter.approved(cause)); + } + + for(String f : new String[] {"s:feature-master", "d:master", "s:feature-master d: a:foo", "a:bar"}) { + BitbucketBuildFilter filter = BitbucketBuildFilter.InstanceByString(f); + assertFalse(filter.approved(cause)); + } + } + @Test @WithoutJenkins public void emptyGitSCMFilter() { -- cgit v1.2.3