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)));
}
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 ‘"));
assertThat(states.get(0).getDescription(), containsString("’ 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."));
}
}
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"));
}
Aggregations