Skip to content

feat: Add Testing suite for destination plugins#369

Merged
kodiakhq[bot] merged 23 commits intomainfrom
feat/testing_suite_destination_plugins
Nov 8, 2022
Merged

feat: Add Testing suite for destination plugins#369
kodiakhq[bot] merged 23 commits intomainfrom
feat/testing_suite_destination_plugins

Conversation

@yevgenypats
Copy link
Copy Markdown
Contributor

@yevgenypats yevgenypats commented Nov 7, 2022

Closes #348

Introduce testing suite for destination plugins as well as number of methods to including transformers and reverseTransformers to help testing suite be able to test "end-to-end".

This also adds more testing with a memoryDB plugin to test destination plugin and destination plugin testing suite

@github-actions github-actions bot added feat and removed feat labels Nov 7, 2022
Copy link
Copy Markdown
Contributor

@hermanschaaf hermanschaaf left a comment

Choose a reason for hiding this comment

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

There's quite a bit to unpack here, so I haven't reviewed it in great detail, but noticed a few small testing-related bugs

yevgenypats and others added 9 commits November 7, 2022 19:12
Co-authored-by: Herman Schaaf <hermanschaaf@gmail.com>
Co-authored-by: Herman Schaaf <hermanschaaf@gmail.com>
Co-authored-by: Herman Schaaf <hermanschaaf@gmail.com>
Co-authored-by: Herman Schaaf <hermanschaaf@gmail.com>
Co-authored-by: Herman Schaaf <hermanschaaf@gmail.com>
Co-authored-by: Herman Schaaf <hermanschaaf@gmail.com>
Co-authored-by: Herman Schaaf <hermanschaaf@gmail.com>
Co-authored-by: Herman Schaaf <hermanschaaf@gmail.com>
@erezrokah
Copy link
Copy Markdown
Member

Looks like the newly added tests on Windows are failing https://github.com/cloudquery/plugin-sdk/actions/runs/3412572062/jobs/5678256683

@yevgenypats
Copy link
Copy Markdown
Contributor Author

Looks like the newly added tests on Windows are failing https://github.com/cloudquery/plugin-sdk/actions/runs/3412572062/jobs/5678256683

wow so weird. maybe something related to time. seems like it cannot delete stale data on windows or fails to do so.

@yevgenypats
Copy link
Copy Markdown
Contributor Author

Ok I think found the bug on windows actions. seems like either it is "too fast" but more likely time.Now returns the same thing 🤷 per run.

Copy link
Copy Markdown
Member

@erezrokah erezrokah left a comment

Choose a reason for hiding this comment

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

I think the helper methods and memory plugin make sense.

I might be missing something with the test suites. Maybe we could make them more readable by having a clear structure of setup, act, assert, and splitting the suites (especially the overwrite one), so each one tests a single use case?

ctx := context.Background()
logger := getTestLogger(t)

t.Run("TestWriteOverwrite", func(t *testing.T) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe we should use a list of enums instead of multiple booleans? Then this should will be a for loop of the suites we want to run (instead of running, then skipping).

We can default to all if the list is nil

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Tried a different approach now.

expectedResource := &schema.DestinationResource{
TableName: tables[0].Name,
Data: TestData(),
if !s.skipTestOverWriteDeleteStale {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These lines don't impact the outcome of the test (you can remove them and TestDestinationPlugin passes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not sure I understand. some plugins dont support DeleteStale

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I mean you can remove the entire block (including DeleteStale) and the test still passes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

But I want to run deletestale for plugins that support it so why remove it? or we are talking about a different block.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That is what's confusing for me, why do we need it if the test passes without it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I removed it I was referring to a deletestale lateron where I check if it was deleted after that via read

sourceName := uuid.NewString()
resource := schema.DestinationResource{
TableName: table.Name,
Data: testdata.TestData(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not that happy about different tests sharing the same data. I think it's better to have it duplicated than creating a dependency between the different tests, WDYT?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

They dont share it. it creates new data every call to TestData

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

By share I mean if someone changes TestData it impacts all tests (i.e. I can add data to test something and it will break other tests accidentally)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It wont impact as it creates a new struct or we are talking about something else. Each test creates it's own testdata.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh you mean the function itself. yes but no one else is using it so let's keep it as is now given we didn't have tests before.

TableName: table.Name,
Data: testdata.TestData(),
}
_ = resource2.Data[5].Set("00000000-0000-0000-0000-000000000007")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This might a bit hard to read. Maybe we can struct the test data in a way that it's clear what is its type?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agree, there is no good way here. maybe we need some support from the SDK but I would leave this out for now as it turns a bit into an "ORM" given read abilities.

}

func DestinationPluginTestHelper(ctx context.Context, p *DestinationPlugin, logger zerolog.Logger, spec specs.Destination) error {
func (s *DestinationPluginTestSuite) destinationPluginTestWriteOverwrite(ctx context.Context, p *DestinationPlugin, logger zerolog.Logger, spec specs.Destination) error {
Copy link
Copy Markdown
Member

@erezrokah erezrokah Nov 8, 2022

Choose a reason for hiding this comment

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

Doesn't this test only OverWriteDeleteStale?

If I remove the code that handles skipTestOverWriteDeleteStale (both sections of it) the test fails.
I'm not sure how this tests only overwrite mode.

May I suggest splitting this suite to 2 distinct suites, 1 for overwrite mode and another for overwrite with delete stale?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added a struct with options instead of with


func TestDestinationPlugin(t *testing.T) {
p := NewDestinationPlugin("test", "development", NewTestDestinationMemDBClient)
DestinationPluginTestSuiteRunner(t, p, specs.Destination{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm a bit confused by this. DestinationPluginTestSuiteRunner runs TestWriteOverwrite and TestWriteAppend, but we set the plugin write mode to WriteModeAppend.

I'd expect it so each suite will run on a specific plugin write mode

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The testsuite will re-run Init. maybe I need to change it to get just the spec of the plugin instead of the destination.

@yevgenypats yevgenypats requested a review from erezrokah November 8, 2022 12:18
@yevgenypats
Copy link
Copy Markdown
Contributor Author

@erezrokah Thanks! Can you please take another look?


t.Run("TestWriteOverwrite", func(t *testing.T) {
t.Helper()
if suite.tests.Overwrite {
Copy link
Copy Markdown
Member

@erezrokah erezrokah Nov 8, 2022

Choose a reason for hiding this comment

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

Shouldn't this be:

if suite.tests.Overwrite {
  t.Run("TestWriteOverwrite"...
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think not because otherwise I cant call t.skip which will give indicator on what tests were skipped natively.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, cool but then it should be if !suite.tests.Overwrite to skip when the condition is false?

@yevgenypats yevgenypats requested a review from erezrokah November 8, 2022 12:39
Copy link
Copy Markdown
Member

@erezrokah erezrokah left a comment

Choose a reason for hiding this comment

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

The remaining comments are non blocking

@kodiakhq kodiakhq bot merged commit 1a542b9 into main Nov 8, 2022
@kodiakhq kodiakhq bot deleted the feat/testing_suite_destination_plugins branch November 8, 2022 13:20
kodiakhq bot pushed a commit that referenced this pull request Nov 8, 2022
🤖 I have created a release *beep* *boop*
---


## [1.1.0](v1.0.4...v1.1.0) (2022-11-08)


### Features

* Add Testing suite for destination plugins ([#369](#369)) ([1a542b9](1a542b9))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
kodiakhq bot pushed a commit to cloudquery/cloudquery that referenced this pull request Nov 8, 2022
SCKelemen pushed a commit to SCKelemen/cloudquery that referenced this pull request Nov 15, 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