summaryrefslogtreecommitdiff
path: root/caddytest/integration
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2020-10-02 14:23:40 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2020-10-02 14:23:56 -0600
commit25d2b4bf2927bf69ddce582d33339ef7d13cb6bf (patch)
tree7741803a180bb85eefdb6861c1fd69e2b10b6a85 /caddytest/integration
parent023d702f30d0b7ccc039f2c96ca369def3acb41b (diff)
map: Reimplement; multiple outputs; optimize
Diffstat (limited to 'caddytest/integration')
-rw-r--r--caddytest/integration/map_test.go131
-rw-r--r--caddytest/integration/sni_test.go5
2 files changed, 64 insertions, 72 deletions
diff --git a/caddytest/integration/map_test.go b/caddytest/integration/map_test.go
index e31b95a..dc077ee 100644
--- a/caddytest/integration/map_test.go
+++ b/caddytest/integration/map_test.go
@@ -8,7 +8,6 @@ import (
)
func TestMap(t *testing.T) {
-
// arrange
tester := caddytest.NewTester(t)
tester.InitServer(`{
@@ -18,25 +17,24 @@ func TestMap(t *testing.T) {
localhost:9080 {
- map http.request.method dest-name {
+ map {http.request.method} {dest-1} {dest-2} {
default unknown
- G.T get-called
- POST post-called
+ ~G.T get-called
+ POST post-called foobar
}
respond /version 200 {
- body "hello from localhost {dest-name}"
+ body "hello from localhost {dest-1} {dest-2}"
}
}
`, "caddyfile")
// act and assert
- tester.AssertGetResponse("http://localhost:9080/version", 200, "hello from localhost get-called")
- tester.AssertPostResponseBody("http://localhost:9080/version", []string{}, bytes.NewBuffer([]byte{}), 200, "hello from localhost post-called")
+ tester.AssertGetResponse("http://localhost:9080/version", 200, "hello from localhost get-called ")
+ tester.AssertPostResponseBody("http://localhost:9080/version", []string{}, bytes.NewBuffer([]byte{}), 200, "hello from localhost post-called foobar")
}
func TestMapRespondWithDefault(t *testing.T) {
-
// arrange
tester := caddytest.NewTester(t)
tester.InitServer(`{
@@ -46,9 +44,9 @@ func TestMapRespondWithDefault(t *testing.T) {
localhost:9080 {
- map http.request.method dest-name {
+ map {http.request.method} {dest-name} {
default unknown
- GET get-called
+ GET get-called
}
respond /version 200 {
@@ -63,80 +61,75 @@ func TestMapRespondWithDefault(t *testing.T) {
}
func TestMapAsJson(t *testing.T) {
-
// arrange
tester := caddytest.NewTester(t)
- tester.InitServer(`{
+ tester.InitServer(`
+ {
"apps": {
"http": {
- "http_port": 9080,
- "https_port": 9443,
- "servers": {
- "srv0": {
- "listen": [
- ":9080"
- ],
- "routes": [
- {
- "handle": [
- {
- "handler": "subroute",
+ "http_port": 9080,
+ "https_port": 9443,
+ "servers": {
+ "srv0": {
+ "listen": [
+ ":9080"
+ ],
"routes": [
{
- "handle": [
- {
- "handler": "map",
- "source": "http.request.method",
- "destination": "dest-name",
- "default": "unknown",
- "items": [
+ "handle": [
{
- "expression": "GET",
- "value": "get-called"
- },
+ "handler": "subroute",
+ "routes": [
+ {
+ "handle": [
+ {
+ "handler": "map",
+ "source": "{http.request.method}",
+ "destinations": ["dest-name"],
+ "defaults": ["unknown"],
+ "mappings": [
+ {
+ "input": "GET",
+ "outputs": ["get-called"]
+ },
+ {
+ "input": "POST",
+ "outputs": ["post-called"]
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "handle": [
+ {
+ "body": "hello from localhost {dest-name}",
+ "handler": "static_response",
+ "status_code": 200
+ }
+ ],
+ "match": [
+ {
+ "path": ["/version"]
+ }
+ ]
+ }
+ ]
+ }
+ ],
+ "match": [
{
- "expression": "POST",
- "value": "post-called"
+ "host": ["localhost"]
}
- ]
- }
- ]
- },
- {
- "handle": [
- {
- "body": "hello from localhost {dest-name}",
- "handler": "static_response",
- "status_code": 200
- }
- ],
- "match": [
- {
- "path": [
- "/version"
- ]
- }
- ]
+ ],
+ "terminal": true
}
]
- }
- ],
- "match": [
- {
- "host": [
- "localhost"
- ]
- }
- ],
- "terminal": true
}
- ]
}
}
- }
- }
}
- `, "json")
+ }`, "json")
tester.AssertGetResponse("http://localhost:9080/version", 200, "hello from localhost get-called")
tester.AssertPostResponseBody("http://localhost:9080/version", []string{}, bytes.NewBuffer([]byte{}), 200, "hello from localhost post-called")
diff --git a/caddytest/integration/sni_test.go b/caddytest/integration/sni_test.go
index 46f7c83..813e9a0 100644
--- a/caddytest/integration/sni_test.go
+++ b/caddytest/integration/sni_test.go
@@ -99,7 +99,7 @@ func TestDefaultSNI(t *testing.T) {
// act and assert
// makes a request with no sni
- tester.AssertGetResponse("https://127.0.0.1:9443/version", 200, "hello from a")
+ tester.AssertGetResponse("https://127.0.0.1:9443/version", 200, "hello from a.caddy.localhost")
}
func TestDefaultSNIWithNamedHostAndExplicitIP(t *testing.T) {
@@ -204,7 +204,6 @@ func TestDefaultSNIWithNamedHostAndExplicitIP(t *testing.T) {
}
func TestDefaultSNIWithPortMappingOnly(t *testing.T) {
-
// arrange
tester := caddytest.NewTester(t)
tester.InitServer(`
@@ -273,7 +272,7 @@ func TestDefaultSNIWithPortMappingOnly(t *testing.T) {
// act and assert
// makes a request with no sni
- tester.AssertGetResponse("https://127.0.0.1:9443/version", 200, "hello from a")
+ tester.AssertGetResponse("https://127.0.0.1:9443/version", 200, "hello from a.caddy.localhost")
}
func TestHttpOnlyOnDomainWithSNI(t *testing.T) {