Skip to content

Commit

Permalink
Work around JENKINS-67309
Browse files Browse the repository at this point in the history
  • Loading branch information
basil committed Apr 24, 2022
1 parent 3f62c0d commit 23b2654
Showing 1 changed file with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import hudson.plugins.git.extensions.impl.UserIdentity;
import io.jenkins.plugins.casc.misc.RoundTripAbstractTest;
import jenkins.plugins.git.traits.AuthorInChangelogTrait;
import jenkins.plugins.git.traits.BranchDiscoveryTrait;
import jenkins.plugins.git.traits.CheckoutOptionTrait;
import jenkins.plugins.git.traits.CleanAfterCheckoutTrait;
import jenkins.plugins.git.traits.CleanBeforeCheckoutTrait;
Expand All @@ -21,12 +20,13 @@
import jenkins.plugins.git.traits.RefSpecsSCMSourceTrait;
import jenkins.plugins.git.traits.RemoteNameSCMSourceTrait;
import jenkins.plugins.git.traits.SubmoduleOptionTrait;
import jenkins.plugins.git.traits.TagDiscoveryTrait;
import jenkins.plugins.git.traits.UserIdentityTrait;
import jenkins.plugins.git.traits.WipeWorkspaceTrait;
import jenkins.scm.api.SCMSource;
import jenkins.scm.impl.trait.RegexSCMHeadFilterTrait;
import jenkins.scm.impl.trait.WildcardSCMHeadFilterTrait;
import org.hamcrest.Description;
import org.hamcrest.DiagnosingMatcher;
import org.jenkinsci.plugins.workflow.libs.GlobalLibraries;
import org.jenkinsci.plugins.workflow.libs.LibraryConfiguration;
import org.jenkinsci.plugins.workflow.libs.LibraryRetriever;
Expand Down Expand Up @@ -64,11 +64,13 @@ protected void assertConfiguredAsExpected(RestartableJenkinsRule restartableJenk
assertThat(gitSCMSource.getTraits(), containsInAnyOrder(
//Discover branches
allOf(
instanceOf(BranchDiscoveryTrait.class)
new SimpleNameMatcher("BranchDiscoveryTrait")
// TODO after JENKINS-67309 instanceOf(BranchDiscoveryTrait.class)
),
// Discover tags
allOf(
instanceOf(TagDiscoveryTrait.class)
new SimpleNameMatcher("TagDiscoveryTrait")
// TODO after JENKINS-67309 instanceOf(TagDiscoveryTrait.class)
),
// Check out to matching local branch
allOf(
Expand Down Expand Up @@ -188,4 +190,32 @@ protected String stringInLogExpected() {
protected String configResource() {
return "global-with-modern-casc.yaml";
}

private static final class SimpleNameMatcher extends DiagnosingMatcher<Object> {
private final String expectedSimpleName;

public SimpleNameMatcher(String expectedSimpleName) {
this.expectedSimpleName = expectedSimpleName;
}

@Override
protected boolean matches(Object item, Description mismatch) {
if (item == null) {
mismatch.appendText("null");
return false;
}

if (!item.getClass().getSimpleName().equals(expectedSimpleName)) {
mismatch.appendValue(item).appendText(" is a " + item.getClass().getName());
return false;
}

return true;
}

@Override
public void describeTo(Description description) {
description.appendText("an instance of ").appendText(expectedSimpleName);
}
}
}

0 comments on commit 23b2654

Please sign in to comment.