Răsfoiți Sursa

test(update): check readiness against a local probe

The test reached github.com, so a runner without outbound access failed the whole workflow with netUnreachable. The probe target is injectable and the test uses a local server.
Nacho 4 săptămâni în urmă
părinte
comite
9bd832cc7c

+ 12 - 0
server-go/internal/httpapi/update_readiness_test.go

@@ -2,13 +2,25 @@
 package httpapi_test
 
 import (
+	"net/http"
+	"net/http/httptest"
 	"testing"
+
+	"github.com/gnacho/netpulse/server-go/internal/updater"
 )
 
 func TestUpdateStatusExposesReadiness(t *testing.T) {
 	if !gitAvailable() {
 		t.Skip("git no disponible")
 	}
+	// #160: el check de conectividad apunta a un servidor local. Antes dependia
+	// de que el runner alcanzase github.com y un corte de red ponia en rojo el
+	// workflow sin que hubiese nada roto.
+	probe := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
+		w.WriteHeader(http.StatusOK)
+	}))
+	defer probe.Close()
+	defer updater.SetProbeURL(probe.URL)()
 	root := t.TempDir()
 	writeDeployScript(t, root)
 	writeGitHead(t, root)

+ 9 - 0
server-go/internal/updater/readiness.go

@@ -35,6 +35,15 @@ const (
 // Var de paquete para apuntarlo al httptest de los tests.
 var probeURL = "https://github.com"
 
+// SetProbeURL cambia el destino del check de conectividad y devuelve la
+// funcion para restaurarlo. Solo para tests: el check no debe depender de que
+// el runner de CI alcance internet (#160).
+func SetProbeURL(u string) (restore func()) {
+	old := probeURL
+	probeURL = u
+	return func() { probeURL = old }
+}
+
 // minDiskFreeBytes es el espacio libre mínimo exigido en repoRoot (descarga
 // del binario de CI ~40 MB + backup del binario actual + margen de build).
 // Var de paquete para poder bajarlo en tests.