Search in sources :

Example 1 with BuildAgent

use of jetbrains.buildServer.agent.BuildAgent in project teamcity-git by JetBrains.

the class AgentStartupGitDetectorTest method should_set_path_to_detected_git_if_not_set_by_user.

private void should_set_path_to_detected_git_if_not_set_by_user() {
    final BuildAgent agent = myContext.mock(BuildAgent.class);
    myContext.checking(new Expectations() {

        {
            BuildAgentConfiguration config = myContext.mock(BuildAgentConfiguration.class);
            BuildParametersMap paramsMap = myContext.mock(BuildParametersMap.class);
            Map<String, String> params = new HashMap<String, String>();
            atLeast(1).of(agent).getConfiguration();
            will(returnValue(config));
            atLeast(1).of(config).getBuildParameters();
            will(returnValue(paramsMap));
            atLeast(1).of(paramsMap).getEnvironmentVariables();
            will(returnValue(params));
            atLeast(1).of(config).addEnvironmentVariable(with(Constants.TEAMCITY_AGENT_GIT_PATH), with(any(String.class)));
        }
    });
    myDetector.afterAgentConfigurationLoaded(agent);
    myContext.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) BuildParametersMap(jetbrains.buildServer.agent.BuildParametersMap) BuildAgent(jetbrains.buildServer.agent.BuildAgent) BuildAgentConfiguration(jetbrains.buildServer.agent.BuildAgentConfiguration) HashMap(java.util.HashMap) Map(java.util.Map) BuildParametersMap(jetbrains.buildServer.agent.BuildParametersMap)

Example 2 with BuildAgent

use of jetbrains.buildServer.agent.BuildAgent in project teamcity-git by JetBrains.

the class SSHAgentServiceTest method check_classpath_is_correct.

public void check_classpath_is_correct() throws IOException {
    File tempDir = createTempDir();
    Mockery m = new Mockery();
    BuildAgent agent = m.mock(BuildAgent.class);
    BuildAgentConfiguration agentConf = m.mock(BuildAgentConfiguration.class);
    CurrentBuildTracker buildTracker = m.mock(CurrentBuildTracker.class);
    m.checking(new Expectations() {

        {
            allowing(agentConf).getConfigurationParameters();
            will(returnValue(Collections.emptyMap()));
            allowing(agentConf).getTempDirectory();
            will(returnValue(tempDir));
            allowing(buildTracker).getCurrentBuild();
            will(throwException(new NoRunningBuildException()));
        }
    });
    GitAgentSSHService agentSSHService = new GitAgentSSHService(agent, agentConf, new MockGitPluginDescriptor(), new MockVcsRootSshKeyManagerProvider(), buildTracker);
    String scriptPath = agentSSHService.getScriptPath();
    GeneralCommandLine commandLine = new GeneralCommandLine();
    commandLine.setExePath(scriptPath);
    commandLine.addParameter("localhost");
    Map<String, String> env = new HashMap<>();
    env.put(GitSSHHandler.TEAMCITY_DEBUG_SSH, "true");
    commandLine.setEnvParams(env);
    ExecResult res = SimpleCommandLineProcessRunner.runCommand(commandLine, new byte[0]);
    then(res.getStderr()).doesNotContain("NoClassDefFoundError").doesNotContain("ClassNotFoundError");
}
Also used : Expectations(org.jmock.Expectations) GitAgentSSHService(jetbrains.buildServer.buildTriggers.vcs.git.agent.GitAgentSSHService) HashMap(java.util.HashMap) BuildAgent(jetbrains.buildServer.agent.BuildAgent) Mockery(org.jmock.Mockery) NoRunningBuildException(jetbrains.buildServer.agent.NoRunningBuildException) MockVcsRootSshKeyManagerProvider(jetbrains.buildServer.buildTriggers.vcs.git.tests.MockVcsRootSshKeyManagerProvider) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) CurrentBuildTracker(jetbrains.buildServer.agent.CurrentBuildTracker) File(java.io.File) BuildAgentConfiguration(jetbrains.buildServer.agent.BuildAgentConfiguration) MockGitPluginDescriptor(jetbrains.buildServer.buildTriggers.vcs.git.tests.MockGitPluginDescriptor) ExecResult(jetbrains.buildServer.ExecResult)

Example 3 with BuildAgent

use of jetbrains.buildServer.agent.BuildAgent in project teamcity-git by JetBrains.

the class AgentStartupGitDetectorTest method should_do_nothing_if_path_to_git_set_by_user.

public void should_do_nothing_if_path_to_git_set_by_user() {
    final BuildAgent agent = myContext.mock(BuildAgent.class);
    myContext.checking(new Expectations() {

        {
            BuildAgentConfiguration config = myContext.mock(BuildAgentConfiguration.class);
            BuildParametersMap paramsMap = myContext.mock(BuildParametersMap.class);
            Map<String, String> params = new HashMap<String, String>() {

                {
                    put(Constants.TEAMCITY_AGENT_GIT_PATH, "/some/path/to/git");
                }
            };
            atLeast(1).of(agent).getConfiguration();
            will(returnValue(config));
            atLeast(1).of(config).getBuildParameters();
            will(returnValue(paramsMap));
            atLeast(1).of(paramsMap).getEnvironmentVariables();
            will(returnValue(params));
        }
    });
    myDetector.afterAgentConfigurationLoaded(agent);
    myContext.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) BuildParametersMap(jetbrains.buildServer.agent.BuildParametersMap) BuildAgent(jetbrains.buildServer.agent.BuildAgent) BuildAgentConfiguration(jetbrains.buildServer.agent.BuildAgentConfiguration) HashMap(java.util.HashMap) Map(java.util.Map) BuildParametersMap(jetbrains.buildServer.agent.BuildParametersMap)

Aggregations

HashMap (java.util.HashMap)3 BuildAgent (jetbrains.buildServer.agent.BuildAgent)3 BuildAgentConfiguration (jetbrains.buildServer.agent.BuildAgentConfiguration)3 Expectations (org.jmock.Expectations)3 Map (java.util.Map)2 BuildParametersMap (jetbrains.buildServer.agent.BuildParametersMap)2 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)1 File (java.io.File)1 ExecResult (jetbrains.buildServer.ExecResult)1 CurrentBuildTracker (jetbrains.buildServer.agent.CurrentBuildTracker)1 NoRunningBuildException (jetbrains.buildServer.agent.NoRunningBuildException)1 GitAgentSSHService (jetbrains.buildServer.buildTriggers.vcs.git.agent.GitAgentSSHService)1 MockGitPluginDescriptor (jetbrains.buildServer.buildTriggers.vcs.git.tests.MockGitPluginDescriptor)1 MockVcsRootSshKeyManagerProvider (jetbrains.buildServer.buildTriggers.vcs.git.tests.MockVcsRootSshKeyManagerProvider)1 Mockery (org.jmock.Mockery)1