add codes

This commit is contained in:
2025-11-24 15:20:05 +07:00
parent 4fcd71ca05
commit 2c96165a20
3 changed files with 83 additions and 8 deletions

View File

@@ -185,6 +185,37 @@ func TestVMLifecycleStartStop(t *testing.T) {
}
}
func TestCTLifecycleStartStop(t *testing.T) {
tmpDir := t.TempDir()
store := state.NewStore(filepath.Join(tmpDir, "vm"), filepath.Join(tmpDir, "ct"))
cfg := config.Config{
StoragePools: []config.StoragePool{{Name: "local"}},
Bridges: []config.Bridge{{Name: "vmbr0"}},
}
t.Setenv("JAGACLOUD_SKIP_BRIDGE_CHECK", "1")
svc := Services{
Tasks: tasks.NewRegistry(),
Libvirt: &fakeLibvirt{},
LXC: &fakeLXC{},
Podman: &fakePodman{},
Store: store,
}
go svc.Tasks.StartWorker(testCtx(t))
r := chi.NewRouter()
RegisterRoutes(r, cfg, svc)
_ = store.SaveCT(lxc.Spec{ID: "ct-run", Name: "ct-run", Template: "debian", RootfsPool: "local", RootfsSizeG: 1, Limits: lxc.Limits{CPU: 1, MemoryMB: 256}})
for _, action := range []string{"start", "stop"} {
req := httptest.NewRequest(http.MethodPost, "/api/v1/containers/ct-run/"+action, nil)
rec := httptest.NewRecorder()
r.ServeHTTP(rec, req)
if rec.Code != http.StatusAccepted {
t.Fatalf("expected 202 for %s, got %d", action, rec.Code)
}
}
}
func TestCTLifecycleDeleteCleansSpec(t *testing.T) {
tmpDir := t.TempDir()
store := state.NewStore(filepath.Join(tmpDir, "vm"), filepath.Join(tmpDir, "ct"))