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

Add tests in KeyValueClientITest for getting nested keys #267

Merged
merged 1 commit into from
Aug 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion src/itest/java/org/kiwiproject/consul/KeyValueClientITest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.kiwiproject.consul;

import static java.util.stream.Collectors.toMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
import static org.kiwiproject.consul.TestUtils.randomUUIDString;

import org.apache.commons.codec.binary.Base64;
Expand Down Expand Up @@ -173,6 +175,48 @@ void shouldPutAndReceiveStringsWithAnotherCharset() {
assertThat(new HashSet<>(keyValueClient.getValuesAsString(key, TEST_CHARSET))).isEqualTo(Set.of(value, value2));
}

@Test
void shouldGetNestedValue() {
var topLevelKey = "folder-" + randomUUIDString();
var childKey = "child-" + randomUUIDString();
var key = topLevelKey + "/" + childKey;
var value = randomUUIDString();

assertThat(keyValueClient.putValue(key, value)).isTrue();
var receivedValue = keyValueClient.getValue(key).orElseThrow();
assertThat(receivedValue.getValueAsString()).contains(value);
}

@Test
void shouldGetNestedValues() {
var topLevelKey = "folder-" + randomUUIDString();

var childKey1 = "child-" + randomUUIDString();
var key1 = topLevelKey + "/" + childKey1;
var value1 = randomUUIDString();
assertThat(keyValueClient.putValue(key1, value1)).isTrue();

var childKey2 = "child-" + randomUUIDString();
var key2 = topLevelKey + "/" + childKey2;
var value2 = randomUUIDString();
assertThat(keyValueClient.putValue(key2, value2)).isTrue();

var childKey3 = "child-" + randomUUIDString();
var key3 = topLevelKey + "/" + childKey3;
var value3 = randomUUIDString();
assertThat(keyValueClient.putValue(key3, value3)).isTrue();

var valuesMap = keyValueClient.getValues(topLevelKey)
.stream()
.collect(toMap(Value::getKey, value -> value.getValueAsString().orElseThrow()));

assertThat(valuesMap).containsOnly(
entry(key1, value1),
entry(key2, value2),
entry(key3, value3)
);
}

@Test
void shouldDelete() {
var key = randomUUIDString();
Expand Down Expand Up @@ -401,7 +445,7 @@ void testGetConsulResponseWithValues() {

keyValueClient.deleteKey(key);

assertThat(!response.getResponse().isEmpty()).isTrue();
assertThat(response.getResponse()).isNotEmpty();
assertThat(response.getIndex()).isNotNull();
}

Expand Down