caddy_test.go 956 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package caddy_test
  2. import (
  3. "fmt"
  4. "net/http"
  5. "sync"
  6. "testing"
  7. "github.com/caddyserver/caddy/v2/caddytest"
  8. )
  9. func TestPHP(t *testing.T) {
  10. var wg sync.WaitGroup
  11. caddytest.Default.AdminPort = 2019
  12. tester := caddytest.NewTester(t)
  13. tester.InitServer(`
  14. {
  15. admin localhost:2999
  16. http_port 9080
  17. https_port 9443
  18. }
  19. localhost:9080 {
  20. respond "Hello"
  21. }
  22. `, "caddyfile")
  23. wg.Add(100)
  24. for i := 0; i < 100; i++ {
  25. go func(i int) {
  26. tester.AssertGetResponse(fmt.Sprintf("http://localhost:9080?i=%d", i), http.StatusOK, fmt.Sprintf("I am by birth a Genevese (%d)", i))
  27. wg.Done()
  28. }(i)
  29. }
  30. wg.Wait()
  31. }
  32. func TestAutoHTTPtoHTTPSRedirectsImplicitPort(t *testing.T) {
  33. tester := caddytest.NewTester(t)
  34. tester.InitServer(`
  35. {
  36. http_port 9080
  37. https_port 9443
  38. }
  39. localhost
  40. respond "Yahaha! You found me!"
  41. `, "caddyfile")
  42. tester.AssertRedirect("http://localhost:9080/", "https://localhost/", http.StatusPermanentRedirect)
  43. }