Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more prune stale tags tests #875

Merged
merged 3 commits into from
Apr 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
public class PruneStaleTag extends GitSCMExtension {

private static final String TAG_REF = "refs/tags/";
private boolean pruneTags;
private final boolean pruneTags;

/**
* Control pruning of tags that exist in the local repository but
Expand Down Expand Up @@ -158,7 +158,7 @@ public int hashCode() {
*/
@Override
public String toString() {
return "PruneStaleTag {}";
return "PruneStaleTag { " + pruneTags + " }";
}

@Symbol("pruneTags")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import nl.jqno.equalsverifier.EqualsVerifier;
import org.apache.commons.io.FileUtils;
import org.jenkinsci.plugins.gitclient.GitClient;
import org.jenkinsci.plugins.gitclient.TestCliGitAPIImpl;
Expand All @@ -40,6 +41,10 @@
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;

import hudson.EnvVars;
import hudson.Functions;
import hudson.model.Run;
Expand Down Expand Up @@ -230,4 +235,50 @@ private GitClient initRepository(File workspace) throws Exception {
return remoteClient;
}

@Test
public void testGetPruneTags() {
PruneStaleTag pruneEnabled = new PruneStaleTag(true);
assertThat(pruneEnabled.getPruneTags(), is(true));
}

@Test
public void testGetPruneTagsDisabled() {
PruneStaleTag pruneEnabled = new PruneStaleTag(false);
assertThat(pruneEnabled.getPruneTags(), is(false));
}

@Test
public void testEquals() {
EqualsVerifier.forClass(PruneStaleTag.class).usingGetClass().verify();
}

@Test
public void testHashCode() {
PruneStaleTag enabledOne = new PruneStaleTag(true);
PruneStaleTag enabledTwo = new PruneStaleTag(true);
assertThat(enabledOne.equals(enabledTwo), is(true));
assertThat(enabledTwo.equals(enabledOne), is(true));
assertThat(enabledOne.hashCode(), is(enabledTwo.hashCode()));

PruneStaleTag disabledOne = new PruneStaleTag(false);
PruneStaleTag disabledTwo = new PruneStaleTag(false);
assertThat(disabledOne.equals(disabledTwo), is(true));
assertThat(disabledTwo.equals(disabledOne), is(true));
assertThat(disabledOne.hashCode(), is(disabledTwo.hashCode()));

// Not required by hashCode contract, expected in this case
assertThat(enabledOne.hashCode(), not(is(disabledOne.hashCode())));
}

@Test
public void testToString() {
PruneStaleTag enabled = new PruneStaleTag(true);
assertThat(enabled.toString(), is("PruneStaleTag { true }"));
}

@Test
public void testToStringDisabled() {
PruneStaleTag disabled = new PruneStaleTag(false);
assertThat(disabled.toString(), is("PruneStaleTag { false }"));
}
}