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

[tests-only][full-ci] add tests for checking the header location for tus upload #10807

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

nabim777
Copy link
Member

@nabim777 nabim777 commented Dec 24, 2024

Description

Since current test uses TUS library for tus operations and is unable to get and check the response.
Due to this, there was no check for the location header on TUS upload.
So, in this PR, following things are done:

  • TUS wrapper class is made and able to check the header response.
  • added step on tus scenario for status code check

Related Issue

Motivation and Context

How Has This Been Tested?

  • test environment:
  • CI
  • locally
  • ...

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests only (no source changes)

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation ticket raised:

@nabim777 nabim777 self-assigned this Dec 24, 2024
@nabim777 nabim777 force-pushed the tests/check-header-location-for-tus-upload branch from b79bb57 to e9d5edd Compare December 24, 2024 11:07
@nabim777 nabim777 force-pushed the tests/check-header-location-for-tus-upload branch 2 times, most recently from e61de04 to c78d8a1 Compare December 27, 2024 04:47
@nabim777 nabim777 marked this pull request as ready for review December 27, 2024 04:48
@nabim777 nabim777 marked this pull request as draft December 27, 2024 04:48
@nabim777 nabim777 force-pushed the tests/check-header-location-for-tus-upload branch from c78d8a1 to 0ec975d Compare January 2, 2025 07:00
@nabim777 nabim777 marked this pull request as ready for review January 2, 2025 08:29
tests/acceptance/TestHelpers/TusClientWrapper.php Outdated Show resolved Hide resolved
tests/acceptance/TestHelpers/TusClientWrapper.php Outdated Show resolved Hide resolved
tests/acceptance/TestHelpers/TusClientWrapper.php Outdated Show resolved Hide resolved
tests/acceptance/TestHelpers/TusClientWrapper.php Outdated Show resolved Hide resolved
@nabim777 nabim777 force-pushed the tests/check-header-location-for-tus-upload branch from ee5defd to 91ea534 Compare January 3, 2025 04:22
@nabim777 nabim777 requested a review from nirajacharya2 January 3, 2025 04:23
@nabim777 nabim777 force-pushed the tests/check-header-location-for-tus-upload branch from 91ea534 to 0842b80 Compare January 3, 2025 05:17
@nabim777 nabim777 requested a review from phil-davis January 3, 2025 06:21
@nabim777 nabim777 force-pushed the tests/check-header-location-for-tus-upload branch 2 times, most recently from d592bae to fa52f68 Compare January 3, 2025 08:54
@nabim777 nabim777 force-pushed the tests/check-header-location-for-tus-upload branch 2 times, most recently from db2f7b6 to c860b81 Compare January 7, 2025 10:56
tests/acceptance/bootstrap/TUSContext.php Outdated Show resolved Hide resolved
* @throws GuzzleException
* @throws ReflectionException
*/
public function publicUploadFileUsingTus(
Copy link
Member

Choose a reason for hiding this comment

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

can we use the above existing method (update if necessary)?

Copy link
Member Author

Choose a reason for hiding this comment

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

@saw-jan Could you check the changes I made to this function and let me know if they are what you meant?

@nabim777 nabim777 requested a review from saw-jan January 14, 2025 09:45
@nabim777 nabim777 force-pushed the tests/check-header-location-for-tus-upload branch 7 times, most recently from 9afc1e7 to d715bbf Compare January 21, 2025 11:21
@nabim777 nabim777 force-pushed the tests/check-header-location-for-tus-upload branch 3 times, most recently from c8883d7 to f12a814 Compare January 22, 2025 03:43
Signed-off-by: nabim777 <[email protected]>
@nabim777 nabim777 force-pushed the tests/check-header-location-for-tus-upload branch from f12a814 to a2fd9b6 Compare January 22, 2025 08:38
* @return ResponseInterface
* @throws GuzzleException
*/
public function createUploadWithResponse(string $key, int $bytes = -1): ResponseInterface {
Copy link
Member

Choose a reason for hiding this comment

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

since we want to reflect the existing methods but return differently, I recommend appending a char like this.

Suggested change
public function createUploadWithResponse(string $key, int $bytes = -1): ResponseInterface {
public function createWithUploadR(string $key, int $bytes = -1): ResponseInterface {

* @throws GuzzleException
* @throws TusException | ConnectionException
*/
public function uploadWithResponse(int $bytes = -1): ResponseInterface {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public function uploadWithResponse(int $bytes = -1): ResponseInterface {
public function uploadR(int $bytes = -1): ResponseInterface {

tests/acceptance/TestHelpers/TusClient.php Outdated Show resolved Hide resolved
tests/acceptance/TestHelpers/TusClient.php Outdated Show resolved Hide resolved
Comment on lines 130 to 141
try {
$response = $this->getClient()->patch(
$this->getUrl(),
[
'body' => $data,
'headers' => $headers,
]
);
} catch (ClientException $e) {
throw $this->handleClientException($e);
}
return $response;
Copy link
Member

Choose a reason for hiding this comment

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

just return a response?

tests/acceptance/TestHelpers/TusClient.php Outdated Show resolved Hide resolved
if ($this->isPartial()) {
$headers += ['Upload-Concat' => 'partial'];
}
try {
Copy link
Member

Choose a reason for hiding this comment

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

check if we need try catch

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

@nabim777 nabim777 Jan 23, 2025

Choose a reason for hiding this comment

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

@saw-jan
First of all thanks for the docs.
As documet you have shared
can I add 'http_errors' => false, on post ?
it says it'll disable throwing exceptions on an HTTP protocol errors (i.e., 4xx and 5xx responses).

$response = $this->getClient()->post(
	$this->apiPath,
	[
	'body' => $data,
	'headers' => $headers,
	'http_errors' => false,
	]
);

@@ -46,7 +46,7 @@ class TusClient extends Client {
* @return ResponseInterface
* @throws GuzzleException
*/
public function createUploadWithResponse(string $key, int $bytes = -1): ResponseInterface {
public function createWithUploadR(string $key, int $bytes = -1): ResponseInterface {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public function createWithUploadR(string $key, int $bytes = -1): ResponseInterface {
public function createUploadWithResponse(string $key, int $bytes = -1): ResponseInterface {

Copy link
Member

Choose a reason for hiding this comment

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

createUploadWithResponse is not a good name here. create with response seems a bit odd.
we are mimicking createWithUpload method from parent class but this time it retruns response. So, either createWithUploadR or createWithUploadRR - return response

Copy link
Member

Choose a reason for hiding this comment

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

you can have a comment for the method

Copy link
Member Author

@nabim777 nabim777 Jan 23, 2025

Choose a reason for hiding this comment

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

can i have comment like this?
creates a resource with a post request and returns response

@nabim777 nabim777 force-pushed the tests/check-header-location-for-tus-upload branch 2 times, most recently from 1a16898 to 4381533 Compare January 23, 2025 11:05
Signed-off-by: nabim777 <[email protected]>
@nabim777 nabim777 force-pushed the tests/check-header-location-for-tus-upload branch from 4381533 to 11993f0 Compare January 23, 2025 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants