2024-05-13 20:38:18 +03:00
package integration
import (
2024-06-19 07:45:54 +03:00
"fmt"
2024-05-13 20:38:18 +03:00
"testing"
"github.com/caddyserver/caddy/v2/caddytest"
)
func TestIntercept ( t * testing . T ) {
2024-06-19 07:45:54 +03:00
harness := caddytest . StartHarness ( t )
harness . LoadConfig ( ` {
2024-05-13 20:38:18 +03:00
skip_install_trust
2024-06-19 07:45:54 +03:00
admin { $ TESTING_CADDY_ADMIN_BIND }
http_port { $ TESTING_CADDY_PORT_ONE }
https_port { $ TESTING_CADDY_PORT_TWO }
2024-05-13 20:38:18 +03:00
grace_period 1 ns
}
2024-06-19 07:45:54 +03:00
localhost : { $ TESTING_CADDY_PORT_ONE } {
2024-05-13 20:38:18 +03:00
respond / intercept "I'm a teapot" 408
respond / no - intercept "I'm not a teapot"
intercept {
@ teapot status 408
handle_response @ teapot {
respond / intercept "I'm a combined coffee/tea pot that is temporarily out of coffee" 503
}
2024-06-19 07:45:54 +03:00
}
2024-05-13 20:38:18 +03:00
}
` , "caddyfile" )
2024-06-19 07:45:54 +03:00
harness . AssertGetResponse ( fmt . Sprintf ( "http://localhost:%d/intercept" , harness . Tester ( ) . PortOne ( ) ) , 503 , "I'm a combined coffee/tea pot that is temporarily out of coffee" )
harness . AssertGetResponse ( fmt . Sprintf ( "http://localhost:%d/no-intercept" , harness . Tester ( ) . PortOne ( ) ) , 200 , "I'm not a teapot" )
2024-05-13 20:38:18 +03:00
}