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

@@ -33,6 +33,9 @@ type (
// CommandsConfig gathers all commands' configurations as defined
// by the user in the gotenberg.yml file.
CommandsConfig struct {
// Markdown is the command's configuration for converting
// an markdown file to PDF.
Markdown *CommandConfig
// HTML is the command's configuration for converting
// an HTML file to PDF.
HTML *CommandConfig
@@ -79,13 +82,20 @@ func NewAppConfig(configurationFilePath string) (*AppConfig, error) {
c.Logs.Formatter = formatter
c.CommandsConfig = &CommandsConfig{}
c.CommandsConfig.Markdown = &CommandConfig{}
c.CommandsConfig.HTML = &CommandConfig{}
c.CommandsConfig.Office = &CommandConfig{}
c.CommandsConfig.Merge = &CommandConfig{}
c.CommandsConfig.Markdown.Timeout = fileConfig.Commands.Markdown.Timeout
c.CommandsConfig.HTML.Timeout = fileConfig.Commands.HTML.Timeout
c.CommandsConfig.Office.Timeout = fileConfig.Commands.Office.Timeout
c.CommandsConfig.Merge.Timeout = fileConfig.Commands.Merge.Timeout
tmplMarkdown, err := getCommandTemplate(fileConfig.Commands.Markdown.Template, "Markdown")
if err != nil {
return nil, err
}
tmplHTML, err := getCommandTemplate(fileConfig.Commands.HTML.Template, "HTML")
if err != nil {
return nil, err
@@ -101,6 +111,7 @@ func NewAppConfig(configurationFilePath string) (*AppConfig, error) {
return nil, err
}
c.CommandsConfig.Markdown.Template = tmplMarkdown
c.CommandsConfig.HTML.Template = tmplHTML
c.CommandsConfig.Office.Template = tmplOffice
c.CommandsConfig.Merge.Template = tmplMerge
@@ -116,6 +127,10 @@ type fileConfig struct {
Format string `yaml:"format"`
} `yaml:"logs"`
Commands struct {
Markdown struct {
Timeout int `yaml:"timeout"`
Template string `yaml:"template"`
} `yaml:"markdown"`
HTML struct {
Timeout int
Template string

View File

@@ -29,25 +29,31 @@ func TestNewAppConfig(t *testing.T) {
t.Error("AppConfig should not have been instantiated!")
}
// case 5: uses a configuration file with a wrong HTML command template.
// case 5: uses a configuration file with a wrong markdown command template.
path, _ = filepath.Abs("../../_tests/configurations/wrong-markdown-command-template-gotenberg.yml")
if _, err := NewAppConfig(path); err == nil {
t.Error("AppConfig should not have been instantiated!")
}
// case 6: uses a configuration file with a wrong HTML command template.
path, _ = filepath.Abs("../../_tests/configurations/wrong-html-command-template-gotenberg.yml")
if _, err := NewAppConfig(path); err == nil {
t.Error("AppConfig should not have been instantiated!")
}
// case 6: uses a configuration file with a wrong Office command template.
// case 7: uses a configuration file with a wrong Office command template.
path, _ = filepath.Abs("../../_tests/configurations/wrong-office-command-template-gotenberg.yml")
if _, err := NewAppConfig(path); err == nil {
t.Error("AppConfig should not have been instantiated!")
}
// case 7: uses a configuration file with a wrong merge command template.
// case 8: uses a configuration file with a wrong merge command template.
path, _ = filepath.Abs("../../_tests/configurations/wrong-merge-command-template-gotenberg.yml")
if _, err := NewAppConfig(path); err == nil {
t.Error("AppConfig should not have been instantiated!")
}
// case 8: uses a correct configuration file.
// case 9: uses a correct configuration file.
path, _ = filepath.Abs("../../_tests/configurations/gotenberg.yml")
if _, err := NewAppConfig(path); err != nil {
t.Error("AppConfig should have been instantiated!")