@Test public void shouldAllowResourcesOnNonElasticAgents() throws Exception { BasicCruiseConfig cruiseConfig = GoConfigMother.configWithPipelines("dev", "qa"); AgentConfig agentConfig = new AgentConfig("uuid", "hostname", "10.10.10.10"); cruiseConfig.agents().add(agentConfig); agentConfig.addResourceConfig(new ResourceConfig("foo")); assertThat(cruiseConfig.validateAfterPreprocess().isEmpty(), is(true)); }
@Test public void shouldReturnValidationErrorMessages(){ BasicCruiseConfig cruiseConfig = new BasicCruiseConfig(); BasicEnvironmentConfig environmentConfig = new BasicEnvironmentConfig(new CaseInsensitiveString("env")); environmentConfig.addAgent("does_not_exist_1"); environmentConfig.addAgent("does_not_exist_2"); environmentConfig.addAgent("exists_3"); cruiseConfig.addEnvironment(environmentConfig); cruiseConfig.agents().add(new AgentConfig("exists_3")); List<ConfigErrors> errors = new EnvironmentAgentValidator().validateConfig(cruiseConfig); assertThat(errors.size(), is(2)); assertThat(errors.get(0).on(EnvironmentAgentConfig.UUID), is("Environment 'env' has an invalid agent uuid 'does_not_exist_1'")); assertThat(errors.get(1).on(EnvironmentAgentConfig.UUID), is("Environment 'env' has an invalid agent uuid 'does_not_exist_2'")); } }
@Test public void shouldNotAllowResourcesElasticAgents() throws Exception { BasicCruiseConfig cruiseConfig = GoConfigMother.configWithPipelines("dev", "qa"); AgentConfig agentConfig = new AgentConfig("uuid", "hostname", "10.10.10.10"); cruiseConfig.agents().add(agentConfig); agentConfig.setElasticPluginId("com.example.foo"); agentConfig.setElasticAgentId("foobar"); agentConfig.addResourceConfig(new ResourceConfig("foo")); assertThat(cruiseConfig.validateAfterPreprocess().isEmpty(), is(false)); assertEquals(1, agentConfig.errors().size()); assertThat(agentConfig.errors().on("elasticAgentId"), is("Elastic agents cannot have resources.")); }
@Test public void shouldNotThrowExceptionIfValidationPasses() throws Exception { BasicCruiseConfig cruiseConfig = new BasicCruiseConfig(); BasicEnvironmentConfig environmentConfig = new BasicEnvironmentConfig(new CaseInsensitiveString("env")); environmentConfig.addAgent("exists_1"); cruiseConfig.addEnvironment(environmentConfig); cruiseConfig.agents().add(new AgentConfig("exists_1")); new EnvironmentAgentValidator().validate(cruiseConfig); assertThat(environmentConfig.getAgents().first().errors().isEmpty(), is(true)); }