This repository has been archived by the owner on Aug 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
test: add Mongo Asset's FindByID
unit testing
#139
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Signed-off-by: KeisukeYamashita <[email protected]>
Signed-off-by: KeisukeYamashita <[email protected]>
Codecov Report
@@ Coverage Diff @@
## main #139 +/- ##
==========================================
- Coverage 36.68% 34.61% -2.07%
==========================================
Files 331 349 +18
Lines 29890 31755 +1865
==========================================
+ Hits 10964 10992 +28
- Misses 17925 19760 +1835
- Partials 1001 1003 +2
|
Signed-off-by: KeisukeYamashita <[email protected]>
KeisukeYamashita
commented
May 8, 2022
KeisukeYamashita
changed the title
[WIP] Add Mongo Asset's
Add Mongo Asset's May 8, 2022
FindByID
unit testingFindByID
unit testing
TODO ✔️
|
rot1024
changed the title
Add Mongo Asset's
test: add Mongo Asset's May 9, 2022
FindByID
unit testingFindByID
unit testing
rot1024
reviewed
May 9, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! How about creating a helper function like this one?
func connect(t *testing.T) func() (*mongodoc.Client, func()) {
t.Helper()
// Skip unit testing if "REEARTH_DB" is not configured
// See details: https://github.com/reearth/reearth/issues/273
db := os.Getenv("REEARTH_DB")
if db == "" {
t.SkipNow()
return nil
}
c, _ := mongo.Connect(
context.Background(),
options.Client().
ApplyURI(db).
SetConnectTimeout(time.Second*10),
)
return func() {
database, _ := uuid.New()
databaseName := "reearth-test-" + string(database[:])
client := mongodoc.NewClient(databaseName, c)
return client, func() {
_ = c.Database(databaseName).Drop(context.Background())
}
}
}
Usage:
func TestFindByID(t *testing.T) {
// ...
initDB := connect(t)
for _, tc := range tests {
tc := tc
t.Run(tc.Name, func() {
t.Paralell()
client, dropDB := initDB()
defer dropDB()
repo := NewAsset(client)
ctx := context.Background()
err := repo.Save(ctx, want)
assert.NoError(t, err)
got, err := repo.FindByID(ctx, want.ID())
// ...
})
}
}
Signed-off-by: KeisukeYamashita <[email protected]>
Signed-off-by: KeisukeYamashita <[email protected]>
KeisukeYamashita
force-pushed
the
test-mongo-asset-findbyid
branch
from
May 9, 2022 14:07
06278f8
to
7810ec8
Compare
Signed-off-by: KeisukeYamashita <[email protected]>
Signed-off-by: KeisukeYamashita <[email protected]>
15 tasks
rot1024
approved these changes
May 10, 2022
Thank you for your review 😄 |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
I have added initial unit testing for the MongoDB based on this issue for "small start" 👉 reearth/reearth-visualizer#273.
See details (requirements) in that issue.
I implemented one for a trial to avoid conflicts and decide how we are going to test this methods.
What I've done
I have added unit test for the Asset repository's
FindByID
method.What I haven't done
Add unit tests for all methods for Assets or other repositories.
This is because I wanted to "start small" since we need to discuss the policy and the implementation design first so that we don't waste time.
How I tested
The testings are done by the CI GitHub Actions workflow.
This can be also tested locally.
Which point I want you to review particularly
Memo
Please feel free to give me any feedback as this is the starting point of adding unit tests to the repository layer.