From 59c32bd1f613b5ae26041182f8aca4439777ba95 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 6 Nov 2025 11:57:38 +0800 Subject: [PATCH 1/2] Update file tests to handle content type variations - Modified assertions in file upload, retrieval, and content tests to account for content type variations that may include charset. - Enhanced test robustness by checking that the content type starts with the expected value, improving validation accuracy. --- openapi/tests/file/file_test.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/openapi/tests/file/file_test.go b/openapi/tests/file/file_test.go index a543b374..bebbc235 100644 --- a/openapi/tests/file/file_test.go +++ b/openapi/tests/file/file_test.go @@ -164,7 +164,9 @@ func TestFileUpload(t *testing.T) { assert.Contains(t, response, "path") assert.Contains(t, response, "user_path") assert.Equal(t, testFileName, response["filename"]) - assert.Equal(t, testContentType, response["content_type"]) + // Content type may include charset + contentType, _ := response["content_type"].(string) + assert.True(t, strings.HasPrefix(contentType, testContentType), "Content-Type should start with %s, got %s", testContentType, contentType) assert.Equal(t, "uploaded", response["status"]) // The file_id should be URL-safe (no slashes) and be an MD5 hash (32 chars) @@ -519,7 +521,9 @@ func TestFileRetrieve(t *testing.T) { assert.Contains(t, response, "content_type") assert.Equal(t, testFileID, response["file_id"]) assert.Equal(t, testFileName, response["filename"]) - assert.Equal(t, testContentType, response["content_type"]) + // Content type may include charset + contentType, _ := response["content_type"].(string) + assert.True(t, strings.HasPrefix(contentType, testContentType), "Content-Type should start with %s, got %s", testContentType, contentType) t.Logf("Successfully retrieved file metadata: %s", testFileID) }) @@ -627,7 +631,9 @@ func TestFileContent(t *testing.T) { defer resp.Body.Close() assert.Equal(t, http.StatusOK, resp.StatusCode) - assert.Equal(t, testContentType, resp.Header.Get("Content-Type")) + // Content type may include charset + assert.True(t, strings.HasPrefix(resp.Header.Get("Content-Type"), testContentType), + "Content-Type should start with %s, got %s", testContentType, resp.Header.Get("Content-Type")) // Read and verify content content, err := io.ReadAll(resp.Body) From 0b88fb609803e4f61f9ca1be4c6f1a9f39812944 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 6 Nov 2025 11:57:59 +0800 Subject: [PATCH 2/2] Refactor content type assertion in file tests for improved clarity - Adjusted the assertion for content type in the file tests to enhance readability and maintainability. - Ensured that the content type validation remains robust while checking for variations that may include charset. --- openapi/tests/file/file_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openapi/tests/file/file_test.go b/openapi/tests/file/file_test.go index bebbc235..4774c5cb 100644 --- a/openapi/tests/file/file_test.go +++ b/openapi/tests/file/file_test.go @@ -632,7 +632,7 @@ func TestFileContent(t *testing.T) { assert.Equal(t, http.StatusOK, resp.StatusCode) // Content type may include charset - assert.True(t, strings.HasPrefix(resp.Header.Get("Content-Type"), testContentType), + assert.True(t, strings.HasPrefix(resp.Header.Get("Content-Type"), testContentType), "Content-Type should start with %s, got %s", testContentType, resp.Header.Get("Content-Type")) // Read and verify content