Commit d96bd526 authored by Matt Holt's avatar Matt Holt

Merge pull request #235 from Karthic-Hackintosh/master

middleware: Complete test coverage for replacer 
parents f8e2cc80 ed4148f2
......@@ -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)
......
......@@ -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")
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment