MCPcopy
hub / github.com/caddyserver/caddy / TestDialWithPlaceholderUnix

Function TestDialWithPlaceholderUnix

caddytest/integration/reverseproxy_test.go:59–139  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

57}
58
59func TestDialWithPlaceholderUnix(t *testing.T) {
60 if runtime.GOOS == "windows" {
61 t.SkipNow()
62 }
63
64 f, err := os.CreateTemp("", "*.sock")
65 if err != nil {
66 t.Errorf("failed to create TempFile: %s", err)
67 return
68 }
69 // a hack to get a file name within a valid path to use as socket
70 socketName := f.Name()
71 os.Remove(f.Name())
72
73 server := http.Server{
74 Handler: http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
75 w.Write([]byte("Hello, World!"))
76 }),
77 }
78
79 unixListener, err := net.Listen("unix", socketName)
80 if err != nil {
81 t.Errorf("failed to listen on the socket: %s", err)
82 return
83 }
84 go server.Serve(unixListener)
85 t.Cleanup(func() {
86 server.Close()
87 })
88 runtime.Gosched() // Allow other goroutines to run
89
90 tester := caddytest.NewTester(t)
91 tester.InitServer(`
92 {
93 "admin": {
94 "listen": "localhost:2999"
95 },
96 "apps": {
97 "pki": {
98 "certificate_authorities": {
99 "local": {
100 "install_trust": false
101 }
102 }
103 },
104 "http": {
105 "grace_period": 1,
106 "servers": {
107 "srv0": {
108 "listen": [
109 ":18080"
110 ],
111 "routes": [
112 {
113 "handle": [
114 {
115 "handler": "reverse_proxy",
116 "upstreams": [

Callers

nothing calls this directly

Calls 9

InitServerMethod · 0.95
AssertResponseMethod · 0.95
NewTesterFunction · 0.92
ListenMethod · 0.80
CleanupMethod · 0.65
NameMethod · 0.45
WriteMethod · 0.45
CloseMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected