feat: add one pull plug and play feature

This commit is contained in:
2026-05-18 11:28:38 +02:00
parent ad64766cd6
commit fc498379f6
11 changed files with 290 additions and 42 deletions

View File

@ -488,6 +488,77 @@ func TestListContainers_WithData(t *testing.T) {
}
}
// ── DeleteAgent ───────────────────────────────────────────────────────────────
func TestDeleteAgent_Success(t *testing.T) {
h, s, reg, _ := newTestHandler(t)
_ = s.CreateAgentToken("a1", "t1", "host1")
reg.Register("a1", "host1", "", "ip", "arch", "os")
router := chi.NewRouter()
router.Delete("/api/v1/agents/{agentID}", h.DeleteAgent)
req, _ := http.NewRequest(http.MethodDelete, "/api/v1/agents/a1", nil)
w := httptest.NewRecorder()
router.ServeHTTP(w, req)
if w.Code != http.StatusNoContent {
t.Fatalf("expected 204, got %d — body: %s", w.Code, w.Body.String())
}
// Agent must be gone from store
_, err := s.GetAgent("a1")
if err == nil {
t.Error("expected store error after deletion, got nil")
}
// Agent must be gone from registry
_, ok := reg.Get("a1")
if ok {
t.Error("expected agent to be deregistered from registry")
}
}
func TestDeleteAgent_NotInRegistry(t *testing.T) {
h, s, _, _ := newTestHandler(t)
_ = s.CreateAgentToken("a1", "t1", "host1")
// Agent not registered in registry (offline agent)
router := chi.NewRouter()
router.Delete("/api/v1/agents/{agentID}", h.DeleteAgent)
req, _ := http.NewRequest(http.MethodDelete, "/api/v1/agents/a1", nil)
w := httptest.NewRecorder()
router.ServeHTTP(w, req)
if w.Code != http.StatusNoContent {
t.Fatalf("expected 204 even when not in registry, got %d — body: %s", w.Code, w.Body.String())
}
_, err := s.GetAgent("a1")
if err == nil {
t.Error("expected store error after deletion, got nil")
}
}
func TestDeleteAgent_NonExistent(t *testing.T) {
h, _, _, _ := newTestHandler(t)
router := chi.NewRouter()
router.Delete("/api/v1/agents/{agentID}", h.DeleteAgent)
req, _ := http.NewRequest(http.MethodDelete, "/api/v1/agents/ghost", nil)
w := httptest.NewRecorder()
router.ServeHTTP(w, req)
// DELETE on a non-existent ID is still 204 (idempotent)
if w.Code != http.StatusNoContent {
t.Fatalf("expected 204 for non-existent agent, got %d — body: %s", w.Code, w.Body.String())
}
}
// ── ContainerAction ───────────────────────────────────────────────────────────
func TestContainerAction_AgentNotConnected(t *testing.T) {