test: Added Unit tests for stream.go file's methods#980
test: Added Unit tests for stream.go file's methods#980supersanchayrx wants to merge 14 commits into
Conversation
added test for NewStream(), WithSyncMode(), WithPrimaryKey(), WithCursorField(), WithSchema(), Wrap(). left for WithUpsertField(), UnmarshalJson(), StreamsToMap(), LogCatalog(), ID().
|
@supersanchayrx Thanks a lot! Will assign a reviewer for this PR soon. |
|
@supersanchayrx Assigning @saksham-datazip to review your PR |
Signed-off-by: Sanchay <grindinforvalore@gmail.com>
saksham-datazip
left a comment
There was a problem hiding this comment.
Sorry for the late review and please make the respective changes.
| }) | ||
| } | ||
|
|
||
| func TestStream_UnmarshalJSON(t *testing.T) { |
There was a problem hiding this comment.
Please try to follow patterns as the way we followed in other files by creating a struct and also make the same changes in function below as well.
There was a problem hiding this comment.
Could you please use the same test case structure that's used in the other tests as well? It would help maintain consistency across the test suite for All the functions.Like this:-
tests := []struct {
testName string
syncIndex int
}{
Instead of directly using t.Run
There was a problem hiding this comment.
done
it now uses this kind of tests struct pattern only. it has per field expected values to cross check against. all of the test cases are traversed through loop. Made sure this pattern remains consistent with other methods as well.
|
Hey sure I'll fix these asap thanks for the review |
|
@supersanchayrx Are you still working on this unit test? |
|
Hey @saksham-datazip sorry for the delay. Yup I implemented your suggestions and fixed the code wherever needed. Please review it once more. Thanks! |
saksham-datazip
left a comment
There was a problem hiding this comment.
I've addressed the previous comments on my end, but it looks like a few comments are still pending from your side. Could you please take a look at those as well? If you have any questions or need any clarification, feel free to ask in the comments.
| asserts.Equal(tt.expectedStream.Name, stream.Name) | ||
| asserts.Equal(tt.expectedStream.Namespace, stream.Namespace) | ||
| asserts.NotNil(stream.SupportedSyncModes, "SupportedSyncModes should be initialized") | ||
| asserts.NotNil(stream.SourceDefinedPrimaryKey, "SourceDefinedPrimaryKey should be initialized") | ||
| asserts.NotNil(stream.AvailableCursorFields, "AvailableCursorFields should be initialized") | ||
| asserts.NotNil(stream.Schema, "Schema should be initialized") | ||
| asserts.Equal(tt.expectedStream.DestinationDatabase, stream.DestinationDatabase) | ||
| asserts.Equal(tt.expectedStream.DestinationTable, stream.DestinationTable) |
There was a problem hiding this comment.
instead of this much checks you should use asserts.Equal(tt.expectedStream, stream)
and apart from this the streams which we are getting as output are different from expected so consider using complete structure, Like this :-
expectedStream: &Stream{
Name: "User-Orders.v2",
Namespace: "My.Schema",
Schema: NewTypeSchema(),
SupportedSyncModes: NewSet[SyncMode](),
SourceDefinedPrimaryKey: NewSet[string](),
AvailableCursorFields: NewSet[string](),
DestinationDatabase: ":my_schema",
DestinationTable: "user_orders_v2",
},
Note: This is a dummy code
There was a problem hiding this comment.
Done! thanks for the dummy code 👍
| stream := NewStream("users", "public", nil) | ||
| returnedStream := stream.WithPrimaryKey(tt.keys...) | ||
|
|
There was a problem hiding this comment.
returnedStream was previously named outputStream. Could we make the naming consistent? Also, if there are any other variable names that could be made more consistent throughout the test for better readability, it would be nice to update those as well.
There was a problem hiding this comment.
I have changed this and also tried to keep consistent naming across file
| testName: "multiple keys", | ||
| keys: []string{"id", "user_uuid"}, | ||
| expectedKeys: []string{"id", "user_uuid"}, | ||
| }, | ||
| { | ||
| testName: "composite key", | ||
| keys: []string{"tenant_id", "user_id", "order_id"}, | ||
| expectedKeys: []string{"tenant_id", "user_id", "order_id"}, | ||
| }, |
There was a problem hiding this comment.
multiple keys test and composite keys tests are kind of same just with different number of keys and due to their naming ig this testName "keys with underscores" is redundant.
There was a problem hiding this comment.
Yes i've removed the redundant test cases.
| testName string | ||
| fields []string | ||
| expectedFields []string |
There was a problem hiding this comment.
Can you change this fields name with the function input name also check for other variables.
There was a problem hiding this comment.
changed 'fields' -> 'columns' to match the function input var name
| { | ||
| testName: "single field", | ||
| fields: []string{"updated_at"}, | ||
| expectedFields: []string{"updated_at"}, | ||
| }, | ||
| { | ||
| testName: "multiple fields", | ||
| fields: []string{"updated_at", "inserted_at"}, | ||
| expectedFields: []string{"updated_at", "inserted_at"}, | ||
| }, | ||
| { | ||
| testName: "timestamp fields", | ||
| fields: []string{"created_at", "updated_at", "deleted_at"}, | ||
| expectedFields: []string{"created_at", "updated_at", "deleted_at"}, | ||
| }, | ||
| { | ||
| testName: "duplicate fields", | ||
| fields: []string{"updated_at", "updated_at", "inserted_at"}, | ||
| expectedFields: []string{"updated_at", "inserted_at"}, | ||
| }, | ||
| { | ||
| testName: "empty fields", | ||
| fields: []string{}, | ||
| expectedFields: []string{}, | ||
| }, | ||
| { | ||
| testName: "fields with underscores", |
There was a problem hiding this comment.
Also Can you please confirm these all checks seems to be redundant ?
There was a problem hiding this comment.
yes removed the redundant check
| //test for merging two datatypes on subsequent upsert calls with same names | ||
| t.Run("Multiple datatypes test", func(t *testing.T) { | ||
| asserts := assert.New(t) | ||
| stream := NewStream("phones", "seller", nil) | ||
|
|
||
| stream.UpsertField("codename", Int64, false, false) | ||
| stream.UpsertField("codename", String, true, true) | ||
|
|
There was a problem hiding this comment.
Can we write this testcase like others no need for a new t.Run ?
There was a problem hiding this comment.
I can do it but I purposely kept it separate as it needs to check whether 2 usertfields on 1 col actually gives merged types. Making this into the table tests would reduce readibilty in my opinion and would also look a bit odd but nonetheless I can make it happen. Do let me know I'll make that change quick
| { | ||
| testName: "wrap with large index", | ||
| syncIndex: 100, | ||
| }, |
There was a problem hiding this comment.
Look into those tc as this function is input independent 1-2 basic testcases is more than enough
There was a problem hiding this comment.
yeah removed trivial ones. Just kept the -ve and 0
| for _, tt := range tests { | ||
| t.Run(tt.testName, func(t *testing.T) { | ||
| stream := NewStream("users", "public", nil) | ||
| configuredStream := stream.Wrap(tt.syncIndex) |
There was a problem hiding this comment.
here also try to make this name configuredStream consistent as told earlier
There was a problem hiding this comment.
yes followed consistency for all variables in general throughout the file
| assert.NotNil(t, configuredStream, "Should return a configuredStream") | ||
| assert.Same(t, stream, configuredStream.Stream, "Should wrap the exact same stream instance") |
There was a problem hiding this comment.
Can we use equal instead of those two lines ?
There was a problem hiding this comment.
yes used equal directly of 2 individual checks.
| }) | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
For the function after line 538 i am expecting you to make changes if possible else a reason why we cant follow olake pattern.
There was a problem hiding this comment.
done. Sorry for not resolving this in last review
it now uses this kind of tests struct pattern only as you suggested in other comment. it has per field expected values to cross check against. all of the test cases are traversed through loop. Made sure this pattern remains consistent with other methods as well.
|
@supersanchayrx Hey! Are you still working on this issue? If so, please let us know. Otherwise, we'll have to close this PR due to inactivity. |
|
hey yes sorry for the delay. I'm pushing an update asap |
|
Please have a review once more |
Description
Added comprehensive unit tests for
stream.gofile.Fixes #661
Type of change
How Has This Been Tested?
All tests verified via
go test ./types -v -run "TestStream_"Screenshots or Recordings
stream.file.tests.mp4
Video Content :
All unit test cases pass.
sync.tests.mp4
Video Content:
The streams.go interaction with other files still work properly as the sync shows expected behaviour.
Documentation
Related PR's (If Any):
#680