-
Notifications
You must be signed in to change notification settings - Fork 1k
move fabric8-config to junit-5 #798
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
move fabric8-config to junit-5 #798
Conversation
import io.fabric8.kubernetes.api.model.DoneableConfigMap; | ||
import io.fabric8.kubernetes.client.KubernetesClient; | ||
import io.fabric8.kubernetes.client.dsl.MixedOperation; | ||
import io.fabric8.kubernetes.client.dsl.Resource; |
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.
the changes here are obvious: move to junit-5 + minor nitpick on a raw type.
import java.util.Map; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; |
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.
trivial changes also : junit-5 + assertJ to be consistent
|
||
@BeforeClass | ||
public static void setUpBeforeClass() { | ||
// injected because of @EnableKubernetesMockClient. Because of the way |
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.
I hope this comment makes sense of why the configuration has moved in here from the common class. It is just the way @EnableKubernetesMockClient
"injects" fields.
|
||
HashMap<String, String> data = new HashMap<>(); | ||
data.put("bean.greeting", "Hello ConfigMap, %s!"); | ||
server.expect().withPath("/api/v1/namespaces/test/configmaps/" + APPLICATION_NAME) |
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.
mock client works slightly differently now and there is no need to mock paths, instead everything happens on the client itself. It is the same exact thing, logically.
|
||
mockClient.secrets().inNamespace(DEFAULT_NAMESPACE).create(secret1); | ||
|
||
Map<String, String> metadata2 = new HashMap() { |
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.
refactor the anti-pattern away
setup("spring.cloud.kubernetes.enabled=true", "spring.cloud.kubernetes.config.enabled=false", | ||
"spring.cloud.kubernetes.secrets.enabled=false", "spring.cloud.kubernetes.reload.enabled=true"); | ||
public void kubernetesReloadEnabledButSecretAndConfigDisabled() { | ||
setup(KubernetesClientTestConfiguration.class, "spring.cloud.kubernetes.enabled=true", |
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.
setup
method was slightly changed to get Class<?>
as input, and I pass the KubernetesClientTestConfiguration.class
configuration in there. everything else stays the same
private static void createConfigmap(KubernetesClient client, String configMapName, String namespace, | ||
Map<String, String> data) { | ||
|
||
server.expect().withPath(String.format("/api/v1/namespaces/%s/configmaps/%s", namespace, configMapName)) |
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.
no need to mock paths anymore
protected static final String FIRST_FILE_NAME_DUPLICATED_FULL_PATH = FILES_ROOT_PATH + "/" + FILES_SUB_PATH + "/" | ||
+ FIRST_FILE_NAME; | ||
|
||
@ClassRule |
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.
this is now injected by @EnableKubernetesMockClient(crud = true, https = false)
so no need for the server. the rest of the changes are trivial, imho, here.
|
||
protected static final String APPLICATION_NAME = "configmap-mixed-example"; | ||
|
||
@ClassRule |
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.
this is now injected by @EnableKubernetesMockClient(crud = true, https = false)
so no need for the server. the rest of the changes are trivial, imho, here.
|
||
HashMap<String, String> data = new HashMap<>(); | ||
data.put("bean.morning", "Buenos Dias ConfigMap, %s"); | ||
server.expect().withPath("/api/v1/namespaces/test/configmaps/" + APPLICATION_NAME) |
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.
no need to mock paths anymore
@SuppressWarnings("unchecked") | ||
Map<String, String> data = (Map<String, String>) configMapList.getAdditionalProperties().get("data"); | ||
assertThat(data.get("KEY")).isEqualTo("123"); | ||
assertThat(configMapList.getItems().size()).isEqualTo(1); |
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.
it tests the same thing, but where to find the "thing" to assert against is in a different place
@Test | ||
public void testConfigMapFromSingleApplicationProperties() { | ||
String configMapName = "app-properties-test"; | ||
String namespace = "app-props"; |
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.
another interesting change is that KubernetesServer
used to return a NamespacedKubernetesClient
, so you could do : this.server.getClient().inNamespace(namespace)
, specifically call inNamespace
with a certain namespace
. KubernetesClient
that is injected can't do that so I used it's default namespace test
.
As such, I deleted String namespace = "app-props";
. Fundamentally, the test does the same assertions.
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.
the same change is across all tests in this class
|
||
@Autowired(required = false) | ||
private KubernetesClient client; | ||
// not a fan of changing the type from KubernetesClient, but because of: |
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.
this was already fixed by me, waiting for a review. I've also asked if this will be back-ported. If it is (and you are OK with that, of course), I will upgrade the fabric8 libraries and revert this back.
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.
What version of fabric8 was it changed in? Maybe we should make that change first, before making these?
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.
this is still pending review from my PR here. The good news is that it is targeted in 4.13.4
and not 5.x.x
. I am more than OK to wait for 4.13.4
release and only then merge this one.
That being said - I do have a minor question here. Why isn't this project moving towards fabric8 - 5.x.x
? thank you
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.
OK cool, its up to you. If you don't mind going back and making that change I am happy to merge this now.
We will move to 5.x.x in our next release train. We just don't want to make a major change like that and cause it to break people in a service release.
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.
I will make the change in a separate PR, as soon as 4.13.4
is released. pinky-promise!
your explanation makes perfect sense, btw. thx
@EnableKubernetesMockClient(crud = true, https = false) | ||
public class KubernetesConfigConfigurationTest extends KubernetesConfigTestBase { | ||
|
||
// injected because of @EnableKubernetesMockClient. Because of the way |
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.
why this is needed in this manner is explained in a similar class, I hope it makes sense.
context = new SpringApplicationBuilder(PropertyPlaceholderAutoConfiguration.class, | ||
KubernetesClientTestConfiguration.class, BootstrapConfiguration.class, | ||
ConfigReloadAutoConfiguration.class, RefreshAutoConfiguration.class) | ||
protected void setup(Class<?> mockClientConfiguration, String... env) { |
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.
this method take one more argument now
@ryanjbaxter ready to review. The changes are not that big (but I am biased since I stayed quite a while in this code). The one change that I wish I could perform and really can't is to drop all |
Can you mark it ready to review? |
done |
|
||
@Autowired(required = false) | ||
private KubernetesClient client; | ||
// not a fan of changing the type from KubernetesClient, but because of: |
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.
What version of fabric8 was it changed in? Maybe we should make that change first, before making these?
Thanks for this, just one minor question! |
No description provided.