mirror of
https://github.com/usememos/memos.git
synced 2024-12-21 10:11:42 +03:00
84 lines
1.5 KiB
Go
84 lines
1.5 KiB
Go
|
package telegram
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
|
"github.com/stretchr/testify/require"
|
||
|
)
|
||
|
|
||
|
func TestGetMimeType(t *testing.T) {
|
||
|
tests := []struct {
|
||
|
mimeType string
|
||
|
fileName string
|
||
|
expected string
|
||
|
}{
|
||
|
{
|
||
|
fileName: "file.jpg",
|
||
|
mimeType: "image/jpeg",
|
||
|
expected: "image/jpeg",
|
||
|
},
|
||
|
{
|
||
|
fileName: "file.png",
|
||
|
mimeType: "image/png",
|
||
|
expected: "image/png",
|
||
|
},
|
||
|
{
|
||
|
fileName: "file.pdf",
|
||
|
mimeType: "application/pdf",
|
||
|
expected: "application/pdf",
|
||
|
},
|
||
|
{
|
||
|
fileName: "file.php",
|
||
|
mimeType: "application/x-php",
|
||
|
expected: "application/x-php",
|
||
|
},
|
||
|
{
|
||
|
fileName: "file.xlsx",
|
||
|
mimeType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||
|
expected: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||
|
},
|
||
|
{
|
||
|
fileName: "file.oga",
|
||
|
mimeType: "audio/ogg",
|
||
|
expected: "audio/ogg",
|
||
|
},
|
||
|
{
|
||
|
fileName: "file.jpg",
|
||
|
expected: "image/jpeg",
|
||
|
},
|
||
|
{
|
||
|
fileName: "file.png",
|
||
|
expected: "image/png",
|
||
|
},
|
||
|
{
|
||
|
fileName: "file.mp4",
|
||
|
expected: "video/mp4",
|
||
|
},
|
||
|
{
|
||
|
fileName: "file.pdf",
|
||
|
expected: "application/octet-stream",
|
||
|
},
|
||
|
{
|
||
|
fileName: "file.oga",
|
||
|
expected: "audio/ogg",
|
||
|
},
|
||
|
{
|
||
|
fileName: "file.xlsx",
|
||
|
expected: "application/octet-stream",
|
||
|
},
|
||
|
{
|
||
|
fileName: "file.txt",
|
||
|
expected: "application/octet-stream",
|
||
|
},
|
||
|
}
|
||
|
|
||
|
for _, test := range tests {
|
||
|
attachment := Attachment{
|
||
|
FileName: test.fileName,
|
||
|
MimeType: test.mimeType,
|
||
|
}
|
||
|
|
||
|
require.Equal(t, test.expected, attachment.GetMimeType())
|
||
|
}
|
||
|
}
|