adding markdown conversion to PDF + fixing some issue in CI process

This commit is contained in:
Julien Neuhart
2018-04-10 16:56:30 +02:00
parent 563733f496
commit e29ab4760a
21 changed files with 114 additions and 19 deletions

View File

@@ -3,6 +3,7 @@ package process
import (
"bytes"
"fmt"
"os/exec"
"text/template"
"time"
@@ -45,6 +46,10 @@ func Unconv(workingDir string, file *gfile.File) (string, error) {
)
switch file.Type {
case gfile.MarkdownType:
cmdTemplate = commandsConfig.Markdown.Template
cmdTimeout = commandsConfig.Markdown.Timeout
break
case gfile.HTMLType:
cmdTemplate = commandsConfig.HTML.Template
cmdTimeout = commandsConfig.HTML.Timeout
@@ -99,12 +104,13 @@ func Merge(workingDir string, filesPaths []string) (string, error) {
return cmdData.ResultFilePath, nil
}
type commandTimeoutError struct{}
const commandTimeoutErrorMessage = "The command has reached timeout"
type commandTimeoutError struct {
command string
timeout int
}
func (e *commandTimeoutError) Error() string {
return commandTimeoutErrorMessage
return fmt.Sprintf("The command '%s' has reached the %d second(s) timeout", e.command, e.timeout)
}
// run runs the given command. If timeout is reached or
@@ -126,7 +132,10 @@ func run(command string, timeout int) error {
if err := cmd.Process.Kill(); err != nil {
return err
}
return &commandTimeoutError{}
return &commandTimeoutError{
command: command,
timeout: timeout,
}
case err := <-done:
if err != nil {
return err

View File

@@ -120,8 +120,14 @@ func TestImpossibleConversionError(t *testing.T) {
}
func TestCommandTimeoutError(t *testing.T) {
err := &commandTimeoutError{}
if err.Error() != commandTimeoutErrorMessage {
t.Errorf("Error returned a wrong message: got %s want %s", err.Error(), commandTimeoutErrorMessage)
err := &commandTimeoutError{
command: "echo hello",
timeout: 30,
}
expected := fmt.Sprintf("The command '%s' has reached the %d second(s) timeout", err.command, err.timeout)
if err.Error() != expected {
t.Errorf("Error returned a wrong message: got %s want %s", err.Error(), expected)
}
}