summaryrefslogtreecommitdiff
path: root/caddytest/integration/caddyfile_test.go
diff options
context:
space:
mode:
authorMark Sargent <99003+sarge@users.noreply.github.com>2020-04-27 13:23:46 +1200
committerGitHub <noreply@github.com>2020-04-27 13:23:46 +1200
commit570d84f7d3642b85f96906ceab6402678177949e (patch)
treee16c2693b8ec69bb95163fc389f4939ecc9150dc /caddytest/integration/caddyfile_test.go
parenta6761153cbbf4547b9c0a76656d74f1401067205 (diff)
refactored caddytest helpers (#3285)
* refactored caddytest helpers * added cookie jar support. Added support for more http verbs
Diffstat (limited to 'caddytest/integration/caddyfile_test.go')
-rw-r--r--caddytest/integration/caddyfile_test.go45
1 files changed, 40 insertions, 5 deletions
diff --git a/caddytest/integration/caddyfile_test.go b/caddytest/integration/caddyfile_test.go
index dd3dcba..4e9bdd9 100644
--- a/caddytest/integration/caddyfile_test.go
+++ b/caddytest/integration/caddyfile_test.go
@@ -1,6 +1,8 @@
package integration
import (
+ "net/http"
+ "net/url"
"testing"
"github.com/caddyserver/caddy/v2/caddytest"
@@ -9,7 +11,8 @@ import (
func TestRespond(t *testing.T) {
// arrange
- caddytest.InitServer(t, `
+ tester := caddytest.NewTester(t)
+ tester.InitServer(`
{
http_port 9080
https_port 9443
@@ -23,13 +26,14 @@ func TestRespond(t *testing.T) {
`, "caddyfile")
// act and assert
- caddytest.AssertGetResponse(t, "http://localhost:9080/version", 200, "hello from localhost")
+ tester.AssertGetResponse("http://localhost:9080/version", 200, "hello from localhost")
}
func TestRedirect(t *testing.T) {
// arrange
- caddytest.InitServer(t, `
+ tester := caddytest.NewTester(t)
+ tester.InitServer(`
{
http_port 9080
https_port 9443
@@ -46,10 +50,10 @@ func TestRedirect(t *testing.T) {
`, "caddyfile")
// act and assert
- caddytest.AssertRedirect(t, "http://localhost:9080/", "http://localhost:9080/hello", 301)
+ tester.AssertRedirect("http://localhost:9080/", "http://localhost:9080/hello", 301)
// follow redirect
- caddytest.AssertGetResponse(t, "http://localhost:9080/", 200, "hello from localhost")
+ tester.AssertGetResponse("http://localhost:9080/", 200, "hello from localhost")
}
func TestDuplicateHosts(t *testing.T) {
@@ -66,3 +70,34 @@ func TestDuplicateHosts(t *testing.T) {
"caddyfile",
"duplicate site address not allowed")
}
+
+func TestReadCookie(t *testing.T) {
+
+ localhost, _ := url.Parse("http://localhost")
+ cookie := http.Cookie{
+ Name: "clientname",
+ Value: "caddytest",
+ }
+
+ // arrange
+ tester := caddytest.NewTester(t)
+ tester.Client.Jar.SetCookies(localhost, []*http.Cookie{&cookie})
+ tester.InitServer(`
+ {
+ http_port 9080
+ https_port 9443
+ }
+
+ localhost:9080 {
+ templates {
+ root testdata
+ }
+ file_server {
+ root testdata
+ }
+ }
+ `, "caddyfile")
+
+ // act and assert
+ tester.AssertGetResponse("http://localhost:9080/cookie.html", 200, "<h2>Cookie.ClientName caddytest</h2>")
+}