Files
query-orchestration/internal/server/api/batch_worker_extension_test.go
T
Jay Brown b71a28d3c0 Merged in feature/support-more-types (pull request #219)
support new types for import

* tests pass

* missing file

* bug fixes
2026-03-31 17:40:42 +00:00

96 lines
2.1 KiB
Go

package api
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestIsAcceptedExtension_AllSupported(t *testing.T) {
supported := []string{
".pdf", ".tiff", ".tif", ".jpeg", ".jpg",
".png", ".bmp", ".docx", ".xlsx",
".pptx", ".txt", ".eml",
}
for _, ext := range supported {
t.Run(ext, func(t *testing.T) {
assert.True(t, isAcceptedExtension("document"+ext),
"expected %s to be accepted", ext)
})
}
}
func TestIsAcceptedExtension_CaseInsensitive(t *testing.T) {
cases := []struct {
filename string
}{
{"report.PDF"},
{"image.Png"},
{"file.DOCX"},
{"scan.TiFf"},
{"mail.EML"},
}
for _, tc := range cases {
t.Run(tc.filename, func(t *testing.T) {
assert.True(t, isAcceptedExtension(tc.filename),
"expected %s to be accepted (case insensitive)", tc.filename)
})
}
}
func TestIsAcceptedExtension_Unsupported(t *testing.T) {
unsupported := []struct {
filename string
}{
{"virus.exe"},
{"library.dll"},
{"outlook.msg"},
{"legacy.doc"},
{"old.xls"},
{"slides.ppt"},
{"archive.zip"},
{"data.csv"},
{"page.html"},
{"macros.docm"},
{"macros.xlsm"},
{"macros.pptm"},
}
for _, tc := range unsupported {
t.Run(tc.filename, func(t *testing.T) {
assert.False(t, isAcceptedExtension(tc.filename),
"expected %s to be rejected", tc.filename)
})
}
}
func TestIsAcceptedExtension_NoExtension(t *testing.T) {
assert.False(t, isAcceptedExtension("README"),
"file with no extension should be rejected")
assert.False(t, isAcceptedExtension("Makefile"),
"file with no extension should be rejected")
}
func TestIsAcceptedExtension_WithPath(t *testing.T) {
cases := []struct {
name string
filename string
want bool
}{
{"nested pdf", "folder/document.pdf", true},
{"deep path docx", "a/b/c/report.docx", true},
{"nested unsupported", "folder/file.exe", false},
{"path with spaces", "my folder/scan.png", true},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
got := isAcceptedExtension(tc.filename)
assert.Equal(t, tc.want, got,
"isAcceptedExtension(%q) = %v, want %v", tc.filename, got, tc.want)
})
}
}