attachment_test.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package telegram
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/require"
  5. )
  6. func TestGetMimeType(t *testing.T) {
  7. tests := []struct {
  8. mimeType string
  9. fileName string
  10. expected string
  11. }{
  12. {
  13. fileName: "file.jpg",
  14. mimeType: "image/jpeg",
  15. expected: "image/jpeg",
  16. },
  17. {
  18. fileName: "file.png",
  19. mimeType: "image/png",
  20. expected: "image/png",
  21. },
  22. {
  23. fileName: "file.pdf",
  24. mimeType: "application/pdf",
  25. expected: "application/pdf",
  26. },
  27. {
  28. fileName: "file.php",
  29. mimeType: "application/x-php",
  30. expected: "application/x-php",
  31. },
  32. {
  33. fileName: "file.xlsx",
  34. mimeType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
  35. expected: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
  36. },
  37. {
  38. fileName: "file.oga",
  39. mimeType: "audio/ogg",
  40. expected: "audio/ogg",
  41. },
  42. {
  43. fileName: "file.jpg",
  44. expected: "image/jpeg",
  45. },
  46. {
  47. fileName: "file.png",
  48. expected: "image/png",
  49. },
  50. {
  51. fileName: "file.mp4",
  52. expected: "video/mp4",
  53. },
  54. {
  55. fileName: "file.pdf",
  56. expected: "application/octet-stream",
  57. },
  58. {
  59. fileName: "file.oga",
  60. expected: "audio/ogg",
  61. },
  62. {
  63. fileName: "file.xlsx",
  64. expected: "application/octet-stream",
  65. },
  66. {
  67. fileName: "file.txt",
  68. expected: "application/octet-stream",
  69. },
  70. }
  71. for _, test := range tests {
  72. attachment := Attachment{
  73. FileName: test.fileName,
  74. MimeType: test.mimeType,
  75. }
  76. require.Equal(t, test.expected, attachment.GetMimeType())
  77. }
  78. }