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

refactoring changes to make testing possible for inode package using testify mock bucket #2696

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ashmeenkaur
Copy link
Collaborator

Description

This PR includes following refactoring changes:

  • testify mock bucket now implements SyncerBucketInterface
  • file inode now uses SyncerBucketInterface instead of struct SyncerBucket

Link to the issue in case of a bug fix.

NA

Testing details

  1. Manual - NA
  2. Unit tests - Updated
  3. Integration tests - NA

@ashmeenkaur ashmeenkaur marked this pull request as ready for review November 20, 2024 08:06
@ashmeenkaur ashmeenkaur requested a review from a team as a code owner November 20, 2024 08:06
@kislaykishore kislaykishore requested review from a team, BrennaEpp, tritone and gargnitingoogle and removed request for a team, BrennaEpp and tritone November 20, 2024 08:07
Copy link

codecov bot commented Nov 20, 2024

Codecov Report

Attention: Patch coverage is 14.28571% with 6 lines in your changes missing coverage. Please review.

Project coverage is 77.21%. Comparing base (801aada) to head (7774d8b).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
internal/storage/mock/testify_mock_bucket.go 0.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2696      +/-   ##
==========================================
- Coverage   77.53%   77.21%   -0.33%     
==========================================
  Files         112      113       +1     
  Lines       15801    15879      +78     
==========================================
+ Hits        12252    12261       +9     
- Misses       3025     3095      +70     
+ Partials      524      523       -1     
Flag Coverage Δ
unittests 77.21% <14.28%> (-0.33%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@@ -124,3 +125,11 @@ func (m *TestifyMockBucket) CreateFolder(ctx context.Context, folderName string)
}
return nil, args.Error(1)
}

func (m *TestifyMockBucket) SyncObject(ctx context.Context, fileName string, srcObject *gcs.Object, content gcsx.TempFile) (o *gcs.Object, err error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

MockBucket is for mocking bucket operations. Why are we adding custom operations to this file?

Copy link
Collaborator Author

@ashmeenkaur ashmeenkaur Nov 21, 2024

Choose a reason for hiding this comment

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

Added this so that mock bucket also implements SyncerBucketInterface. I want to use it for file_test.go file which uses syncer bucket. Don't think there is value in creating a duplicate struct. Let me know if you think otherwise.

@@ -124,3 +125,11 @@ func (m *TestifyMockBucket) CreateFolder(ctx context.Context, folderName string)
}
return nil, args.Error(1)
}

func (m *TestifyMockBucket) SyncObject(ctx context.Context, fileName string, srcObject *gcs.Object, content gcsx.TempFile) (o *gcs.Object, err error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

also fakes are preferred over mocks. Why do you want to have a mock for syncObject when the methods used by internally has fake implementation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In file_test.go we are creating the content (temp file) before hand for the tests. This won't work for buffered writes as I want to ensure that in case of failure temp file is created. That is why I needed mocks. Do you think there is a better way to do this?

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.

2 participants