MCPcopy Create free account
hub / github.com/astercloud/aster / TestSystemHandlers

Function TestSystemHandlers

server/handlers_test.go:230–302  ·  view source on GitHub ↗

TestSystemHandlers 测试 System 相关的处理器

(t *testing.T)

Source from the content-addressed store, hash-verified

228
229// TestSystemHandlers 测试 System 相关的处理器
230func TestSystemHandlers(t *testing.T) {
231 srv, cleanup := setupTestServer(t)
232 defer cleanup()
233
234 t.Run("GetSystemInfo", func(t *testing.T) {
235 req := httptest.NewRequest(http.MethodGet, "/v1/system/info", nil)
236 w := httptest.NewRecorder()
237
238 srv.Router().ServeHTTP(w, req)
239
240 assert.Equal(t, http.StatusOK, w.Code)
241 assert.Contains(t, w.Body.String(), "version")
242 })
243
244 t.Run("GetSystemHealth", func(t *testing.T) {
245 req := httptest.NewRequest(http.MethodGet, "/v1/system/health", nil)
246 w := httptest.NewRecorder()
247
248 srv.Router().ServeHTTP(w, req)
249
250 assert.Equal(t, http.StatusOK, w.Code)
251 })
252
253 t.Run("GetSystemStats", func(t *testing.T) {
254 req := httptest.NewRequest(http.MethodGet, "/v1/system/stats", nil)
255 w := httptest.NewRecorder()
256
257 srv.Router().ServeHTTP(w, req)
258
259 assert.Equal(t, http.StatusOK, w.Code)
260 })
261
262 t.Run("ListConfig", func(t *testing.T) {
263 req := httptest.NewRequest(http.MethodGet, "/v1/system/config", nil)
264 w := httptest.NewRecorder()
265
266 srv.Router().ServeHTTP(w, req)
267
268 assert.Equal(t, http.StatusOK, w.Code)
269 })
270
271 t.Run("UpdateConfig", func(t *testing.T) {
272 body := `{
273 "value": "test_value"
274 }`
275
276 req := httptest.NewRequest(http.MethodPut, "/v1/system/config/test_key", strings.NewReader(body))
277 req.Header.Set("Content-Type", "application/json")
278 w := httptest.NewRecorder()
279
280 srv.Router().ServeHTTP(w, req)
281
282 assert.Equal(t, http.StatusOK, w.Code)
283 })
284
285 t.Run("GetConfig", func(t *testing.T) {
286 req := httptest.NewRequest(http.MethodGet, "/v1/system/config/test_key", nil)
287 w := httptest.NewRecorder()

Callers

nothing calls this directly

Calls 6

setupTestServerFunction · 0.85
SetMethod · 0.65
RunMethod · 0.45
ServeHTTPMethod · 0.45
RouterMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected