update_readiness_test.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // update_readiness_test.go — readiness en /api/update/status (issue #160).
  2. package httpapi_test
  3. import (
  4. "net/http"
  5. "net/http/httptest"
  6. "testing"
  7. "github.com/gnacho/netpulse/server-go/internal/updater"
  8. )
  9. func TestUpdateStatusExposesReadiness(t *testing.T) {
  10. if !gitAvailable() {
  11. t.Skip("git no disponible")
  12. }
  13. // #160: el check de conectividad apunta a un servidor local. Antes dependia
  14. // de que el runner alcanzase github.com y un corte de red ponia en rojo el
  15. // workflow sin que hubiese nada roto.
  16. probe := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
  17. w.WriteHeader(http.StatusOK)
  18. }))
  19. defer probe.Close()
  20. defer updater.SetProbeURL(probe.URL)()
  21. root := t.TempDir()
  22. writeDeployScript(t, root)
  23. writeGitHead(t, root)
  24. ts := makeTestServerWithUpdater(t, root)
  25. cookie := adminCookie(t, ts)
  26. res := get(t, ts.URL, "/api/update/status", cookie)
  27. if res.StatusCode != 200 {
  28. t.Fatalf("status: got %d want 200", res.StatusCode)
  29. }
  30. body := readJSON(t, res)
  31. r, ok := body["readiness"].(map[string]any)
  32. if !ok {
  33. t.Fatalf("readiness ausente: %+v", body)
  34. }
  35. ready, _ := r["ready"].(bool)
  36. if !ready {
  37. t.Errorf("ready false: %+v", r)
  38. }
  39. for _, k := range []string{"disk", "git", "network", "concurrent"} {
  40. ck, ok := r[k].(map[string]any)
  41. if !ok {
  42. t.Errorf("check %s ausente: %+v", k, r)
  43. continue
  44. }
  45. okv, _ := ck["ok"].(bool)
  46. if !okv {
  47. t.Errorf("check %s = %+v, want ok", k, ck)
  48. }
  49. }
  50. }