Merge pull request #1271 from trheyi/main

Update file tests to handle content type variations
This commit is contained in:
Max 2025-11-06 11:59:02 +08:00 committed by GitHub
commit 4699f4fa24
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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)