Skip to content

Commit

Permalink
Add more tests of KVClient#getKeys (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
sleberknight authored Aug 18, 2023
1 parent 41dd1dc commit 25756a8
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/itest/java/org/kiwiproject/consul/KeyValueClientITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.kiwiproject.consul.async.ConsulResponseCallback;
import org.kiwiproject.consul.model.ConsulResponse;
import org.kiwiproject.consul.model.kv.ImmutableOperation;
Expand Down Expand Up @@ -479,13 +481,31 @@ void testBasicTxn() {
}

@Test
void testGetKeysWithSeparator() {
void shouldGetKeysWithSeparator_LimitingToPrefix() {
keyValueClient.putValue("nested/first", "first");
keyValueClient.putValue("nested/second", "second");

List<String> keys = keyValueClient.getKeys("nested", "/");
assertThat(keys).hasSize(1);
assertThat(keys.get(0)).isEqualTo("nested/");
assertThat(keys).containsExactly("nested/");
}

@ParameterizedTest
@ValueSource(strings = { "nested/", "/nested/" })
void shouldGetKeysWithSeparator_LimitingToNestedKeys(String key) {
keyValueClient.putValue("nested/first", "first");
keyValueClient.putValue("nested/second", "second");

List<String> keys = keyValueClient.getKeys(key, "/");
assertThat(keys).containsExactly("nested/first", "nested/second");
}

@Test
void shouldGetKeysWithSeparator_LimitingToPrefix_WithSeparatorOtherThanSlash() {
keyValueClient.putValue("children-first", "first");
keyValueClient.putValue("children-second", "second");

List<String> keys = keyValueClient.getKeys("children-", "-");
assertThat(keys).containsExactly("children-first", "children-second");
}

@Test
Expand Down

0 comments on commit 25756a8

Please sign in to comment.