Files
seaweedfs/weed/util/compression_test.go
T
d650abe0e7 compression: compress JSON uploads, and match file types by extension (#12339)
* compression: compress JSON uploads, and match file types by extension

IsCompressableFileType did not recognise JSON media types, so S3 uploads of application/json (which carry no file name) were never compressed. Its callers also passed filepath.Base of the file name where it expects the extension, so the .json/.js/.html/... extension rules never matched a real file name. Both callers now pass filepath.Ext; the function lower-cases the extension and media type, ignores media-type parameters ("application/json; charset=utf-8"), and treats */json and *+json types as compressible.

* compression: treat application/json-seq as JSON

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* volume(rust): compress JSON uploads and match media types without parameters

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* operation: keep uploader gzip only when it saves at least 10%

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Pat White <5015863+patwhite@users.noreply.github.com>
Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 10:15:01 -08:00

32 lines
1002 B
Go

package util
import "testing"
func TestIsCompressableFileType(t *testing.T) {
tests := []struct {
ext, mtype string
compress, isSure bool
}{
{".json", "", true, true},
{".JSON", "", true, true},
{"", "application/json", true, true},
{"", "application/json; charset=utf-8", true, true},
{"", "application/ld+json", true, true},
{"", "application/x-ndjson", true, true},
{"", "application/json-seq", true, true},
{"", "Application/JSON", true, true},
{"", "text/plain; charset=utf-8", true, true},
{"", "application/xml", true, true},
{".gz", "application/json", false, true},
{"", "application/gzip", false, false},
{"", "image/png", false, true},
{"", "", false, false},
}
for _, tt := range tests {
compress, isSure := IsCompressableFileType(tt.ext, tt.mtype)
if compress != tt.compress || isSure != tt.isSure {
t.Errorf("IsCompressableFileType(%q, %q) = (%v, %v), want (%v, %v)", tt.ext, tt.mtype, compress, isSure, tt.compress, tt.isSure)
}
}
}