- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1k
Add the ability to disable leader info contributor #2086
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /* | ||
| * Copyright 2013-present the original author or authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|  | ||
| package org.springframework.cloud.kubernetes.fabric8.leader; | ||
|  | ||
| import org.junit.jupiter.api.Test; | ||
|  | ||
| import org.springframework.beans.factory.NoSuchBeanDefinitionException; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.SpringBootConfiguration; | ||
| import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.cloud.kubernetes.commons.leader.LeaderInfoContributor; | ||
| import org.springframework.context.ApplicationContext; | ||
|  | ||
| import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|  | ||
| /** | ||
| * Tests that verify LeaderInfoContributor can be disabled via configuration property. | ||
| */ | ||
| @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, | ||
| properties = { "spring.main.cloud-platform=KUBERNETES", "spring.cloud.kubernetes.leader.autoStartup=false", | ||
| "management.info.leader.enabled=false" }) | ||
| class Fabric8LeaderInfoContributorDisabledTests { | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to have a test, when  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure we need that. That is functionality from Boot which controls all InfoContributors. | ||
|  | ||
| @Autowired | ||
| private ApplicationContext context; | ||
|  | ||
| /** | ||
| * Test that the LeaderInfoContributor bean is NOT present when | ||
| * management.info.leader.enabled=false | ||
| */ | ||
| @Test | ||
| void leaderInfoContributorShouldNotBePresent() { | ||
| assertThatThrownBy(() -> context.getBean(LeaderInfoContributor.class)) | ||
| .isInstanceOf(NoSuchBeanDefinitionException.class); | ||
| } | ||
|  | ||
| @SpringBootConfiguration | ||
| @EnableAutoConfiguration | ||
| protected static class TestConfig { | ||
|  | ||
| } | ||
|  | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is an typo, correct? Should be
management.info.leader.enabledThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I fixed the typo!