Skip to content

Commit

Permalink
fix: set the correct database id on the key parent when calling Key#g…
Browse files Browse the repository at this point in the history
…etParent (#1457)

* fix: set database ID on parent key

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and jimit-j-shah committed Jun 13, 2024
1 parent 6117812 commit e872d9a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
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

0 comments on commit e872d9a

Please sign in to comment.