summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorKarthic Rao <[email protected]>2015-07-11 00:44:31 +0530
committerKarthic Rao <[email protected]>2015-07-11 00:44:31 +0530
commit2b7ec1b0235c8faac26b5d1dc2ac5c6dd07e4492 (patch)
tree18fee6d3b99630ddaeb48ccb3e4476ff177b586c
parentd3c229375c54376814cff35df54b57d327a543e7 (diff)
downloadcaddy-2b7ec1b0235c8faac26b5d1dc2ac5c6dd07e4492.tar.gz
caddy-2b7ec1b0235c8faac26b5d1dc2ac5c6dd07e4492.zip
Complete test coverage for config/setup/markdown.go
-rw-r--r--config/setup/markdown_test.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/config/setup/markdown_test.go b/config/setup/markdown_test.go
index bbfb69131..c84a118dd 100644
--- a/config/setup/markdown_test.go
+++ b/config/setup/markdown_test.go
@@ -1,6 +1,7 @@
package setup
import (
+ "fmt"
"github.com/mholt/caddy/middleware/markdown"
"testing"
)
@@ -29,5 +30,59 @@ func TestMarkdown(t *testing.T) {
if myHandler.Configs[0].PathScope != "/blog" {
t.Errorf("Expected /blog as the Path Scope")
}
+ if fmt.Sprint(myHandler.Configs[0].Extensions) != fmt.Sprint([]string{".md"}) {
+ t.Errorf("Expected .md as the Default Extension")
+ }
+
+}
+func TestMarkdownParse(t *testing.T) {
+ tests := []struct {
+ inputMarkdownConfig string
+ shouldErr bool
+ expectedMarkdownConfig []markdown.Config
+ }{
+
+ {`markdown /blog {
+ ext .md .txt
+ css /resources/css/blog.css
+ js /resources/js/blog.js
+}`, false, []markdown.Config{{
+ PathScope: "/blog",
+ Extensions: []string{".md", ".txt"},
+ Styles: []string{"/resources/css/blog.css"},
+ Scripts: []string{"/resources/js/blog.js"},
+ }}},
+ }
+ for i, test := range tests {
+ c := NewTestController(test.inputMarkdownConfig)
+ actualMarkdownConfigs, err := markdownParse(c)
+
+ if err == nil && test.shouldErr {
+ t.Errorf("Test %d didn't error, but it should have", i)
+ } else if err != nil && !test.shouldErr {
+ t.Errorf("Test %d errored, but it shouldn't have; got '%v'", i, err)
+ }
+ if len(actualMarkdownConfigs) != len(test.expectedMarkdownConfig) {
+ t.Fatalf("Test %d expected %d no of WebSocket configs, but got %d ",
+ i, len(test.expectedMarkdownConfig), len(actualMarkdownConfigs))
+ }
+ for j, actualMarkdownConfig := range actualMarkdownConfigs {
+
+ if actualMarkdownConfig.PathScope != test.expectedMarkdownConfig[j].PathScope {
+ t.Errorf("Test %d expected %dth Markdown PathScope to be %s , but got %s",
+ i, j, test.expectedMarkdownConfig[j].PathScope, actualMarkdownConfig.PathScope)
+ }
+
+ if fmt.Sprint(actualMarkdownConfig.Styles) != fmt.Sprint(test.expectedMarkdownConfig[j].Styles) {
+ t.Errorf("Test %d expected %dth Markdown Config Styles to be %s , but got %s",
+ i, j, fmt.Sprint(test.expectedMarkdownConfig[j].Styles), fmt.Sprint(actualMarkdownConfig.Styles))
+ }
+ if fmt.Sprint(actualMarkdownConfig.Scripts) != fmt.Sprint(test.expectedMarkdownConfig[j].Scripts) {
+ t.Errorf("Test %d expected %dth Markdown Config Scripts to be %s , but got %s",
+ i, j, fmt.Sprint(test.expectedMarkdownConfig[j].Scripts), fmt.Sprint(actualMarkdownConfig.Scripts))
+ }
+
+ }
+ }
}