2020-03-13 20:32:53 +03:00
|
|
|
package integration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/caddyserver/caddy/v2/caddytest"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRespond(t *testing.T) {
|
|
|
|
|
|
|
|
// arrange
|
|
|
|
caddytest.InitServer(t, `
|
|
|
|
{
|
|
|
|
http_port 9080
|
|
|
|
https_port 9443
|
|
|
|
}
|
|
|
|
|
|
|
|
localhost:9080 {
|
|
|
|
respond /version 200 {
|
2020-03-17 21:39:01 +03:00
|
|
|
body "hello from localhost"
|
2020-03-13 20:32:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`, "caddyfile")
|
|
|
|
|
|
|
|
// act and assert
|
2020-03-17 21:39:01 +03:00
|
|
|
caddytest.AssertGetResponse(t, "http://localhost:9080/version", 200, "hello from localhost")
|
2020-03-13 20:32:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRedirect(t *testing.T) {
|
|
|
|
|
|
|
|
// arrange
|
|
|
|
caddytest.InitServer(t, `
|
|
|
|
{
|
|
|
|
http_port 9080
|
|
|
|
https_port 9443
|
|
|
|
}
|
|
|
|
|
|
|
|
localhost:9080 {
|
|
|
|
|
|
|
|
redir / http://localhost:9080/hello 301
|
|
|
|
|
|
|
|
respond /hello 200 {
|
2020-03-17 21:39:01 +03:00
|
|
|
body "hello from localhost"
|
2020-03-13 20:32:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`, "caddyfile")
|
|
|
|
|
|
|
|
// act and assert
|
|
|
|
caddytest.AssertRedirect(t, "http://localhost:9080/", "http://localhost:9080/hello", 301)
|
|
|
|
|
|
|
|
// follow redirect
|
2020-03-17 21:39:01 +03:00
|
|
|
caddytest.AssertGetResponse(t, "http://localhost:9080/", 200, "hello from localhost")
|
2020-03-13 20:32:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDuplicateHosts(t *testing.T) {
|
|
|
|
|
|
|
|
// act and assert
|
|
|
|
caddytest.AssertLoadError(t,
|
|
|
|
`
|
|
|
|
localhost:9080 {
|
|
|
|
}
|
|
|
|
|
|
|
|
localhost:9080 {
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
"caddyfile",
|
|
|
|
"duplicate site address not allowed")
|
|
|
|
}
|