mirror of
https://github.com/caddyserver/caddy.git
synced 2025-12-08 06:09:53 +00:00
testing: make it so caddytest launches an instance of caddy per server
This commit is contained in:
parent
c2ccf8690f
commit
b732a7999a
24 changed files with 1071 additions and 881 deletions
|
|
@ -2,6 +2,7 @@ package integration
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
|
|
@ -9,36 +10,36 @@ import (
|
|||
)
|
||||
|
||||
func TestBrowse(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
skip_install_trust
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
https_port 9443
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
https_port {$TESTING_CADDY_PORT_TWO}
|
||||
grace_period 1ns
|
||||
}
|
||||
http://localhost:9080 {
|
||||
http://localhost:{$TESTING_CADDY_PORT_ONE} {
|
||||
file_server browse
|
||||
}
|
||||
`, "caddyfile")
|
||||
|
||||
req, err := http.NewRequest(http.MethodGet, "http://localhost:9080/", nil)
|
||||
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("http://localhost:%d/", harness.Tester().PortOne()), nil)
|
||||
if err != nil {
|
||||
t.Fail()
|
||||
return
|
||||
}
|
||||
tester.AssertResponseCode(req, 200)
|
||||
harness.AssertResponseCode(req, 200)
|
||||
}
|
||||
|
||||
func TestRespondWithJSON(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`
|
||||
harness := caddytest.StartHarness(t)
|
||||
harness.LoadConfig(`
|
||||
{
|
||||
skip_install_trust
|
||||
admin localhost:2999
|
||||
http_port 9080
|
||||
https_port 9443
|
||||
admin {$TESTING_CADDY_ADMIN_BIND}
|
||||
http_port {$TESTING_CADDY_PORT_ONE}
|
||||
https_port {$TESTING_CADDY_PORT_TWO}
|
||||
grace_period 1ns
|
||||
}
|
||||
localhost {
|
||||
|
|
@ -46,7 +47,7 @@ func TestRespondWithJSON(t *testing.T) {
|
|||
}
|
||||
`, "caddyfile")
|
||||
|
||||
res, _ := tester.AssertPostResponseBody("https://localhost:9443/",
|
||||
res, _ := harness.AssertPostResponseBody(fmt.Sprintf("https://localhost:%d/", harness.Tester().PortTwo()),
|
||||
nil,
|
||||
bytes.NewBufferString(`{
|
||||
"greeting": "Hello, world!"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue