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

Function adminHandlerFixture

modules/caddyhttp/reverseproxy/admin_test.go:30–56  ·  view source on GitHub ↗

adminHandlerFixture sets up the global host state for an admin endpoint test and returns a cleanup function that must be deferred by the caller. staticAddrs are inserted into the UsagePool (as a static upstream would be). dynamicAddrs are inserted into the dynamicHosts map (as a dynamic upstream wo

(t *testing.T, staticAddrs, dynamicAddrs []string)

Source from the content-addressed store, hash-verified

28// staticAddrs are inserted into the UsagePool (as a static upstream would be).
29// dynamicAddrs are inserted into the dynamicHosts map (as a dynamic upstream would be).
30func adminHandlerFixture(t *testing.T, staticAddrs, dynamicAddrs []string) func() {
31 t.Helper()
32
33 for _, addr := range staticAddrs {
34 u := &Upstream{Dial: addr}
35 u.fillHost()
36 }
37
38 dynamicHostsMu.Lock()
39 for _, addr := range dynamicAddrs {
40 dynamicHosts[addr] = dynamicHostEntry{host: new(Host), lastSeen: time.Now()}
41 }
42 dynamicHostsMu.Unlock()
43
44 return func() {
45 // Remove static entries from the UsagePool.
46 for _, addr := range staticAddrs {
47 _, _ = hosts.Delete(addr)
48 }
49 // Remove dynamic entries.
50 dynamicHostsMu.Lock()
51 for _, addr := range dynamicAddrs {
52 delete(dynamicHosts, addr)
53 }
54 dynamicHostsMu.Unlock()
55 }
56}
57
58// callAdminUpstreams fires a GET against handleUpstreams and returns the
59// decoded response body.

Calls 2

fillHostMethod · 0.95
DeleteMethod · 0.45

Tested by

no test coverage detected