mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-17 12:42:16 +01:00
more tests + small refactoring (no more App struct)
This commit is contained in:
52
app/converter/file/file_test.go
Normal file
52
app/converter/file/file_test.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package file
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewFile(t *testing.T) {
|
||||
workingDir := "test"
|
||||
os.Mkdir(workingDir, 0666)
|
||||
|
||||
// case 1: uses an empty reader.
|
||||
if _, err := NewFile(workingDir, new(bytes.Buffer)); err == nil {
|
||||
t.Error("File should not have been instantiated!")
|
||||
}
|
||||
|
||||
// case 2: uses a reader from a wrong file type.
|
||||
path, _ := filepath.Abs("../../../_tests/configurations/gotenberg.yml")
|
||||
r, _ := os.Open(path)
|
||||
defer r.Close()
|
||||
if _, err := NewFile(workingDir, r); err == nil {
|
||||
t.Error("File should not have been instantiated!")
|
||||
}
|
||||
|
||||
// case 3: uses a reader from a correct file type.
|
||||
path, _ = filepath.Abs("../../../_tests/file.pdf")
|
||||
r, _ = os.Open(path)
|
||||
defer r.Close()
|
||||
if _, err := NewFile(workingDir, r); err != nil {
|
||||
t.Error("File should have been instantiated!")
|
||||
}
|
||||
|
||||
os.RemoveAll(workingDir)
|
||||
}
|
||||
|
||||
func TestReworkFilePath(t *testing.T) {
|
||||
workingDir := "test"
|
||||
os.Mkdir(workingDir, 0666)
|
||||
|
||||
f := &File{
|
||||
Path: MakeFilePath(workingDir),
|
||||
Type: 999,
|
||||
}
|
||||
|
||||
if _, err := reworkFilePath(workingDir, f); err == nil {
|
||||
t.Error("It should not have been able to found the file extension!")
|
||||
}
|
||||
|
||||
os.RemoveAll(workingDir)
|
||||
}
|
||||
Reference in New Issue
Block a user