Search in sources :

Example 11 with GitRepo

use of org.jenkinsci.test.acceptance.plugins.git.GitRepo in project acceptance-test-harness by jenkinsci.

the class GitPluginTest method default_strategy_to_choose_build.

@Test
public void default_strategy_to_choose_build() {
    final String BRANCH_NAME = "secondBranch";
    GitRepo repo = buildGitRepo();
    repo.createBranch(BRANCH_NAME);
    repo.transferToDockerContainer(host, port);
    // Default Strategy for master
    job.useScm(GitScm.class).url(repoUrl).credentials(USERNAME).chooseBuildStrategy("Default");
    job.save();
    Build b = job.startBuild();
    b.shouldSucceed();
    assertThat(b.getConsole(), Matchers.containsRegexp("Checking out Revision .* \\(refs/remotes/origin/master\\)", Pattern.MULTILINE));
    // Default Strategy for secondBranch
    job.configure();
    job.useScm(GitScm.class).branch(BRANCH_NAME);
    job.save();
    b = job.startBuild();
    b.shouldSucceed();
    assertThat(b.getConsole(), Matchers.containsRegexp("Checking out Revision .* \\(origin/" + BRANCH_NAME + "\\)", Pattern.MULTILINE));
    // Default Strategy for any branch
    job.configure();
    job.useScm(GitScm.class).branch("");
    job.save();
    b = job.startBuild();
    b.shouldSucceed();
    // 2 branches discovered
    assertThat(b.getConsole(), Matchers.containsRegexp("Checking out Revision .* \\(origin/.*, origin/.*\\)", Pattern.MULTILINE));
}
Also used : GitRepo(org.jenkinsci.test.acceptance.plugins.git.GitRepo) Build(org.jenkinsci.test.acceptance.po.Build) GitScm(org.jenkinsci.test.acceptance.plugins.git.GitScm) Test(org.junit.Test)

Example 12 with GitRepo

use of org.jenkinsci.test.acceptance.plugins.git.GitRepo in project acceptance-test-harness by jenkinsci.

the class GitPluginTest method buildGitRepo.

private GitRepo buildGitRepo() {
    GitRepo repo = new GitRepo();
    repo.changeAndCommitFoo("Initial commit");
    return repo;
}
Also used : GitRepo(org.jenkinsci.test.acceptance.plugins.git.GitRepo)

Example 13 with GitRepo

use of org.jenkinsci.test.acceptance.plugins.git.GitRepo in project acceptance-test-harness by jenkinsci.

the class GitPluginTest method test_clean_while_checkout.

/**
 * Invoked by {@link #clean_after_checkout()} and {@link #clean_before_checkout()}
 *
 * @param before Select "clean before" or "clean after"
 */
private void test_clean_while_checkout(boolean before) {
    GitRepo repo = buildGitRepo();
    repo.transferToDockerContainer(host, port);
    // configure and build to create untrackedFile.txt
    GitScm git = job.useScm(GitScm.class).url(repoUrl).credentials(USERNAME);
    if (before) {
        git.cleanBeforeCheckout();
    } else {
        git.cleanAfterCheckout();
    }
    job.addShellStep("touch untrackedFile.txt");
    job.save();
    job.startBuild().shouldSucceed();
    // configure and build to test if file has been removed
    job.configure();
    job.removeFirstBuildStep();
    job.addShellStep("ls && test ! -f untrackedFile.txt");
    job.save();
    job.startBuild().shouldSucceed();
}
Also used : GitRepo(org.jenkinsci.test.acceptance.plugins.git.GitRepo) GitScm(org.jenkinsci.test.acceptance.plugins.git.GitScm)

Example 14 with GitRepo

use of org.jenkinsci.test.acceptance.plugins.git.GitRepo in project acceptance-test-harness by jenkinsci.

the class GitPluginTest method advanced_clone_test.

@Test
public void advanced_clone_test() {
    final String TEST_INITIAL_COMMIT = "Initial commit";
    final String TEST_COMMIT1_MESSAGE = "First commit";
    final String TEST_COMMIT2_MESSAGE = "Second commit";
    Build b;
    GitRepo repo = buildGitRepo();
    repo.changeAndCommitFoo(TEST_COMMIT1_MESSAGE);
    repo.changeAndCommitFoo(TEST_COMMIT2_MESSAGE);
    repo.transferToDockerContainer(host, port);
    GitScm gitScm = job.useScm(GitScm.class).url(repoUrl).credentials(USERNAME);
    job.addShellStep("git log");
    job.save();
    b = job.startBuild();
    b.shouldSucceed();
    String console = b.getConsole();
    assertThat(console, Matchers.containsRegexp(TEST_INITIAL_COMMIT, Pattern.MULTILINE));
    assertThat(console, Matchers.containsRegexp(TEST_COMMIT1_MESSAGE, Pattern.MULTILINE));
    assertThat(console, Matchers.containsRegexp(TEST_COMMIT2_MESSAGE, Pattern.MULTILINE));
    job.configure();
    GitScm.AdvancedClone behaviour = gitScm.advancedClone().checkShallowClone(true).setNumDepth("2");
    job.save();
    b = job.startBuild();
    b.shouldSucceed();
    console = b.getConsole();
    assertThat(console, not(Matchers.containsRegexp(TEST_INITIAL_COMMIT, Pattern.MULTILINE)));
    assertThat(console, Matchers.containsRegexp(TEST_COMMIT1_MESSAGE, Pattern.MULTILINE));
    assertThat(console, Matchers.containsRegexp(TEST_COMMIT2_MESSAGE, Pattern.MULTILINE));
    job.configure();
    behaviour.setNumDepth("1");
    job.save();
    b = job.startBuild();
    b.shouldSucceed();
    console = b.getConsole();
    assertThat(console, not(Matchers.containsRegexp(TEST_INITIAL_COMMIT, Pattern.MULTILINE)));
    assertThat(console, not(Matchers.containsRegexp(TEST_COMMIT1_MESSAGE, Pattern.MULTILINE)));
    assertThat(console, Matchers.containsRegexp(TEST_COMMIT2_MESSAGE, Pattern.MULTILINE));
}
Also used : GitRepo(org.jenkinsci.test.acceptance.plugins.git.GitRepo) Build(org.jenkinsci.test.acceptance.po.Build) GitScm(org.jenkinsci.test.acceptance.plugins.git.GitScm) Test(org.junit.Test)

Example 15 with GitRepo

use of org.jenkinsci.test.acceptance.plugins.git.GitRepo in project acceptance-test-harness by jenkinsci.

the class GitPluginTest method advanced_checkout_test.

@Test
public void advanced_checkout_test() {
    final String TEST_COMMIT_MESSAGE = "First commit";
    final String TEST_TIME_OUT = "2";
    Build b;
    GitRepo repo = buildGitRepo();
    repo.changeAndCommitFoo(TEST_COMMIT_MESSAGE);
    repo.transferToDockerContainer(host, port);
    GitScm gitScm = job.useScm(GitScm.class).url(repoUrl).credentials(USERNAME);
    job.save();
    b = job.startBuild();
    b.shouldSucceed();
    String console = b.getConsole();
    String revision = getRevisionFromConsole(console);
    assertThat(console, not(Matchers.containsRegexp("git checkout -f " + revision + " # timeout=" + TEST_TIME_OUT, Pattern.MULTILINE)));
    job.configure();
    gitScm.advancedCheckout().setTimeOut(TEST_TIME_OUT);
    job.save();
    b = job.startBuild();
    b.shouldSucceed();
    console = b.getConsole();
    assertThat(console, Matchers.containsRegexp("git checkout -f " + revision + " # timeout=" + TEST_TIME_OUT, Pattern.MULTILINE));
}
Also used : GitRepo(org.jenkinsci.test.acceptance.plugins.git.GitRepo) Build(org.jenkinsci.test.acceptance.po.Build) GitScm(org.jenkinsci.test.acceptance.plugins.git.GitScm) Test(org.junit.Test)

Aggregations

GitRepo (org.jenkinsci.test.acceptance.plugins.git.GitRepo)19 Test (org.junit.Test)14 Build (org.jenkinsci.test.acceptance.po.Build)12 GitScm (org.jenkinsci.test.acceptance.plugins.git.GitScm)11 GitContainer (org.jenkinsci.test.acceptance.docker.fixtures.GitContainer)4 URL (java.net.URL)2 Matchers.containsString (org.hamcrest.Matchers.containsString)1 DockerAgentContainer (org.jenkinsci.test.acceptance.docker.fixtures.DockerAgentContainer)1 AbstractJUnitTest (org.jenkinsci.test.acceptance.junit.AbstractJUnitTest)1 DockerTest (org.jenkinsci.test.acceptance.junit.DockerTest)1 WithCredentials (org.jenkinsci.test.acceptance.junit.WithCredentials)1 WithDocker (org.jenkinsci.test.acceptance.junit.WithDocker)1 WithPlugins (org.jenkinsci.test.acceptance.junit.WithPlugins)1 SshSlaveLauncher (org.jenkinsci.test.acceptance.plugins.ssh_slaves.SshSlaveLauncher)1 DumbSlave (org.jenkinsci.test.acceptance.po.DumbSlave)1 WorkflowJob (org.jenkinsci.test.acceptance.po.WorkflowJob)1 CommandBuilder (org.jenkinsci.utils.process.CommandBuilder)1 Category (org.junit.experimental.categories.Category)1 Issue (org.jvnet.hudson.test.Issue)1