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

fix: set the correct database id on the key parent when calling Key#getParent #1457

Merged
merged 2 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ public Key getParent() {
PathElement parent = ancestors.get(ancestors.size() - 1);
Key.Builder keyBuilder;
if (parent.hasName()) {
keyBuilder = Key.newBuilder(getProjectId(), parent.getKind(), parent.getName());
keyBuilder =
Key.newBuilder(getProjectId(), parent.getKind(), parent.getName(), getDatabaseId());
} else {
keyBuilder = Key.newBuilder(getProjectId(), parent.getKind(), parent.getId());
keyBuilder =
Key.newBuilder(getProjectId(), parent.getKind(), parent.getId(), getDatabaseId());
}
String namespace = getNamespace();
if (namespace != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@

public class IncompleteKeyTest {

private static IncompleteKey pk1, pk2, pk4;
private static Key parent1;
private static IncompleteKey pk1, pk2, pk4, pk5;
private static Key parent1, parent2;

@Before
public void setUp() {
pk1 = IncompleteKey.newBuilder("ds", "kind1").build();
parent1 = Key.newBuilder("ds", "kind2", 10).setNamespace("ns").build();
parent2 = Key.newBuilder("ds", "kind2", 10, "test-db").setNamespace("ns").build();
pk2 = IncompleteKey.newBuilder(parent1, "kind3").build();
pk4 = IncompleteKey.newBuilderWithDatabaseId("ds", "kind3", "test-db").build();
pk5 = IncompleteKey.newBuilder(parent2, "kind4").build();
}

@Test
Expand All @@ -59,12 +61,18 @@ public void testBuilders() {
assertEquals("test-db", pk4.getDatabaseId());
assertEquals("kind3", pk4.getKind());
assertTrue(pk4.getAncestors().isEmpty());

assertEquals("ds", pk5.getProjectId());
assertEquals("test-db", pk5.getDatabaseId());
assertEquals("kind4", pk5.getKind());
assertEquals(parent2.getPath(), pk5.getAncestors());
}

@Test
public void testParent() {
assertNull(pk1.getParent());
assertEquals(parent1, pk2.getParent());
assertEquals(parent2, pk5.getParent());
Key parent2 = Key.newBuilder("ds", "kind3", "name").setNamespace("ns").build();
IncompleteKey pk3 = IncompleteKey.newBuilder(parent2, "kind3").build();
assertEquals(parent2, pk3.getParent());
Expand Down
Loading