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

feat(taps): Add checks for primary keys, replication keys and state partitioning keys to standard tap tests #829

Merged

Conversation

laurentS
Copy link
Contributor

This PR adds 2 tests to the standard ones that all sdk-based taps run:

  • 1 checks that PKeys are actually in the stream schema
  • 1 does the same for replication keys

Without these tests, it is easy to write invalid streams that will only fail after a certain amount of processing (usually because the target will complain). See this thread in a separate PR for context.
These tests help catch coding errors much sooner, as some errors might live in rarely used streams (or untested ones).

Ideally we could add a third test that validates that all path variables are available in the stream context. This might be best addressed in a separate PR, as this is a bit harder to test, given the dynamic nature of the stream context.

@laurentS
Copy link
Contributor Author

I've tested this with the code in MeltanoLabs/tap-gitlab#71 and it does correctly flag problems.

@codecov
Copy link

codecov bot commented Jul 18, 2022

Codecov Report

Merging #829 (fce9ca1) into main (797226a) will decrease coverage by 0.01%.
The diff coverage is 79.16%.

@@            Coverage Diff             @@
##             main     #829      +/-   ##
==========================================
- Coverage   80.37%   80.36%   -0.02%     
==========================================
  Files          34       34              
  Lines        3425     3448      +23     
  Branches      681      687       +6     
==========================================
+ Hits         2753     2771      +18     
- Misses        499      502       +3     
- Partials      173      175       +2     
Impacted Files Coverage Δ
singer_sdk/testing.py 93.68% <79.16%> (-4.93%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@visch
Copy link
Contributor

visch commented Jul 18, 2022

@laurentS another trick I've been doing is baking a jsonl test into the github actions test. Requires a full data pull but 🤷 just an idea not really for this PR but I happened to see this while cruising through things today!

  jsonl_test:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Set up Python
      uses: actions/setup-python@v2
      with:
        python-version: "3.8"
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install meltano
        meltano install
    - name: Schema test
      run: |
        meltano run tap-name target-jsonl

No real reason we couldn't do a schema check in pytest instead of using a seperate target 🤷

Found the issue #227 I"ll update it! Sorry about hijacking this :D great PR

@edgarrmondragon edgarrmondragon changed the title Add code validation tests to standard tests feat: Add code validation tests to standard tests Jul 18, 2022
@edgarrmondragon
Copy link
Collaborator

Hi and thank you @laurentS! I see in the PR description that is meant to add tests for replication keys, but I only see them for primary keys and state partitioning keys. Let me know if you're planning to add them. Otherwise I can review (and merge) it as is 😄.

@laurentS
Copy link
Contributor Author

Hi and thank you @laurentS! I see in the PR description that is meant to add tests for replication keys, but I only see them for primary keys and state partitioning keys. Let me know if you're planning to add them. Otherwise I can review (and merge) it as is 😄.

Sorry, this was my mistake, but I added an extra test, since it seems like a pretty useful one for correctness. I think this is ready for review now. There are some failures in CI that I'm not sure how to fix.

singer_sdk/testing.py Outdated Show resolved Hide resolved
singer_sdk/testing.py Outdated Show resolved Hide resolved
singer_sdk/testing.py Outdated Show resolved Hide resolved
singer_sdk/testing.py Outdated Show resolved Hide resolved
@edgarrmondragon
Copy link
Collaborator

There are some failures in CI that I'm not sure how to fix.

@laurentS Some of those are linter errors that I've suggested fixes for. The coverage failures I think we can ignore.

@edgarrmondragon edgarrmondragon self-assigned this Jul 27, 2022
@edgarrmondragon edgarrmondragon changed the title feat: Add code validation tests to standard tests feat(taps): Add code validation tests to standard tests Jul 27, 2022
Co-authored-by: Edgar R. M. <edgarrm358@gmail.com>
@edgarrmondragon
Copy link
Collaborator

pre-commit.ci autofix

singer_sdk/testing.py Outdated Show resolved Hide resolved
@edgarrmondragon edgarrmondragon changed the title feat(taps): Add code validation tests to standard tests feat(taps): Add checks for primary keys, replication keys and state partitioning keys to standard tap tests Aug 31, 2022
Copy link
Collaborator

@edgarrmondragon edgarrmondragon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@laurentS codecov is not deal breaker since at least replication key checks should be covered by external GitLab tests when this lands on main. The state partitioning keys test requires a sample that uses those, so that's not on you really.

cc @aaronsteers in case you want to groom the title

@edgarrmondragon edgarrmondragon changed the title feat(taps): Add checks for primary keys, replication keys and state partitioning keys to standard tap tests feat(taps): Add testing helpers for primary keys, replication keys and state partitioning keys to standard tap tests Sep 1, 2022
@edgarrmondragon edgarrmondragon changed the title feat(taps): Add testing helpers for primary keys, replication keys and state partitioning keys to standard tap tests feat(taps): Add checks for primary keys, replication keys and state partitioning keys to standard tap tests Sep 1, 2022
@edgarrmondragon edgarrmondragon enabled auto-merge (squash) September 1, 2022 01:47
@edgarrmondragon edgarrmondragon merged commit 76eed0d into meltano:main Sep 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants