feat(remote): 显示控制中心和实例版本
This commit is contained in:
@@ -191,6 +191,52 @@ func TestDashboardRequiresOperatorToken(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestHealthAndDashboardExposeControlVersion(t *testing.T) {
|
||||
server, err := NewServer(ServerOptions{
|
||||
DataDir: t.TempDir(),
|
||||
OperatorToken: "operator",
|
||||
Version: "0.6.4",
|
||||
BuildTime: "2026-11-22 16:00:00",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer server.Close()
|
||||
httpServer := httptest.NewServer(server.Handler())
|
||||
defer httpServer.Close()
|
||||
|
||||
healthResponse, err := http.Get(httpServer.URL + "/api/health")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer healthResponse.Body.Close()
|
||||
var health map[string]any
|
||||
if err := json.NewDecoder(healthResponse.Body).Decode(&health); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if health["version"] != "0.6.4" || health["buildTime"] != "2026-11-22 16:00:00" {
|
||||
t.Fatalf("unexpected health version payload: %#v", health)
|
||||
}
|
||||
|
||||
request, err := http.NewRequest(http.MethodGet, httpServer.URL+"/api/dashboard", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
request.Header.Set("X-Control-Token", "operator")
|
||||
dashboardResponse, err := http.DefaultClient.Do(request)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer dashboardResponse.Body.Close()
|
||||
var dashboard DashboardState
|
||||
if err := json.NewDecoder(dashboardResponse.Body).Decode(&dashboard); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if dashboard.ControlVersion != "0.6.4" || dashboard.ControlBuildTime != "2026-11-22 16:00:00" {
|
||||
t.Fatalf("unexpected dashboard version payload: %+v", dashboard)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAgentAutoEnrollsWithoutManualToken(t *testing.T) {
|
||||
server, err := NewServer(ServerOptions{
|
||||
DataDir: t.TempDir(),
|
||||
|
||||
Reference in New Issue
Block a user