update_readiness_test.go 991 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // update_readiness_test.go — readiness en /api/update/status (issue #160).
  2. package httpapi_test
  3. import (
  4. "testing"
  5. )
  6. func TestUpdateStatusExposesReadiness(t *testing.T) {
  7. if !gitAvailable() {
  8. t.Skip("git no disponible")
  9. }
  10. root := t.TempDir()
  11. writeDeployScript(t, root)
  12. writeGitHead(t, root)
  13. ts := makeTestServerWithUpdater(t, root)
  14. cookie := adminCookie(t, ts)
  15. res := get(t, ts.URL, "/api/update/status", cookie)
  16. if res.StatusCode != 200 {
  17. t.Fatalf("status: got %d want 200", res.StatusCode)
  18. }
  19. body := readJSON(t, res)
  20. r, ok := body["readiness"].(map[string]any)
  21. if !ok {
  22. t.Fatalf("readiness ausente: %+v", body)
  23. }
  24. ready, _ := r["ready"].(bool)
  25. if !ready {
  26. t.Errorf("ready false: %+v", r)
  27. }
  28. for _, k := range []string{"disk", "git", "network", "concurrent"} {
  29. ck, ok := r[k].(map[string]any)
  30. if !ok {
  31. t.Errorf("check %s ausente: %+v", k, r)
  32. continue
  33. }
  34. okv, _ := ck["ok"].(bool)
  35. if !okv {
  36. t.Errorf("check %s = %+v, want ok", k, ck)
  37. }
  38. }
  39. }