Skip to content

Commit

Permalink
Add unit test for PDF MIME Type
Browse files Browse the repository at this point in the history
  • Loading branch information
Vytek committed Sep 5, 2023
1 parent 39c60c2 commit 6827089
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ List of formats read:
| RTF | X | text/rtf |
| ODT | X | application/vnd.oasis.opendocument.text |
| DOCX | X | application/vnd.openxmlformats-officedocument.wordprocessingml.document |
| PDF | X | application/pdf "
3 changes: 2 additions & 1 deletion opencrucible.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,5 @@ func readPdf(path string) (string, error) {
newBytes := []byte(" ")
replacedBytes := bytes.Replace(buf.Bytes(), oldBytes, newBytes, -1)
return strings.Trim(string(replacedBytes), " "), nil
}
}

16 changes: 16 additions & 0 deletions opencrucible_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,19 @@ func TestPDFFileParser(t *testing.T) {
t.Errorf("got %q, wanted %q", got, want)
}
}

func TestPDFDetect(t *testing.T) {
pdf, err := os.ReadFile(filepath.Join("test_file","test_file_pdf_1000.pdf"))
if err != nil {
t.Errorf("error loading file \n %s", err)
}
got, _, err := DetectFileTypeMIME(pdf)
if err != nil {
t.Errorf("unable to detect file \n %s", err)
}
want := "application/pdf"
t.Logf("Parsed: %s", got)
if got != want {
t.Errorf("got %q, wanted %q", got, want)
}
}
Binary file added test_file/test_file_pdf_1000.pdf
Binary file not shown.

0 comments on commit 6827089

Please sign in to comment.