mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-03 17:43:49 +03:00
Merge pull request #235 from Karthic-Hackintosh/master
middleware: Complete test coverage for replacer
This commit is contained in:
commit
d96bd5269a
3 changed files with 44 additions and 1 deletions
|
@ -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)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package browse
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"encoding/json"
|
||||
"github.com/mholt/caddy/middleware"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue