From 95a8aa7878969f9dd8020d1ea32bf73c3bfb2cce Mon Sep 17 00:00:00 2001 From: Damian Gryski Date: Mon, 27 Apr 2026 17:25:52 -0700 Subject: [PATCH 1/2] integration_tests/dynamic_backend: add test for backend health --- integration_tests/dynamic_backend/fastly.toml | 9 +- .../dynamic_backend/main_test.go | 92 +++++++++++++++++++ 2 files changed, 99 insertions(+), 2 deletions(-) diff --git a/integration_tests/dynamic_backend/fastly.toml b/integration_tests/dynamic_backend/fastly.toml index 0dfb0aae..a6074503 100644 --- a/integration_tests/dynamic_backend/fastly.toml +++ b/integration_tests/dynamic_backend/fastly.toml @@ -12,5 +12,10 @@ service_id = "" [local_server.backends] - [local_server.backends.TheOrigin] - url = "https://compute-sdk-test-backend.edgecompute.app/" + [local_server.backends.healthy] + url = "https://example.com" + health = "healthy" + + [local_server.backends.unhealthy] + url = "https://example.com" + health = "unhealthy" diff --git a/integration_tests/dynamic_backend/main_test.go b/integration_tests/dynamic_backend/main_test.go index 7cc8465c..c8519278 100644 --- a/integration_tests/dynamic_backend/main_test.go +++ b/integration_tests/dynamic_backend/main_test.go @@ -99,3 +99,95 @@ func TestDynamicBackend(t *testing.T) { t.Errorf("Body = %q, want %q", got, want) } } + +func TestOriginHealth(t *testing.T) { + handler := func(ctx context.Context, w fsthttp.ResponseWriter, r *fsthttp.Request) { + + { + b, err := fsthttp.BackendFromName("healthy") + + if err != nil { + t.Errorf("BackendFromName: %v", err) + fsthttp.Error(w, err.Error(), fsthttp.StatusInternalServerError) + return + } + + health, err := b.Health() + if err != nil { + t.Errorf("Health: %v", err) + fsthttp.Error(w, err.Error(), fsthttp.StatusInternalServerError) + return + } + + if health != fsthttp.BackendHealthHealthy { + want := fsthttp.BackendHealthHealthy + t.Errorf("Health = %v, want %v", health, want) + fsthttp.Error(w, fmt.Sprintf("Health = %v, want %v", health, want), fsthttp.StatusInternalServerError) + return + } + + } + + b, err := fsthttp.BackendFromName("unhealthy") + + if err != nil { + t.Errorf("BackendFromName: %v", err) + fsthttp.Error(w, err.Error(), fsthttp.StatusInternalServerError) + return + } + + health, err := b.Health() + if err != nil { + t.Errorf("Health: %v", err) + fsthttp.Error(w, err.Error(), fsthttp.StatusInternalServerError) + return + } + + if health != fsthttp.BackendHealthUnhealthy { + want := fsthttp.BackendHealthUnhealthy + t.Errorf("Health = %v, want %v", health, want) + fsthttp.Error(w, fmt.Sprintf("Health = %v, want %v", health, want), fsthttp.StatusInternalServerError) + return + } + + req, err := fsthttp.NewRequest("GET", b.Target(), nil) + if err != nil { + t.Errorf("NewRequest: %v", err) + fsthttp.Error(w, err.Error(), fsthttp.StatusInternalServerError) + return + } + + _ = req + + /* + // Send to our unhealthy backend + _, err = req.Send(ctx, b.Name()) + if err == nil { + t.Errorf("Send had nil error") + fsthttp.Error(w, "nil error", fsthttp.StatusInternalServerError) + return + } else { + fmt.Fprintf(w, "error from unhealthy send: %v", err) + } + + */ + + fmt.Fprintf(w, "Ok") + } + + r, err := fsthttp.NewRequest("GET", "/", nil) + if err != nil { + t.Fatalf("NewRequest: %v", err) + } + w := fsttest.NewRecorder() + + handler(context.Background(), w, r) + + if got, want := w.Code, fsthttp.StatusOK; got != want { + t.Errorf("Code = %d, want %d", got, want) + } + + if got, want := w.Body.String(), "Ok"; got != want { + t.Errorf("Body = %q, want %q", got, want) + } +} From 3c1377e506f79479352c28e75c99a89b0e4ad800 Mon Sep 17 00:00:00 2001 From: Damian Gryski Date: Tue, 28 Apr 2026 10:45:20 -0700 Subject: [PATCH 2/2] integration_tests/device_detection -> backend --- integration_tests/{dynamic_backend => backend}/fastly.toml | 0 integration_tests/{dynamic_backend => backend}/main_test.go | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename integration_tests/{dynamic_backend => backend}/fastly.toml (100%) rename integration_tests/{dynamic_backend => backend}/main_test.go (100%) diff --git a/integration_tests/dynamic_backend/fastly.toml b/integration_tests/backend/fastly.toml similarity index 100% rename from integration_tests/dynamic_backend/fastly.toml rename to integration_tests/backend/fastly.toml diff --git a/integration_tests/dynamic_backend/main_test.go b/integration_tests/backend/main_test.go similarity index 100% rename from integration_tests/dynamic_backend/main_test.go rename to integration_tests/backend/main_test.go