mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
Merge pull request #225 from Karthic-Hackintosh/master
middleware: Initial test for replacer
This commit is contained in:
commit
bfc61824b9
1 changed files with 38 additions and 0 deletions
38
middleware/replacer_test.go
Normal file
38
middleware/replacer_test.go
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
package middleware
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNewReplacer(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.replacements["{host}"] != "caddyserver.com" {
|
||||||
|
t.Errorf("Expected host to be caddyserver.com")
|
||||||
|
}
|
||||||
|
if v.replacements["{method}"] != "POST" {
|
||||||
|
t.Errorf("Expected request method to be POST")
|
||||||
|
}
|
||||||
|
if v.replacements["{status}"] != "200" {
|
||||||
|
t.Errorf("Expected status to be 200")
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
t.Fatalf("Return Value from New Replacer expected pass type assertion into a replacer type \n")
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue