Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions control-plane/internal/server/routes_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/http"
"os"
"time"

"github.com/Agent-Field/agentfield/control-plane/internal/config"
Expand Down Expand Up @@ -216,6 +217,9 @@ func (s *AgentFieldServer) healthCheckHandler(c *gin.Context) {
"version": "1.0.0", // TODO: Get from build info
"checks": gin.H{},
}
if furrowPublicAddr := os.Getenv("FURROW_PUBLIC_ADDR"); furrowPublicAddr != "" {
healthStatus["furrow_public_addr"] = furrowPublicAddr
}

allHealthy := true
checks := healthStatus["checks"].(gin.H)
Expand Down
41 changes: 41 additions & 0 deletions control-plane/internal/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,47 @@ func TestHealthCheckHandlerHealthy(t *testing.T) {
}
}

func TestHealthCheckHandlerFurrowPublicAddr(t *testing.T) {
tests := []struct {
name string
address string
wantValue bool
}{
{name: "set", address: "furrow.example.com:7443", wantValue: true},
{name: "empty", address: "", wantValue: false},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Setenv("FURROW_PUBLIC_ADDR", tt.address)
gin.SetMode(gin.TestMode)
srv := &AgentFieldServer{
storageHealthOverride: func(context.Context) gin.H { return gin.H{"status": "healthy"} },
cacheHealthOverride: func(context.Context) gin.H { return gin.H{"status": "healthy"} },
}

w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
req, _ := http.NewRequest(http.MethodGet, "/health", nil)
c.Request = req

srv.healthCheckHandler(c)

var payload map[string]any
if err := json.Unmarshal(w.Body.Bytes(), &payload); err != nil {
t.Fatalf("failed to decode response: %v", err)
}
got, present := payload["furrow_public_addr"]
if present != tt.wantValue {
t.Fatalf("furrow_public_addr presence = %v, want %v; payload: %+v", present, tt.wantValue, payload)
}
if tt.wantValue && got != tt.address {
t.Fatalf("furrow_public_addr = %v, want %q", got, tt.address)
}
})
}
}

func TestHealthCheckHandlerCacheOptional(t *testing.T) {
gin.SetMode(gin.TestMode)
srv := &AgentFieldServer{
Expand Down
Loading