diff --git a/config/setup/fastcgi_test.go b/config/setup/fastcgi_test.go index f32f84d3..661b92e5 100644 --- a/config/setup/fastcgi_test.go +++ b/config/setup/fastcgi_test.go @@ -51,6 +51,16 @@ func TestFastcgiParse(t *testing.T) { SplitPath: ".php", IndexFiles: []string{"index.php"}, }}}, + {`fastcgi / 127.0.0.1:9001 { + split .html + }`, + false, []fastcgi.Rule{{ + Path: "/", + Address: "127.0.0.1:9001", + Ext: "", + SplitPath: ".html", + IndexFiles: []string{}, + }}}, } for i, test := range tests { c := NewTestController(test.inputFastcgiConfig) diff --git a/middleware/browse/browse_test.go b/middleware/browse/browse_test.go index 9f91f34e..05ccff14 100644 --- a/middleware/browse/browse_test.go +++ b/middleware/browse/browse_test.go @@ -1,7 +1,7 @@ package browse import ( - "encoding/json" + "encoding/json" "github.com/mholt/caddy/middleware" "net/http" "net/http/httptest" diff --git a/middleware/replacer_test.go b/middleware/replacer_test.go index ad8a9489..7986a735 100644 --- a/middleware/replacer_test.go +++ b/middleware/replacer_test.go @@ -22,6 +22,7 @@ func TestNewReplacer(t *testing.T) { switch v := replaceValues.(type) { case replacer: + if v.replacements["{host}"] != "caddyserver.com" { t.Errorf("Expected host to be caddyserver.com") } @@ -36,3 +37,35 @@ func TestNewReplacer(t *testing.T) { t.Fatalf("Return Value from New Replacer expected pass type assertion into a replacer type \n") } } + +func TestReplace(t *testing.T) { + w := httptest.NewRecorder() + recordRequest := NewResponseRecorder(w) + userJson := `{"username": "dennis"}` + + reader := strings.NewReader(userJson) //Convert string to reader + + request, err := http.NewRequest("POST", "http://caddyserver.com", reader) //Create request with JSON body + if err != nil { + t.Fatalf("Request Formation Failed \n") + } + replaceValues := NewReplacer(request, recordRequest, "") + + switch v := replaceValues.(type) { + case replacer: + + if v.Replace("This host is {host}") != "This host is caddyserver.com" { + t.Errorf("Expected host replacement failed") + } + if v.Replace("This request method is {method}") != "This request method is POST" { + t.Errorf("Expected method replacement failed") + } + if v.Replace("The response status is {status}") != "The response status is 200" { + t.Errorf("Expected status replacement failed") + } + + default: + t.Fatalf("Return Value from New Replacer expected pass type assertion into a replacer type \n") + } + +}