Skip to content

Commit

Permalink
Merge pull request #852 from rishabhBudhouliya/WipeWorkspaceTest
Browse files Browse the repository at this point in the history
[GSoC] Addition of unit test for WipeWorkspace extension behavior in GitSCM
  • Loading branch information
MarkEWaite authored Mar 9, 2020
2 parents 5b1b9cd + 0c41d45 commit f46eebf
Showing 1 changed file with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,11 +1,54 @@
package hudson.plugins.git.extensions.impl;

import hudson.EnvVars;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.Result;
import hudson.plugins.git.TestGitRepo;
import hudson.plugins.git.extensions.GitSCMExtension;
import hudson.plugins.git.extensions.GitSCMExtensionTest;
import nl.jqno.equalsverifier.EqualsVerifier;
import org.jenkinsci.plugins.gitclient.Git;
import org.jenkinsci.plugins.gitclient.GitClient;
import org.junit.Test;
import org.jvnet.hudson.test.WithoutJenkins;

public class WipeWorkspaceTest {
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

public class WipeWorkspaceTest extends GitSCMExtensionTest {

TestGitRepo repo;
GitClient git;

@Override
public void before() throws Exception {
// do nothing
}

@Override
protected GitSCMExtension getExtension() {
return new WipeWorkspace();
}

/**
* Test to confirm the behavior of forcing re-clone before checkout by cleaning the workspace first.
**/
@Test
public void testWipeWorkspace() throws Exception {
repo = new TestGitRepo("repo", tmp.newFolder(), listener);
git = Git.with(listener, new EnvVars()).in(repo.gitDir).getClient();

FreeStyleProject projectWithMaster = setupBasicProject(repo);
git.commit("First commit");
FreeStyleBuild build = build(projectWithMaster, Result.SUCCESS);

String buildLog = build.getLog();
assertThat("Workspace not cleaned before checkout",true, is(buildLog.contains("Wiping out workspace first.")));
}

@Test
@WithoutJenkins
public void equalsContract() {
EqualsVerifier.forClass(WipeWorkspace.class)
.usingGetClass()
Expand Down

0 comments on commit f46eebf

Please sign in to comment.