[DO NOT MERGE] All spanner ut tests#3843
Conversation
…Change recode processor tests
…ng and shadow table creator tests
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request is primarily dedicated to enhancing the testing infrastructure for Spanner-related data migration templates. By adding extensive unit tests for core utilities and DML generation logic, the changes aim to increase code reliability and maintainability. Additionally, the CI configuration has been optimized to provide more accurate and persistent coverage reporting across the project. Highlights
Ignored Files
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3843 +/- ##
============================================
+ Coverage 54.96% 55.53% +0.56%
- Complexity 6925 7002 +77
============================================
Files 1096 1096
Lines 67353 67354 +1
Branches 7558 7558
============================================
+ Hits 37021 37402 +381
+ Misses 27857 27538 -319
+ Partials 2475 2414 -61
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Code Review
This pull request significantly expands test coverage across the spanner-common, spanner-custom-shard, and spanner-to-sourcedb modules by introducing new unit tests for DDL components, DML generation logic, and change stream processing. It also updates the Codecov configuration and adjusts access modifiers to improve testability. Feedback was provided on a new Cassandra DML generator test where unconfigured mocks could lead to false positives.
| Table spannerTable = Mockito.mock(Table.class); | ||
| SourceTable sourceTable = Mockito.mock(SourceTable.class); | ||
| SourceColumn sourceCol = Mockito.mock(SourceColumn.class); | ||
|
|
||
| Mockito.when(sourceTable.primaryKeyColumns()).thenReturn(ImmutableList.of()); | ||
| Mockito.when(sourceTable.columns()).thenReturn(ImmutableList.of(sourceCol)); | ||
| Mockito.when(sourceCol.name()).thenReturn("col1"); | ||
| Mockito.when(mockSchemaMapper.getSpannerColumnName("", "my_table", "col1")) | ||
| .thenThrow(new NoSuchElementException()); | ||
| Mockito.when(sourceTable.name()).thenReturn("my_table"); |
There was a problem hiding this comment.
The spannerTable mock is not configured with a name or schema. By default, spannerTable.getSchema() and spannerTable.getName() will return null. This causes the mock for mockSchemaMapper.getSpannerColumnName at line 903 (which expects "" and "my_table") to not match the actual call made in getColumnValues. As a result, the NoSuchElementException will not be thrown, and the test may pass for the wrong reason (e.g., by returning null instead of throwing). You should configure the spannerTable mock to match the expected arguments in the mockSchemaMapper stub.
ISchemaMapper mockSchemaMapper = Mockito.mock(ISchemaMapper.class);
Table spannerTable = Mockito.mock(Table.class);
SourceTable sourceTable = Mockito.mock(SourceTable.class);
SourceColumn sourceCol = Mockito.mock(SourceColumn.class);
Mockito.when(spannerTable.getName()).thenReturn("my_table");
Mockito.when(spannerTable.getSchema()).thenReturn("");
Mockito.when(sourceTable.primaryKeyColumns()).thenReturn(ImmutableList.of());
Mockito.when(sourceTable.columns()).thenReturn(ImmutableList.of(sourceCol));
Mockito.when(sourceCol.name()).thenReturn("col1");
Mockito.when(mockSchemaMapper.getSpannerColumnName("", "my_table", "col1"))
.thenThrow(new NoSuchElementException());
Mockito.when(sourceTable.name()).thenReturn("my_table");
No description provided.