TestSystemHandlers 测试 System 相关的处理器
(t *testing.T)
| 228 | |
| 229 | // TestSystemHandlers 测试 System 相关的处理器 |
| 230 | func 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() |