karmada icon indicating copy to clipboard operation
karmada copied to clipboard

operator/pkg: unit test utilities

Open mohamedawnallah opened this issue 1 year ago • 8 comments

Description

In this commit, we unit test utilities on downloader operations and unpacking tar files.

What type of PR is this?

Which issue(s) this PR fixes: Part of #5491.

Does this PR introduce a user-facing change?:

NONE

mohamedawnallah avatar Oct 11 '24 16:10 mohamedawnallah

:warning: Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 38.60%. Comparing base (c16e52a) to head (49eb96b). Report is 71 commits behind head on master.

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5675      +/-   ##
==========================================
+ Coverage   35.85%   38.60%   +2.75%     
==========================================
  Files         647      650       +3     
  Lines       45070    55122   +10052     
==========================================
+ Hits        16158    21281    +5123     
- Misses      27664    32480    +4816     
- Partials     1248     1361     +113     
Flag Coverage Δ
unittests 38.60% <100.00%> (+2.75%) :arrow_up:

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

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar Oct 11 '24 17:10 codecov-commenter

When I run the ut in the windows, it report error:

=== RUN   TestDownloadFile/DownloadFile_FileDownlaoded_
    util_test.go:229: failed to prep before downloading the file, got: failed to create temp file: open C:\Users\C00502~1\AppData\Local\Temp/tempfile-*.txt: The filename, directory name, or volume label syntax is incorrect.
    util_test.go:236: unexpected error, got: failed to download file. url: https://www.example.com/test-file code: 503
    util_test.go:242: failed to verify the actual of download of file: failed   to read file: open C:\Users\C00502~1\AppData\Local\Temp/tempfile-*.txt: The filename, directory name, or volume label syntax is incorrect.
--- FAIL: TestDownloadFile (0.00s)
    --- PASS: TestDownloadFile/DownloadFile_UrlIsNotFound_FailedToGetResponse (0.00s)
    --- PASS: TestDownloadFile/DownloadFile_ServiceIsUnavailable_FailedToReachTheService (0.00s)
    --- FAIL: TestDownloadFile/DownloadFile_FileDownlaoded_ (0.00s)

@XiShanYongYe-Chang Good catch! The current unit testing code assumed it was only targeting the Linux platform, so it used "/" as a separator. I've updated it to use filepath.Join for platform independence. That said, I haven't been able to test it on Windows since I don't have access to one. Could you please test it again and let me know? 🙏

mohamedawnallah avatar Oct 16 '24 09:10 mohamedawnallah

Okay, let me have a retry.

XiShanYongYe-Chang avatar Oct 16 '24 09:10 XiShanYongYe-Chang

I've updated the last commit. @XiShanYongYe-Chang, I realized that I forgot to replace one instance where "/" was used. 😁 Please pull the latest commit! 🙏

mohamedawnallah avatar Oct 16 '24 09:10 mohamedawnallah

It still failed:

=== RUN   TestDownloadFile/DownloadFile_FileDownlaoded_
    util_test.go:230: failed to prep before downloading the file, got: failed to create temp file: open C:\Users\C00502~1\AppData\Local\Temp\tempfile-*.txt: The filename, directory name, or volume label syntax is incorrect.
    util_test.go:237: unexpected error, got: failed to download file. url: https://www.example.com/test-file code: 503
    util_test.go:243: failed to verify the actual of download of file: failed   to read file: open C:\Users\C00502~1\AppData\Local\Temp\tempfile-*.txt: The filename, directory name, or volume label syntax is incorrect.
--- FAIL: TestDownloadFile (0.00s)
    --- PASS: TestDownloadFile/DownloadFile_UrlIsNotFound_FailedToGetResponse (0.00s)
    --- PASS: TestDownloadFile/DownloadFile_ServiceIsUnavailable_FailedToReachTheService (0.00s)
    --- FAIL: TestDownloadFile/DownloadFile_FileDownlaoded_ (0.00s)

XiShanYongYe-Chang avatar Oct 17 '24 03:10 XiShanYongYe-Chang

/assign

XiShanYongYe-Chang avatar Oct 17 '24 04:10 XiShanYongYe-Chang

@XiShanYongYe-Chang, I've updated the commit. I believe the issue is primarily with the naming of the file tempfile-*.txt, but I'm still not 100% sure. Could you please try it again and let me know how it goes? 🙏

mohamedawnallah avatar Oct 17 '24 18:10 mohamedawnallah

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: XiShanYongYe-Chang

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment Approvers can cancel approval by writing /approve cancel in a comment

karmada-bot avatar Oct 29 '24 01:10 karmada-bot