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

Function TestCheckID

caddytest/caddytest_test.go:131–244  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

129}
130
131func TestCheckID(t *testing.T) {
132 tester := NewTester(t)
133 tester.InitServer(`{
134 "admin": {
135 "listen": "localhost:2999"
136 },
137 "apps": {
138 "http": {
139 "http_port": 9080,
140 "servers": {
141 "s_server": {
142 "@id": "s_server",
143 "listen": [
144 ":9080"
145 ],
146 "routes": [
147 {
148 "handle": [
149 {
150 "handler": "static_response",
151 "body": "Hello"
152 }
153 ]
154 }
155 ]
156 }
157 }
158 }
159 }
160 }
161 `, "json")
162 headers := []string{"Content-Type:application/json"}
163 sServer1 := []byte(`{"@id":"s_server","listen":[":9080"],"routes":[{"@id":"route1","handle":[{"handler":"static_response","body":"Hello 2"}]}]}`)
164
165 // PUT to an existing ID should fail with a 409 conflict
166 tester.AssertPutResponseBody(
167 "http://localhost:2999/id/s_server",
168 headers,
169 bytes.NewBuffer(sServer1),
170 409,
171 `{"error":"[/config/apps/http/servers/s_server] key already exists: s_server"}`+"\n")
172
173 // POST replaces the object fully
174 tester.AssertPostResponseBody(
175 "http://localhost:2999/id/s_server",
176 headers,
177 bytes.NewBuffer(sServer1),
178 200,
179 "")
180
181 // Verify the server is running the new route
182 tester.AssertGetResponse(
183 "http://localhost:9080/",
184 200,
185 "Hello 2")
186
187 // Update the existing route to ensure IDs are handled correctly when replaced
188 tester.AssertPostResponseBody(

Callers

nothing calls this directly

Calls 6

InitServerMethod · 0.95
AssertPutResponseBodyMethod · 0.95
AssertGetResponseMethod · 0.95
NewTesterFunction · 0.85

Tested by

no test coverage detected