Skip to content
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

empty properties treated as null #201

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/main/java/com/hazelcast/kubernetes/KubernetesConfig.java
Expand Up @@ -219,22 +219,22 @@ private String getProperty(String prefix, PropertyDefinition property) {
}

private void validateConfig() {
if (serviceDns != null && (serviceName != null || serviceLabelName != null || podLabelName != null)) {
if (!StringUtil.isNullOrEmptyAfterTrim(serviceDns) && (!StringUtil.isNullOrEmptyAfterTrim(serviceName) || !StringUtil.isNullOrEmptyAfterTrim(serviceLabelName) || !StringUtil.isNullOrEmptyAfterTrim(podLabelName ))) {
throw new InvalidConfigurationException(
String.format("Properties '%s' and ('%s' or '%s' or %s) cannot be defined at the same time",
SERVICE_DNS.key(), SERVICE_NAME.key(), SERVICE_LABEL_NAME.key(), POD_LABEL_NAME.key()));
}
if (serviceName != null && serviceLabelName != null) {
if (!StringUtil.isNullOrEmptyAfterTrim(serviceName) && !StringUtil.isNullOrEmptyAfterTrim(serviceLabelName)) {
throw new InvalidConfigurationException(
String.format("Properties '%s' and '%s' cannot be defined at the same time",
SERVICE_NAME.key(), SERVICE_LABEL_NAME.key()));
}
if (serviceName != null && podLabelName != null) {
if (!StringUtil.isNullOrEmptyAfterTrim(serviceName) && !StringUtil.isNullOrEmptyAfterTrim(podLabelName)) {
throw new InvalidConfigurationException(
String.format("Properties '%s' and '%s' cannot be defined at the same time",
SERVICE_NAME.key(), POD_LABEL_NAME.key()));
}
if (serviceLabelName != null && podLabelName != null) {
if (!StringUtil.isNullOrEmptyAfterTrim(serviceLabelName) && !StringUtil.isNullOrEmptyAfterTrim(podLabelName)) {
throw new InvalidConfigurationException(
String.format("Properties '%s' and '%s' cannot be defined at the same time",
SERVICE_LABEL_NAME.key(), POD_LABEL_NAME.key()));
Expand Down
Expand Up @@ -275,4 +275,13 @@ private static String createTestFile(String expectedContents)
}
return temp.getAbsolutePath();
}

@Test
public void propertyIsEmpty() {
// given
Map<String, Comparable> properties = createProperties();
properties.put(SERVICE_NAME.key(), " ");
properties.put(SERVICE_DNS.key(), "service-dns");
new KubernetesConfig(properties);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// given
Map<String, Comparable> properties = createProperties();
properties.put(SERVICE_NAME.key(), " ");
properties.put(SERVICE_DNS.key(), "service-dns");
new KubernetesConfig(properties);
// given
Map<String, Comparable> properties = createProperties();
properties.put(SERVICE_NAME.key(), " ");
properties.put(SERVICE_DNS.key(), "service-dns");
// when
KubernetesConfig config = new KubernetesConfig(properties);
// then
assertEquals("service-dns", config.getServiceDns());

Could you change this test to this format? And could you also change the other tests the same way?

}
}