Search in sources :

Example 6 with FakeBuildRepositoryRemote

use of com.thoughtworks.go.agent.testhelpers.FakeBuildRepositoryRemote in project gocd by gocd.

the class BuildWorkEnvironmentVariablesTest method shouldSetUpP4ClientEnvironmentVariableEnvironmentContextCorrectly.

@Test
public void shouldSetUpP4ClientEnvironmentVariableEnvironmentContextCorrectly() {
    new SystemEnvironment().setProperty("serviceUrl", "some_random_place");
    BuildWork work = getBuildWorkWithP4MaterialRevision(p4Material);
    EnvironmentVariableContext environmentVariableContext = new EnvironmentVariableContext();
    AgentIdentifier agentIdentifier = new AgentIdentifier("somename", "127.0.0.1", AGENT_UUID);
    work.doWork(environmentVariableContext, new AgentWorkContext(agentIdentifier, new FakeBuildRepositoryRemote(), new GoArtifactsManipulatorStub(), new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false), packageRepositoryExtension, scmExtension, taskExtension, null, null));
    assertThat(environmentVariableContext.getProperty("GO_REVISION"), is("10"));
    assertThat(environmentVariableContext.getProperty("GO_SERVER_URL"), is("some_random_place"));
    assertThat(environmentVariableContext.getProperty("GO_TRIGGER_USER"), is(TRIGGERED_BY_USER));
    assertThat(environmentVariableContext.getProperty("GO_P4_CLIENT"), is(p4Material.clientName(dir)));
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) FakeBuildRepositoryRemote(com.thoughtworks.go.agent.testhelpers.FakeBuildRepositoryRemote) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) Test(org.junit.Test)

Example 7 with FakeBuildRepositoryRemote

use of com.thoughtworks.go.agent.testhelpers.FakeBuildRepositoryRemote in project gocd by gocd.

the class BuildWorkArtifactUploadingTest method shouldNotUploadFileContainingFolderAgain.

@Test
public void shouldNotUploadFileContainingFolderAgain() throws Exception {
    List<ArtifactPlan> artifactPlans = new ArrayList<>();
    artifactPlans.add(new ArtifactPlan(ArtifactPlanType.file, "logs/pic/*.png", "mypic"));
    BuildAssignment buildAssigment = createAssignment(artifactPlans, new String[] { "logs/pic/fail.png", "logs/pic/pass.png", "README" });
    BuildWork work = new BuildWork(buildAssigment, StandardCharsets.UTF_8.name());
    GoArtifactsManipulatorStub manipulator = new GoArtifactsManipulatorStub();
    AgentIdentifier agentIdentifier = new AgentIdentifier("somename", "127.0.0.1", AGENT_UUID);
    work.doWork(environmentVariableContext, new AgentWorkContext(agentIdentifier, new FakeBuildRepositoryRemote(), manipulator, new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie"), packageRepositoryExtension, scmExtension, taskExtension, null, pluginRequestProcessorRegistry));
    List<UploadEntry> entries = manipulator.uploadEntries();
    assertThat(entries, uploadFileToDestination(new File(buildWorkingDirectory.getPath() + "/logs/pic/pass.png"), "mypic"));
    assertThat(entries, uploadFileToDestination(new File(buildWorkingDirectory.getPath() + "/logs/pic/fail.png"), "mypic"));
    assertThat(entries, not(uploadFileToDestination(new File(buildWorkingDirectory.getPath() + "/logs/pic"), "mypic")));
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) UploadEntry(com.thoughtworks.go.matchers.UploadEntry) ArrayList(java.util.ArrayList) FakeBuildRepositoryRemote(com.thoughtworks.go.agent.testhelpers.FakeBuildRepositoryRemote) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 8 with FakeBuildRepositoryRemote

use of com.thoughtworks.go.agent.testhelpers.FakeBuildRepositoryRemote in project gocd by gocd.

the class BuildWorkArtifactUploadingTest method shouldUploadFolderWhenMatchedWithWildCards.

@Test
public void shouldUploadFolderWhenMatchedWithWildCards() throws Exception {
    List<ArtifactPlan> artifactPlans = new ArrayList<>();
    artifactPlans.add(new ArtifactPlan(ArtifactPlanType.file, "logs/pic-*", "mypic"));
    BuildAssignment buildAssigment = createAssignment(artifactPlans, new String[] { "logs/pic-1/fail.png", "logs/pic-1/pass.png", "logs/pic-2/cancel.png", "logs/pic-2/complete.png", "README" });
    BuildWork work = new BuildWork(buildAssigment, StandardCharsets.UTF_8.name());
    GoArtifactsManipulatorStub manipulator = new GoArtifactsManipulatorStub();
    AgentIdentifier agentIdentifier = new AgentIdentifier("somename", "127.0.0.1", AGENT_UUID);
    work.doWork(environmentVariableContext, new AgentWorkContext(agentIdentifier, new FakeBuildRepositoryRemote(), manipulator, new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie"), packageRepositoryExtension, scmExtension, taskExtension, null, pluginRequestProcessorRegistry));
    List<UploadEntry> entries = manipulator.uploadEntries();
    assertThat(entries, not(uploadFileToDestination(new File(buildWorkingDirectory.getPath() + "/logs/pic-1/pass.png"), "mypic")));
    assertThat(entries, not(uploadFileToDestination(new File(buildWorkingDirectory.getPath() + "/logs/pic-1/fail.png"), "mypic")));
    assertThat(entries, not(uploadFileToDestination(new File(buildWorkingDirectory.getPath() + "/logs/pic-2/cancel.png"), "mypic")));
    assertThat(entries, not(uploadFileToDestination(new File(buildWorkingDirectory.getPath() + "/logs/pic-2/complete.png"), "mypic")));
    assertThat(entries, uploadFileToDestination(new File(buildWorkingDirectory.getPath() + "/logs/pic-1"), "mypic"));
    assertThat(entries, uploadFileToDestination(new File(buildWorkingDirectory.getPath() + "/logs/pic-2"), "mypic"));
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) UploadEntry(com.thoughtworks.go.matchers.UploadEntry) ArrayList(java.util.ArrayList) FakeBuildRepositoryRemote(com.thoughtworks.go.agent.testhelpers.FakeBuildRepositoryRemote) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 9 with FakeBuildRepositoryRemote

use of com.thoughtworks.go.agent.testhelpers.FakeBuildRepositoryRemote in project gocd by gocd.

the class BuildWorkArtifactUploadingTest method shouldReportUploadFailuresWhenTheyHappen.

@Test
public void shouldReportUploadFailuresWhenTheyHappen() throws Exception {
    List<ArtifactPlan> artifactPlans = new ArrayList<>();
    artifactPlans.add(new ArtifactPlan(ArtifactPlanType.file, "**/*.png", "mypic"));
    BuildAssignment buildAssigment = createAssignment(artifactPlans, new String[] { "logs/pic/pass.png", "logs/pic-1/pass.png" });
    BuildWork work = new BuildWork(buildAssigment, StandardCharsets.UTF_8.name());
    GoArtifactsManipulatorStub manipulator = new GoArtifactsManipulatorStub(new ArrayList<>(), new HttpServiceStub(), new URLService(), new ZipUtilThatRunsOutOfMemory());
    AgentIdentifier agentIdentifier = new AgentIdentifier("somename", "127.0.0.1", AGENT_UUID);
    work.doWork(environmentVariableContext, new AgentWorkContext(agentIdentifier, new FakeBuildRepositoryRemote(), manipulator, new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie"), packageRepositoryExtension, scmExtension, taskExtension, null, pluginRequestProcessorRegistry));
    List<UploadEntry> entries = manipulator.uploadEntries();
    assertThat(entries.isEmpty(), is(true));
    assertThat(manipulator.consoleOut(), containsString("Failed to upload [**/*.png]"));
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) UploadEntry(com.thoughtworks.go.matchers.UploadEntry) URLService(com.thoughtworks.go.util.URLService) ArrayList(java.util.ArrayList) FakeBuildRepositoryRemote(com.thoughtworks.go.agent.testhelpers.FakeBuildRepositoryRemote) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) Test(org.junit.jupiter.api.Test)

Example 10 with FakeBuildRepositoryRemote

use of com.thoughtworks.go.agent.testhelpers.FakeBuildRepositoryRemote in project gocd by gocd.

the class BuildWorkEnvironmentVariablesTest method shouldMergeEnvironmentVariablesFromInitialContext.

@Test
public void shouldMergeEnvironmentVariablesFromInitialContext() throws IOException {
    pipelineConfig.setMaterialConfigs(new MaterialConfigs());
    BuildAssignment buildAssignment = createAssignment(new EnvironmentVariableContext("foo", "bar"));
    BuildWork work = new BuildWork(buildAssignment, StandardCharsets.UTF_8.name());
    EnvironmentVariableContext environmentContext = new EnvironmentVariableContext();
    AgentIdentifier agentIdentifier = new AgentIdentifier("somename", "127.0.0.1", AGENT_UUID);
    work.doWork(environmentContext, new AgentWorkContext(agentIdentifier, new FakeBuildRepositoryRemote(), new GoArtifactsManipulatorStub(), new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie"), packageRepositoryExtension, scmExtension, taskExtension, null, null));
    assertEnvironmentContext(environmentContext, "foo", is("bar"));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) FakeBuildRepositoryRemote(com.thoughtworks.go.agent.testhelpers.FakeBuildRepositoryRemote) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) Test(org.junit.jupiter.api.Test)

Aggregations

FakeBuildRepositoryRemote (com.thoughtworks.go.agent.testhelpers.FakeBuildRepositoryRemote)12 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)12 AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)12 Test (org.junit.jupiter.api.Test)10 UploadEntry (com.thoughtworks.go.matchers.UploadEntry)7 ArrayList (java.util.ArrayList)7 File (java.io.File)6 EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)4 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)3 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)2 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 URLService (com.thoughtworks.go.util.URLService)1 Test (org.junit.Test)1