Search in sources :

Example 1 with ArtifactDirectoryChooser

use of com.thoughtworks.go.server.view.artifacts.ArtifactDirectoryChooser in project gocd by gocd.

the class ArtifactsServiceTest method shouldLogAndIgnoreExceptionsWhenDeletingStageArtifacts.

@Test
void shouldLogAndIgnoreExceptionsWhenDeletingStageArtifacts() throws IllegalArtifactLocationException {
    ArtifactsService artifactsService = new ArtifactsService(resolverService, stageService, artifactsDirHolder, zipUtil);
    Stage stage = StageMother.createPassedStage("pipeline", 10, "stage", 20, "job", new Date());
    ArtifactDirectoryChooser chooser = mock(ArtifactDirectoryChooser.class);
    ReflectionUtil.setField(artifactsService, "chooser", chooser);
    when(chooser.findArtifact(any(LocatableEntity.class), eq(""))).thenThrow(new IllegalArtifactLocationException("holy cow!"));
    try (LogFixture logFixture = logFixtureFor(ArtifactsService.class, Level.DEBUG)) {
        artifactsService.purgeArtifactsForStage(stage);
        assertThat(logFixture.contains(Level.ERROR, "Error occurred while clearing artifacts for 'pipeline/10/stage/20'. Error: 'holy cow!'")).isTrue();
    }
    verify(stageService).markArtifactsDeletedFor(stage);
}
Also used : LogFixture(com.thoughtworks.go.util.LogFixture) LocatableEntity(com.thoughtworks.go.domain.LocatableEntity) IllegalArtifactLocationException(com.thoughtworks.go.domain.exception.IllegalArtifactLocationException) Stage(com.thoughtworks.go.domain.Stage) Date(java.util.Date) ArtifactDirectoryChooser(com.thoughtworks.go.server.view.artifacts.ArtifactDirectoryChooser) Test(org.junit.jupiter.api.Test)

Aggregations

LocatableEntity (com.thoughtworks.go.domain.LocatableEntity)1 Stage (com.thoughtworks.go.domain.Stage)1 IllegalArtifactLocationException (com.thoughtworks.go.domain.exception.IllegalArtifactLocationException)1 ArtifactDirectoryChooser (com.thoughtworks.go.server.view.artifacts.ArtifactDirectoryChooser)1 LogFixture (com.thoughtworks.go.util.LogFixture)1 Date (java.util.Date)1 Test (org.junit.jupiter.api.Test)1