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

fix: [#554] Storage can't judge nesting folder correctly #39

Merged
merged 1 commit into from
Jan 3, 2025

Conversation

hwbrzzl
Copy link
Contributor

@hwbrzzl hwbrzzl commented Jan 3, 2025

📑 Description

Closes goravel/goravel#554

Summary by CodeRabbit

  • Chores

    • Removed Codecov workflow configuration
    • Updated GitHub Actions test workflow with new environment variables
    • Simplified file path handling in OSS-related tests
  • Bug Fixes

    • Enhanced OSS file and directory handling to prevent empty name additions
    • Improved directory creation logic before file uploads

✅ Checks

  • Added test cases for my code

@hwbrzzl hwbrzzl requested a review from a team as a code owner January 3, 2025 11:05
Copy link

coderabbitai bot commented Jan 3, 2025

Walkthrough

The pull request introduces modifications to the GitHub Actions workflows and the OSS (Object Storage Service) implementation. The changes remove the Codecov workflow, update the test workflow with Aliyun-related environment variables, and enhance the OSS functionality in oss.go. The modifications focus on improving directory and file handling, particularly addressing nested folder creation and path management during file operations.

Changes

File Change Summary
.github/workflows/codecov.yml Workflow file removed entirely
.github/workflows/test.yml Added Aliyun-related environment variables, replaced existing test job with a new Ubuntu-based job that runs Go tests
oss.go Added makeDirectories method to create nested directories before file upload, improved directory and file name validation
oss_test.go Removed rootFolder variable, simplified path references in test cases

Assessment against linked issues

Objective Addressed Explanation
Nested folder creation [#554]
Judging nested folder existence [#554] Requires additional verification of Exist method implementation

The changes appear to partially address the issue of nested folder handling by introducing a makeDirectories method that creates directories sequentially. However, a full verification of the Exist method's behavior would require additional testing to confirm complete resolution of the nested folder existence problem.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@hwbrzzl hwbrzzl changed the base branch from master to v1.3.x January 3, 2025 11:05
@hwbrzzl hwbrzzl closed this Jan 3, 2025
@hwbrzzl hwbrzzl reopened this Jan 3, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
oss.go (1)

361-371: Incremental folder creation logic is clear and avoids repeated calls.
Your loop carefully builds up each subpath. However, if path ends with a trailing slash, consider verifying that it doesn't cause redundant calls to MakeDirectory.

 for i := 1; i < len(folders); i++ {
     folder := strings.Join(folders[:i], "/")
+    if folder == "" {
+        continue
+    }
     if err := r.MakeDirectory(folder); err != nil {
         return err
     }
 }
oss_test.go (1)

383-393: Minor overshadowing of the variable named 'url'.
It may be slightly confusing to reuse url from the environment variable. Consider renaming one of them to avoid overshadowing.

- url := url + "/Url/1.txt"
+ newURL := url + "/Url/1.txt"
 assert.Equal(t, newURL, driver.Url("Url/1.txt"))
 resp, err := http.Get(newURL)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4b4af25 and 5bbda45.

📒 Files selected for processing (4)
  • .github/workflows/codecov.yml (0 hunks)
  • .github/workflows/test.yml (1 hunks)
  • oss.go (5 hunks)
  • oss_test.go (2 hunks)
💤 Files with no reviewable changes (1)
  • .github/workflows/codecov.yml
🔇 Additional comments (26)
oss.go (4)

170-174: Skipping empty directory entries is a good safeguard.
Your check ensures that only valid non-empty directory names are captured. This helps avoid issues when the prefix path is re-inserted as an empty string.


197-200: Proper approach to ignore empty file entries.
This condition prevents the accidental addition of empty filenames. It neatly handles the case where a directory gets returned instead of a file.


280-285: Creating top-level folder ensures path integrity.
By calling makeDirectories here, you reduce failures caused by missing intermediate directories. Error handling is also handled properly.


305-310: Consistent folder creation before file upload in PutFileAs.
Calling r.makeDirectories(str.Of(filePath).Finish("/").String()) is consistent with the logic applied in Put(). This avoids nested folder creation errors.

oss_test.go (20)

48-74: Comprehensive test for nested structures in AllDirectories.
Your assertions cover multiple nested levels. This thoroughly validates that subfolders can be listed.


80-100: Good coverage of multi-level scenario in AllFiles.
Testing both top-level and nested files ensures the listing logic is correct.


106-112: Copy operation confirmed for file existence.
The test verifies that the original file still exists after copying, which is correct behavior for a copy.


118-122: Delete operation tests normal removal and existence checks.
Looks good, verifying the file is missing after deletion.


128-132: DeleteDirectory test is straightforward and conclusive.
Confirms that all contents are removed.


138-160: Directories list test with multiple subdirectories.
The approach of verifying partial path inputs is robust.


166-186: Files listing test ensures partial path usage.
You cover plain, dot-prefixed, and slash-prefixed paths, guaranteeing consistent results.


192-200: Get operation test ensures correct file contents.
Retrieving the file as a string and verifying size is a strong validation.


206-214: GetBytes test provides binary retrieval check.
Covers critical functionality for byte-level operations.


220-228: LastModified test ensures timestamp accuracy.
You validate the truncated timestamp in UTC, which is sufficient for functional checks.


234-240: MakeDirectory test covers single and nested directory creation.
Cleanup after creation is well done.


246-261: MimeType validations for text and image.
Testing both textual and binary files ensures robust MIME type detection.


267-273: Move operation tested thoroughly.
The test ensures the old path is missing and the new path is present, which matches expected behavior.


279-285: Put operation test for deep nested structure.
Successfully confirms that each nested directory is created implicitly.


292-295: PutFile_Image covers a typical use case.
Verifies the file is uploaded properly in a folder.


302-309: PutFile_Text ensures text content is correct after upload.
Reading back the file contents to confirm is a good approach.


316-332: PutFileAs_Text test checks custom file naming.
You confirm both a name without extension and with extension. The test looks thorough.


339-349: PutFileAs_Image test validates custom name with .png extension.
Retains correct extension, ensuring the naming logic is correct.


355-360: Size test ensures file length retrieval.
Matches the expected length of the string "Goravel".


Line range hint 366-377: TemporaryUrl test confirms correct ephemeral link behavior.
Fetching the content from the short-lived URL is a strong integration check.

.github/workflows/test.yml (2)

7-12: Environment variables properly set from GitHub secrets.
This eases running integration tests against Aliyun. No concerns here.


14-24: The ubuntu job is well defined and minimal.
Actions that install dependencies and then run tests are correct. This effectively removes external coverage steps if Codecov was previously used, but meets the PR's objective.

@hwbrzzl hwbrzzl merged commit 88ea82f into v1.3.x Jan 3, 2025
4 checks passed
hwbrzzl added a commit that referenced this pull request Jan 3, 2025
* fix: test (#36) (#37)

* fix: test

* remove codecov

* fix: [#554] Storage can't judge nesting folder correctly (#39)
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.

Storage can't judge nesting folder correctly
1 participant