Spaces:
Paused
Paused
ML Intern deploy
Deploy httpSMS gateway to Hugging Face Spaces (Docker SDK): nginx :7860 -> Go API :8000, Nuxt SPA, Android APK, bootstrap-mode entrypoint
83a59ca Download api/pkg/repositories/attachment_repository_test.go from red-kit/httpsms-gateway: direct link, hf CLI and curl.
- Browser
- Download file 1.62 kB
-
https://huggingface.co/spaces/red-kit/httpsms-gateway/resolve/main/api/pkg/repositories/attachment_repository_test.go
- Command line
-
hf download hf://spaces/red-kit/httpsms-gateway/api/pkg/repositories/attachment_repository_test.go
-
curl -L -o attachment_repository_test.go https://huggingface.co/spaces/red-kit/httpsms-gateway/resolve/main/api/pkg/repositories/attachment_repository_test.go
1.62 kB
| package repositories | |
| import "testing" | |
| func TestExtensionFromContentType(t *testing.T) { | |
| tests := []struct { | |
| contentType string | |
| expected string | |
| }{ | |
| {"image/jpeg", ".jpg"}, | |
| {"image/png", ".png"}, | |
| {"image/gif", ".gif"}, | |
| {"image/webp", ".webp"}, | |
| {"image/bmp", ".bmp"}, | |
| {"video/mp4", ".mp4"}, | |
| {"video/3gpp", ".3gp"}, | |
| {"audio/mpeg", ".mp3"}, | |
| {"audio/ogg", ".ogg"}, | |
| {"audio/amr", ".amr"}, | |
| {"application/pdf", ".pdf"}, | |
| {"text/vcard", ".vcf"}, | |
| {"text/x-vcard", ".vcf"}, | |
| {"application/octet-stream", ".bin"}, | |
| {"unknown/type", ".bin"}, | |
| {"", ".bin"}, | |
| } | |
| for _, tt := range tests { | |
| t.Run(tt.contentType, func(t *testing.T) { | |
| got := ExtensionFromContentType(tt.contentType) | |
| if got != tt.expected { | |
| t.Errorf("ExtensionFromContentType(%q) = %q, want %q", tt.contentType, got, tt.expected) | |
| } | |
| }) | |
| } | |
| } | |
| func TestSanitizeFilename(t *testing.T) { | |
| tests := []struct { | |
| name string | |
| index int | |
| expected string | |
| }{ | |
| {"photo.jpg", 0, "photo"}, | |
| {"../../etc/passwd", 0, "etcpasswd"}, | |
| {"hello/world\\test", 0, "helloworldtest"}, | |
| {"normal_file", 0, "normal_file"}, | |
| {"", 0, "attachment-0"}, | |
| {" ", 0, "attachment-0"}, | |
| {"...", 1, "attachment-1"}, | |
| {"My Photo", 0, "My-Photo"}, | |
| {"file name with spaces.png", 0, "file-name-with-spaces"}, | |
| {"UPPER_CASE", 0, "UPPER_CASE"}, | |
| {"special!@#chars", 0, "specialchars"}, | |
| } | |
| for _, tt := range tests { | |
| t.Run(tt.name, func(t *testing.T) { | |
| got := SanitizeFilename(tt.name, tt.index) | |
| if got != tt.expected { | |
| t.Errorf("SanitizeFilename(%q, %d) = %q, want %q", tt.name, tt.index, got, tt.expected) | |
| } | |
| }) | |
| } | |
| } | |