mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-09-11 00:50:43 +02:00
* feat(admin): prefer stored filer mime in file browser and properties * feat(mime): enhance MIME type registration and improve fallback logic Co-authored-by: Copilot <copilot@github.com> --------- Co-authored-by: baracudaz <baracudaz@users.noreply.github.com> Co-authored-by: Copilot <copilot@github.com>
69 lines
1.7 KiB
Go
69 lines
1.7 KiB
Go
package dash
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
)
|
|
|
|
func TestResolveEntryMimePrefersStoredMime(t *testing.T) {
|
|
entry := &filer_pb.Entry{
|
|
Name: "report.txt",
|
|
Attributes: &filer_pb.FuseAttributes{
|
|
Mime: " application/pdf; charset=binary ",
|
|
},
|
|
}
|
|
|
|
if got := ResolveEntryMime(entry); got != "application/pdf" {
|
|
t.Fatalf("ResolveEntryMime() = %q, want %q", got, "application/pdf")
|
|
}
|
|
}
|
|
|
|
func TestResolveEntryMimePrefersStoredMimeMalformedParameter(t *testing.T) {
|
|
entry := &filer_pb.Entry{
|
|
Name: "report.txt",
|
|
Attributes: &filer_pb.FuseAttributes{
|
|
Mime: "APPLICATION/PDF; bad",
|
|
},
|
|
}
|
|
|
|
if got := ResolveEntryMime(entry); got != "application/pdf" {
|
|
t.Fatalf("ResolveEntryMime() = %q, want %q", got, "application/pdf")
|
|
}
|
|
}
|
|
|
|
func TestResolveEntryMimeFallsBackToFilename(t *testing.T) {
|
|
entry := &filer_pb.Entry{Name: "archive.zip"}
|
|
|
|
if got := ResolveEntryMime(entry); got != "application/zip" {
|
|
t.Fatalf("ResolveEntryMime() = %q, want %q", got, "application/zip")
|
|
}
|
|
}
|
|
|
|
func TestResolveEntryMimeReturnsDirectoryMime(t *testing.T) {
|
|
entry := &filer_pb.Entry{
|
|
Name: "folder",
|
|
IsDirectory: true,
|
|
Attributes: &filer_pb.FuseAttributes{
|
|
Mime: "application/json",
|
|
},
|
|
}
|
|
|
|
if got := ResolveEntryMime(entry); got != "inode/directory" {
|
|
t.Fatalf("ResolveEntryMime() = %q, want %q", got, "inode/directory")
|
|
}
|
|
}
|
|
|
|
func TestResolveEntryMimeWhitespaceMimeFallsBackToFilename(t *testing.T) {
|
|
entry := &filer_pb.Entry{
|
|
Name: "archive.zip",
|
|
Attributes: &filer_pb.FuseAttributes{
|
|
Mime: " ",
|
|
},
|
|
}
|
|
|
|
if got := ResolveEntryMime(entry); got != "application/zip" {
|
|
t.Fatalf("ResolveEntryMime() = %q, want %q", got, "application/zip")
|
|
}
|
|
}
|