Skip to content
This repository was archived by the owner on Feb 20, 2026. It is now read-only.

test: Add tests that describe how save should encode excludeFromIndexes for a complex case#1263

Merged
danieljbruce merged 34 commits into1242-to-main-2from
1242-write-tests-on-save
Aug 28, 2024
Merged

test: Add tests that describe how save should encode excludeFromIndexes for a complex case#1263
danieljbruce merged 34 commits into1242-to-main-2from
1242-write-tests-on-save

Conversation

@danieljbruce
Copy link
Copy Markdown
Contributor

@danieljbruce danieljbruce commented Aug 14, 2024

Summary:

As part of the broader effort to solve the bug in this document properly this PR will add tests for the save function that ensure the right data is passed to the Gapic layer. Some tests are skipped as they fail because the issue described in #1242 hasn't been solved yet. When these the issue is solved these tests should be passing.

Changes:

10 tests are added - 2 of which are skipped and need source code changes to address

Four simple tests are added to demonstrate the differences between saving array data and saving non-array data:

  • A test named should pass the right properties for a simple name/value pair is added to demonstrate how non-array data is currently save for data with name and value properties.
  • A test named should pass the right properties for a simple name/value pair in an array is added to demonstrate that when the data from the previous test is wrapped in an array that the name and value properties take on a special meaning for how the data is encoded.
  • should position excludeFromIndexes in the right place when provided at the top level ensures that for arrays when excludeFromIndexes: true is provided in the right place at the top level that it is respected.
  • should pass the right properties for a simple name/value pair in an array with excludeFromIndexes list ensures that
    the excludeFromIndexes list is used properly to add excludeFromIndexes: true in the right places.

Two more complex tests are added for non name/value pair data that compare setting excludeLargeProperties to true and providing an excludeFromIndexes list:

  • should pass the right request with a bunch of large properties excluded - passes - Sample input data, and excludeFromIndexes data was taken from this test and passed into the save function with excludeLargeProperties not set. When this data/excludeFromIndexes is passed into save the mutations that get passed to the Gapic layer are checked for correctness against an expectedMutations object. It looks like this encoding works correctly.
  • should pass the right properties for an object with excludeLargeProperties - passes - the same data from should pass the right request with a bunch of large properties excluded is used, but no excludeFromIndexes data is provided. Instead, the excludeLargeProperties flag is set to true so an excludeFromIndexes list is generated. The mutations passed to the Gapic layer are compared with an expectedMutations object which correctly has excludeFromIndexes: true beside all the values containing a large string and the test passes as expected. The previous test has the same expectedMutations.

A test is added that matches the code from the Github issue:

  • should pass the right request with a nested field - skipped - This test directly evaluates the code the user says is failing in Unable to exclude large indexes #1242 and we need source code changes for this test to pass.

3 more complex tests are added for name/value pair combinations demonstrating where excludeFromIndexes: true is applied for non-array data and ensuring that excludeFromIndexes: true is applied in a similar pattern for array data:

  • should pass the right request with a name/value pair and a bunch of large properties excluded - passes
  • should pass the right request with a name/value pair and excludeLargeProperties set to true - passes
  • should pass the right properties for an array with name/value pairs and excludeLargeProperties - skipped

Next steps:

It is clear upon inspection that one of the reasons should pass the right properties for an array with name/value pairs and excludeLargeProperties is failing is that the helper function findLargeProperties_ isn't generating the right excludeFromIndexes list for array values (the list is empty actually). Many test cases for findLargeProperties_ should be written and findLargeProperties_ should be modified to pass tests for the new test cases.

@product-auto-label product-auto-label bot added size: l Pull request size is large. api: datastore Issues related to the googleapis/nodejs-datastore API. labels Aug 14, 2024
@danieljbruce danieljbruce changed the base branch from main to 1242-to-main-2 August 14, 2024 14:23
@danieljbruce danieljbruce marked this pull request as ready for review August 14, 2024 20:34
@danieljbruce danieljbruce requested a review from a team as a code owner August 14, 2024 20:34
@danieljbruce danieljbruce requested a review from a team August 14, 2024 20:34
@danieljbruce danieljbruce marked this pull request as draft August 15, 2024 13:38
@danieljbruce danieljbruce marked this pull request as ready for review August 19, 2024 14:08
@danieljbruce danieljbruce merged commit 25ae641 into 1242-to-main-2 Aug 28, 2024
@danieljbruce danieljbruce deleted the 1242-write-tests-on-save branch August 28, 2024 14:26
danieljbruce added a commit that referenced this pull request Aug 28, 2024
… of nested fields (#1266)

* test: Restrict types inside the save function (#1264)

* Add interfaces that restrict values passed to save

* Add interfaces for save

We need help from the compiler so these interfaces will be useful for determining the shape of the data.

* Modify current interfaces to make a closer match

The interfaces should match the actual data types that get passed in.

* key and data in PrepareEntityObjectResponse option

These properties are actually optional

* Document all the interfaces added for the save fn

* Add two tests showing name/value should be provide

* Make the SaveNonArrayData more specific.

save doesn’t encode strings or ints or any values that don’t have keys properly so we should restrict the interface to what it does include.

* Add header

* Test should be more flexible

* Add a class for elements with ToString

* Define the toString class inline

* Eliminate links to points in code

* test: Add tests that describe how save should encode excludeFromIndexes for a complex case (#1263)

* Write a sample test for what save output should be

* Add a test for a bunch of complex excludeFromIndex

* Change the replace function so it works everywhere

* Modify the expected value

Make it contain longStringArray

* Correct the test for evaluating arrays

* Break up the entityToEntityProto into separate par

* Fix the tests to work with new addExcludeFromIndex

* Revert "Break up the entityToEntityProto into separate par"

This reverts commit 60dabd7.

* Revert "Fix the tests to work with new addExcludeFromIndex"

This reverts commit ba4e82b.

* Remove source code changes

* Skip the test that looks at arrays

* Remove some of the wildcard indexes

This is in excludeFromIndexes - replace them with literals.

* Remove another boolean value from excludeFromIndex

* Eliminate duplicate expectedMutations

* Eliminate duplicate runTest function

* Begin to set up the async tests

* Pack all tests into the async framework

* Delete tests addressed by async

* Get rid of test functions and inline everything

* Add comment

* Add comments describing each test case

* Remove only

* Add another test looks at name/value not in array

* Add a test for excludeLarge properties and name/va

* Fix the test so that the array case matches

Matches the single case

* should pass the right properties for an array

* Rename the test

* Change name to entityName

* Add two tests that capture the array encoding

encoding problem

* Change expected output of arrays

* Remove only

* Add 2 more tests to ensure behaviour is preserved

* Correct test - it should apply excludeFromIndexes

* Update the test for the nested value

* fix: Handle excludeLarge properties for arrays properly (#1265)

* Write a sample test for what save output should be

* Add a test for a bunch of complex excludeFromIndex

* Change the replace function so it works everywhere

* Modify the expected value

Make it contain longStringArray

* Correct the test for evaluating arrays

* Break up the entityToEntityProto into separate par

* Fix the tests to work with new addExcludeFromIndex

* Break up the entityToEntityProto into separate par

* Fix the tests to work with new addExcludeFromIndex

* Revert "Break up the entityToEntityProto into separate par"

This reverts commit 60dabd7.

* Revert "Fix the tests to work with new addExcludeFromIndex"

This reverts commit ba4e82b.

* Remove source code changes

* Skip the test that looks at arrays

* Remove some of the wildcard indexes

This is in excludeFromIndexes - replace them with literals.

* Remove another boolean value from excludeFromIndex

* Eliminate duplicate expectedMutations

* Eliminate duplicate runTest function

* Begin to set up the async tests

* Pack all tests into the async framework

* Delete tests addressed by async

* Get rid of test functions and inline everything

* Add comment

* Add comments describing each test case

* Remove only

* Add another test looks at name/value not in array

* Add a test for excludeLarge properties and name/va

* Fix the test so that the array case matches

Matches the single case

* should pass the right properties for an array

* Rename the test

* Change name to entityName

* Add two tests that capture the array encoding

encoding problem

* Change expected output of arrays

* Remove only

* Add 2 more tests to ensure behaviour is preserved

* Make argument more specific for excludeFromIndexes

* Use excludeLargeProperties for array/non-array cas

* Fix the test to include entity proto

* Correct mistakes in initial implementation

* Don’t skip any of the tests

* Remove only

* Add check for excludeLargeProperties

* Remove TODO

* 🦉 Updates from OwlBot post-processor

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

* 🦉 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>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

api: datastore Issues related to the googleapis/nodejs-datastore API. size: l Pull request size is large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants