package files import "testing" // Das Alpine-Image bringt keine /etc/mime.types mit, und Gos eingebaute // Ersatztabelle kennt nur Web-Typen. Ohne die eigene Tabelle landete eine MP3 // als application/octet-stream in der Datenbank – nicht abspielbar, falsches // Symbol. func TestDetectMIMEKennteMedienTypen(t *testing.T) { cases := map[string]string{ "lied.mp3": "audio/mpeg", "clip.mp4": "video/mp4", "paket.zip": "application/zip", "paket.tar.gz": "application/gzip", "tabelle.csv": "text/csv", "BILD.PNG": "image/png", // Endung ohne Rücksicht auf Groß/Klein "folien.pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation", "brief.docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "budget.xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", } for name, want := range cases { if got := detectMIME(name, ""); got != want { t.Errorf("detectMIME(%q) = %q, want %q", name, got, want) } } } // Behauptet der Client etwas Sinnvolles und die Endung sagt nichts, gilt der // Client. Behauptet er octet-stream, ist das keine Aussage. func TestDetectMIMEFallback(t *testing.T) { if got := detectMIME("datei.unbekannt", "image/png"); got != "image/png" { t.Errorf("got %q, want the client type", got) } if got := detectMIME("datei.unbekannt", "application/octet-stream"); got != "application/octet-stream" { t.Errorf("got %q", got) } }