grafana / sqlds

A package that assists writing SQL-driven datasources
Apache License 2.0
17 stars 12 forks source link

unit-tests for zero-rows-returned situations #119

Closed gabor closed 3 months ago

gabor commented 3 months ago

(part of https://github.com/grafana/sqlds/issues/118)

i wanted to add unit-tests that describe the current situation, i'll create a separate PR next that does the change.

NOTE: i had to do a small refactor of the code, because i don't know how to mock sqlutil.FrameFromRows. if anyone has a better idea, i'm all ears.

scottlepp commented 3 months ago

@gabor why do you have to mock FrameFromRows?

gabor commented 3 months ago

@scottlepp what i want to test is the functionality that we do AFTER FrameFromRows is called.

problem is, if i want to call getFrames from the unit-test, i have to provide it a working sql.Rows object... which i don't know how .... is there maybe some helper function in sqlds-repo that helps creating sql.Rows objects?

scottlepp commented 3 months ago

@gabor try https://github.com/grafana/sqlds/blob/main/mock/sqlmock.go#L51

You can create a mock driver and return whatever you want.

Here is a test that uses the mock driver.

gabor commented 3 months ago

@scottlepp thanks for the info 👍 , i updated teh PR to use the mentioned test framework.

gabor commented 3 months ago

sorry @scottlepp , could you re-review it pls? i added one more commit, to cover all possible formats.