Search in sources :

Example 26 with GoConfigRevision

use of com.thoughtworks.go.domain.GoConfigRevision in project gocd by gocd.

the class GoConfigMigrationIntegrationTest method shouldVersionControlAnUpgradedConfigIfItIsValid.

@Test
public void shouldVersionControlAnUpgradedConfigIfItIsValid() throws Exception {
    GoConfigMigration upgrader = new GoConfigMigration(new GoConfigMigration.UpgradeFailedHandler() {

        public void handle(Exception e) {
            throw new AssertionError("upgrade failed!!!!!");
        }
    }, configRepository, new TimeProvider(), configCache, ConfigElementImplementationRegistryMother.withNoPlugins());
    FileUtils.writeStringToFile(configFile, ConfigFileFixture.DEFAULT_XML_WITH_2_AGENTS);
    configRepository.checkin(new GoConfigRevision("dummy-content", "some-md5", "loser", "100.3.1", new TimeProvider()));
    upgrader.upgradeIfNecessary(configFile, currentGoServerVersion);
    GoConfigRevision latest = configRepository.getRevision(ConfigRepository.CURRENT);
    assertThat(latest.getUsername(), is("Upgrade"));
    String contents = FileUtils.readFileToString(configFile);
    assertThat(latest.getContent(), is(contents));
    assertThat(latest.getMd5(), is(DigestUtils.md5Hex(contents)));
}
Also used : GoConfigRevision(com.thoughtworks.go.domain.GoConfigRevision) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) Test(org.junit.Test)

Example 27 with GoConfigRevision

use of com.thoughtworks.go.domain.GoConfigRevision in project gocd by gocd.

the class GoConfigMigrationIntegrationTest method shouldTryToRevertConfigToTheLatestValidConfigVersionOnlyOnce.

@Test
public void shouldTryToRevertConfigToTheLatestValidConfigVersionOnlyOnce() throws IOException {
    try {
        configRepository.checkin(new GoConfigRevision("<cruise></cruise>", "md5", "ps", "123", new TimeProvider()));
        loadConfigFileWithContent("<cruise></cruise>");
        ServerHealthStates states = serverHealthService.getAllLogs();
        assertThat(states.size(), is(1));
        assertThat(states.get(0).getDescription(), containsString("Go encountered an invalid configuration file while starting up. The invalid configuration file has been renamed to &lsquo;"));
        assertThat(states.get(0).getDescription(), containsString("&rsquo; and a new configuration file has been automatically created using the last good configuration."));
        assertThat(states.get(0).getMessage(), containsString("Invalid Configuration"));
        assertThat(states.get(0).getType(), is(HealthStateType.general(HealthStateScope.forInvalidConfig())));
        assertThat(states.get(0).getLogLevel(), is(HealthStateLevel.WARNING));
    } catch (Exception e) {
        assertThat(e.getMessage(), containsString("Cruise config file with version 0 is invalid. Unable to upgrade."));
    }
}
Also used : GoConfigRevision(com.thoughtworks.go.domain.GoConfigRevision) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) Test(org.junit.Test)

Example 28 with GoConfigRevision

use of com.thoughtworks.go.domain.GoConfigRevision in project gocd by gocd.

the class UpdateAgentStatusTest method shouldUpdateAgentIPAddressWhenItChanges_asAgent.

@Test
public void shouldUpdateAgentIPAddressWhenItChanges_asAgent() throws Exception {
    CruiseConfig oldConfig = goConfigDao.load();
    String oldIp = oldConfig.agents().getAgentByUuid("uuid").getIpAddress();
    assertThat(oldIp, is("10.81.2.1"));
    AgentIdentifier agentIdentifier1 = new AgentIdentifier("localhost", "10.18.3.95", "uuid");
    AgentRuntimeInfo agentRuntimeInfo1 = new AgentRuntimeInfo(agentIdentifier1, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false);
    agentRuntimeInfo1.busy(new AgentBuildingInfo("building", "buildLocator"));
    agentService.updateRuntimeInfo(agentRuntimeInfo1);
    CruiseConfig newConfig = goConfigDao.load();
    String newIp = newConfig.agents().getAgentByUuid("uuid").getIpAddress();
    assertThat(newIp, is("10.18.3.95"));
    GoConfigRevision rev = configRepo.getRevision(newConfig.getMd5());
    assertThat(rev.getUsername(), is("agent_uuid_10.18.3.95_CCEDev01"));
}
Also used : AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) StringContains.containsString(org.hamcrest.core.StringContains.containsString) GoConfigRevision(com.thoughtworks.go.domain.GoConfigRevision) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) Test(org.junit.Test)

Aggregations

GoConfigRevision (com.thoughtworks.go.domain.GoConfigRevision)28 Test (org.junit.Test)22 TimeProvider (com.thoughtworks.go.util.TimeProvider)13 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)7 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 StringContains.containsString (org.hamcrest.core.StringContains.containsString)3 GoConfigRevisions (com.thoughtworks.go.GoConfigRevisions)2 File (java.io.File)2 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Date (java.util.Date)2 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)1 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)1 FileOutputStream (java.io.FileOutputStream)1 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1 DateTime (org.joda.time.DateTime)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1 SecurityContext (org.springframework.security.context.SecurityContext)1