Search in sources :

Example 26 with GitTestRepo

use of com.thoughtworks.go.domain.materials.git.GitTestRepo in project gocd by gocd.

the class GitMaterialTest method shouldDeleteAndRecheckoutDirectoryWhenUrlChanges.

@Test
public void shouldDeleteAndRecheckoutDirectoryWhenUrlChanges() throws Exception {
    git.latestModification(workingDir, new TestSubprocessExecutionContext());
    File shouldBeRemoved = new File(workingDir, "shouldBeRemoved");
    shouldBeRemoved.createNewFile();
    assertThat(shouldBeRemoved.exists(), is(true));
    git = new GitMaterial(new GitTestRepo(temporaryFolder).projectRepositoryUrl());
    git.latestModification(workingDir, new TestSubprocessExecutionContext());
    assertThat("Should have deleted whole folder", shouldBeRemoved.exists(), is(false));
}
Also used : GitTestRepo(com.thoughtworks.go.domain.materials.git.GitTestRepo) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.junit.Test)

Example 27 with GitTestRepo

use of com.thoughtworks.go.domain.materials.git.GitTestRepo in project gocd by gocd.

the class MaterialDatabaseUpdaterIntegrationTest method setUp.

@Before
public void setUp() throws Exception {
    dbHelper.onSetUp();
    testRepo = new GitTestRepo(temporaryFolder);
    MaterialService slowMaterialService = new MaterialServiceWhichSlowsDownFirstTimeModificationCheck(materialRepository, goConfigService, securityService, packageRepositoryExtension, scmExtension);
    LegacyMaterialChecker materialChecker = new LegacyMaterialChecker(slowMaterialService, subprocessExecutionContext);
    ScmMaterialUpdater scmMaterialUpdater = new ScmMaterialUpdater(materialRepository, materialChecker, subprocessExecutionContext, slowMaterialService);
    transactionTemplateWithInvocationCount = new TransactionTemplateWithInvocationCount(transactionTemplate);
    updater = new MaterialDatabaseUpdater(materialRepository, serverHealthService, transactionTemplateWithInvocationCount, dependencyMaterialUpdater, scmMaterialUpdater, packageMaterialUpdater, pluggableSCMMaterialUpdater, materialExpansionService);
}
Also used : MaterialService(com.thoughtworks.go.server.service.MaterialService) GitTestRepo(com.thoughtworks.go.domain.materials.git.GitTestRepo) Before(org.junit.Before)

Example 28 with GitTestRepo

use of com.thoughtworks.go.domain.materials.git.GitTestRepo in project gocd by gocd.

the class MaterialDatabaseUpdaterIntegrationTest method setUp.

@BeforeEach
public void setUp(@TempDir Path tempDir) throws Exception {
    dbHelper.onSetUp();
    testRepo = new GitTestRepo(tempDir);
    MaterialService slowMaterialService = new MaterialServiceWhichSlowsDownFirstTimeModificationCheck(materialRepository, goConfigService, securityService, packageRepositoryExtension, scmExtension);
    LegacyMaterialChecker materialChecker = new LegacyMaterialChecker(slowMaterialService, subprocessExecutionContext);
    ScmMaterialUpdater scmMaterialUpdater = new ScmMaterialUpdater(materialRepository, materialChecker, subprocessExecutionContext, slowMaterialService);
    transactionTemplateWithInvocationCount = new TransactionTemplateWithInvocationCount(transactionTemplate);
    updater = new MaterialDatabaseUpdater(materialRepository, serverHealthService, transactionTemplateWithInvocationCount, dependencyMaterialUpdater, scmMaterialUpdater, packageMaterialUpdater, pluggableSCMMaterialUpdater, materialExpansionService, goConfigService);
}
Also used : GitTestRepo(com.thoughtworks.go.domain.materials.git.GitTestRepo) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 29 with GitTestRepo

use of com.thoughtworks.go.domain.materials.git.GitTestRepo in project gocd by gocd.

the class BuildCauseProducerServiceDependencyIntegrationTest method setup.

@BeforeEach
public void setup(@TempDir Path tempDir) throws Exception {
    dbHelper.onSetUp();
    configHelper.usingCruiseConfigDao(goConfigDao);
    configHelper.onSetUp();
    dependencyMaterialUpdateNotifier.disableUpdates();
    minglePipeline = new MinglePipeline();
    goPipeline = new GoPipeline();
    svnRepository = new SvnTestRepo(tempDir);
    repository = new SvnCommand(null, svnRepository.projectRepositoryUrl());
    svnMaterialRevs = new MaterialRevisions();
    svnMaterial = new SvnMaterial(repository);
    svnMaterialRevs.addRevision(svnMaterial, svnMaterial.latestModification(null, new ServerSubprocessExecutionContext(goConfigService, new SystemEnvironment())));
    final MaterialRevisions materialRevisions = new MaterialRevisions();
    SvnMaterial anotherSvnMaterial = new SvnMaterial(repository);
    materialRevisions.addRevision(anotherSvnMaterial, anotherSvnMaterial.latestModification(null, subprocessExecutionContext));
    gitTestRepo = new GitTestRepo(tempDir);
    MaterialRevisions gitMaterialRevs = new MaterialRevisions();
    gitMaterial = gitTestRepo.createMaterial();
    gitMaterialRevs.addRevision(gitMaterial, gitTestRepo.latestModifications());
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            materialRepository.save(svnMaterialRevs);
            materialRepository.save(gitMaterialRevs);
        }
    });
    BuildCause buildCause = BuildCause.createWithModifications(svnMaterialRevs, "");
    minglePipeline.setup(buildCause);
    goPipeline.setup(buildCause);
    result = new HttpOperationResult();
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) SvnTestRepo(com.thoughtworks.go.helper.SvnTestRepo) TransactionStatus(org.springframework.transaction.TransactionStatus) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) GitTestRepo(com.thoughtworks.go.domain.materials.git.GitTestRepo) SvnCommand(com.thoughtworks.go.domain.materials.svn.SvnCommand) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 30 with GitTestRepo

use of com.thoughtworks.go.domain.materials.git.GitTestRepo in project gocd by gocd.

the class BuildCauseProducerServiceConfigRepoIntegrationTest method shouldReloadPipelineConfigurationAndUpdateNewMaterialWhenManuallyTriggered.

@Test
public void shouldReloadPipelineConfigurationAndUpdateNewMaterialWhenManuallyTriggered(@TempDir Path tempDir) throws Exception {
    GitTestRepo otherGitRepo = new GitTestRepo(tempDir);
    pipelineConfig = PipelineConfigMother.createPipelineConfigWithStages("pipe1", "build", "test");
    pipelineConfig.materialConfigs().clear();
    materialConfig = hgRepo.createMaterialConfig("dest1");
    materialConfig.setAutoUpdate(true);
    pipelineConfig.materialConfigs().add(materialConfig);
    // new material is added
    GitMaterial gitMaterial = otherGitRepo.createMaterial("dest2");
    gitMaterial.setAutoUpdate(true);
    MaterialConfig otherMaterialConfig = gitMaterial.config();
    otherMaterialConfig.setAutoUpdate(true);
    pipelineConfig.materialConfigs().add(otherMaterialConfig);
    List<Modification> mod = configTestRepo.addPipelineToRepositoryAndPush(fileName, pipelineConfig);
    final HashMap<String, String> revisions = new HashMap<>();
    final HashMap<String, String> environmentVariables = new HashMap<>();
    buildCauseProducer.manualProduceBuildCauseAndSave(PIPELINE_NAME, Username.ANONYMOUS, new ScheduleOptions(revisions, environmentVariables, new HashMap<>()), new ServerHealthStateOperationResult());
    cachedGoConfig.throwExceptionIfExists();
    Map<CaseInsensitiveString, BuildCause> afterLoad = scheduleHelper.waitForAnyScheduled(20);
    assertThat(afterLoad.keySet(), hasItem(new CaseInsensitiveString(PIPELINE_NAME)));
    BuildCause cause = afterLoad.get(new CaseInsensitiveString(PIPELINE_NAME));
    assertThat(cause.getBuildCauseMessage(), containsString("Forced by anonymous"));
    PipelineConfig pipelineConfigAfterSchedule = goConfigService.pipelineConfigNamed(pipelineConfig.name());
    RepoConfigOrigin configOriginAfterSchedule = (RepoConfigOrigin) pipelineConfigAfterSchedule.getOrigin();
    String lastPushedRevision = mod.get(0).getRevision();
    assertThat("revisionOfPipelineConfigOriginShouldMatchLastPushedCommit", configOriginAfterSchedule.getRevision(), is(lastPushedRevision));
    assertThat(pipelineConfig.materialConfigs(), hasItem(otherMaterialConfig));
    assertThat("buildCauseRevisionShouldMatchLastPushedCommit", cause.getMaterialRevisions().latestRevision(), is(lastPushedRevision));
    // update of commited material happened during manual trigger
    MaterialRevisions modificationsInDb = materialRepository.findLatestModification(gitMaterial);
    assertThat(modificationsInDb.latestRevision(), is(otherGitRepo.latestModification().get(0).getRevision()));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) HashMap(java.util.HashMap) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) ServerHealthStateOperationResult(com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) ScheduleOptions(com.thoughtworks.go.server.scheduling.ScheduleOptions) GitTestRepo(com.thoughtworks.go.domain.materials.git.GitTestRepo) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) HgMaterialConfig(com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) Test(org.junit.jupiter.api.Test)

Aggregations

GitTestRepo (com.thoughtworks.go.domain.materials.git.GitTestRepo)31 Test (org.junit.Test)20 RevisionContext (com.thoughtworks.go.domain.materials.RevisionContext)9 Modification (com.thoughtworks.go.domain.materials.Modification)8 StringRevision (com.thoughtworks.go.domain.materials.mercurial.StringRevision)7 File (java.io.File)7 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 Before (org.junit.Before)5 BeforeEach (org.junit.jupiter.api.BeforeEach)4 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)3 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)3 SvnTestRepo (com.thoughtworks.go.helper.SvnTestRepo)3 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)2 HgMaterialConfig (com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig)2 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)2 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)2 HgTestRepo (com.thoughtworks.go.helper.HgTestRepo)2 ScheduleOptions (com.thoughtworks.go.server.scheduling.ScheduleOptions)2 ServerHealthStateOperationResult (com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult)2 InMemoryStreamConsumer (com.thoughtworks.go.util.command.InMemoryStreamConsumer)2